1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
#!/bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src
# Test of ITS support.
: ${XGETTEXT=xgettext}
GETTEXTDATADIR=.
export GETTEXTDATADIR
cat <<\EOF > empty.xml
<?xml version="1.0"?>
<empty></empty>
EOF
${XGETTEXT} --itstool -o empty.pot empty.xml 2>empty.err || { cat empty.err; exit 1; }
test -d its || mkdir its
cat <<\EOF > its/empty-1.loc
<?xml version="1.0"?>
<locatingRules/>
EOF
${XGETTEXT} --itstool -o empty.pot empty.xml 2>empty.err || { cat empty.err; exit 1; }
cat <<\EOF > its/empty-2.loc
<?xml version="1.0"?>
<locatingRules>
<locatingRule pattern="*.xml">
<documentRule prefix="" localName="empty" target="empty.its"/>
</locatingRule>
</locatingRules>
EOF
${XGETTEXT} --itstool -o empty.pot empty.xml 2>empty.err || { cat empty.err; exit 1; }
cat <<\EOF > its/empty.its
<?xml version="1.0"?>
<its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
</its:rules>
EOF
${XGETTEXT} --itstool -o empty.pot empty.xml 2>empty.err || { cat empty.err; exit 1; }
cat <<\EOF > its/messages.loc
<?xml version="1.0"?>
<locatingRules>
<locatingRule pattern="*.xml">
<documentRule localName="messages" target="messages.its"/>
</locatingRule>
<locatingRule pattern="*.msg">
<documentRule localName="messages" target="messages.its"/>
</locatingRule>
</locatingRules>
EOF
cat <<\EOF > its/messages.its
<?xml version="1.0"?>
<its:rules xmlns:its="http://www.w3.org/2005/11/its"
xmlns:gt="https://www.gnu.org/s/gettext/ns/its/extensions/1.0"
xmlns:msg="http://www.gnu.org/s/gettext/ns/messages/1.0"
version="1.0">
<!-- Invalid: no selector -->
<its:translateRule translate="yes"/>
<!-- Invalid: no translate -->
<its:translateRule selector="/"/>
<its:translateRule selector="//msg:message/@comment" translate="yes"/>
<its:translateRule selector="//msg:note" translate="no"/>
<its:translateRule selector="//msg:p[@translatable = 'no']"
translate="no"/>
<!-- Invalid: no selector -->
<its:locNoteRule locNoteType="alert"/>
<!-- Invalid: no locNoteType -->
<its:locNoteRule selector="/"/>
<its:locNoteRule selector="//msg:message/*" locNoteType="alert"
locNotePointer="../msg:note"/>
<its:locNoteRule selector="//msg:code" locNoteType="alert">
<its:locNote>This is code</its:locNote>
</its:locNoteRule>
<its:locNoteRule selector="//msg:message/@comment" locNoteType="alert">
<its:locNote>This is a comment</its:locNote>
</its:locNoteRule>
<!-- Invalid: no selector -->
<its:withinTextRule withinText="yes"/>
<!-- Invalid: no withinText -->
<its:withinTextRule selector="/"/>
<its:withinTextRule selector="//msg:span | //msg:link" withinText="yes"/>
<!-- Invalid: no selector -->
<its:preserveSpaceRule space="preserve"/>
<!-- Invalid: no space -->
<its:preserveSpaceRule selector="/"/>
<its:preserveSpaceRule selector="//msg:code" space="preserve"/>
<gt:contextRule selector="//msg:p[@context = 'yes']"
contextPointer="substring-before(., '|')"
textPointer="substring-after(., '|')"/>
</its:rules>
EOF
cat <<\EOF >messages.xml
<?xml version="1.0"?>
<!DOCTYPE messages PUBLIC "" "" [
<!ENTITY foo "bar">
]>
<messages xmlns="http://www.gnu.org/s/gettext/ns/messages/1.0"
xmlns:its="http://www.w3.org/2005/11/its">
<message>
<p>This is a test message &foo;><&""</p>
</message>
<message>
<p its:translate="no">This is a non-translatable message</p>
</message>
<message>
<p>This is a test message, with an <span>element</span> in a <link href="http://www.gnu.org/s/gettext">text</link></p>
</message>
<message>
<code> $ echo ' ' >> /dev/null
$ cat < /dev/yes
$ sleep 10 &
</code>
</message>
<message comment="This is a comment <>&"">
<p>This is a test message, with an attribute</p>
</message>
<message>
<note>
This is a localization note
</note>
<p>This is a test message, with a localization note</p>
</message>
<message>
<p its:locNote="This is a local localization note" its:locNoteType="alert">
This is a test message, with a local localization note
</p>
</message>
<message>
<!-- empty element, which shouldn't be extracted -->
<p></p>
</message>
<message>
<p xml:space="preserve"> This is a message with space preserved</p>
</message>
<message>
<p translatable="no">This is a non-translatable string</p>
</message>
<message its:translate="no">
<p>This is a non-translatable string</p>
</message>
<message>
<!-- This is a comment -->
<p context="yes">context|A translatable string with a context prefixed</p>
</message>
<message>
<p xml:space="trim"> Leading/trailing whitespaces are removed,
but not middle
</p>
</message>
</messages>
EOF
cat <<\EOF >messages.ok
#. (itstool) path: message/p
#: messages.xml:8
msgid "This is a test message &foo;><&\"\""
msgstr ""
#. (itstool) path: message/p
#: messages.xml:14
msgid "This is a test message, with an <span>element</span> in a <link href=\"http://www.gnu.org/s/gettext\">text</link>"
msgstr ""
#. This is code
#. (itstool) path: message/code
#: messages.xml:17
#, no-wrap
msgid ""
" $ echo ' ' >> /dev/null\n"
" $ cat < /dev/yes\n"
" $ sleep 10 &\n"
msgstr ""
#. This is a comment
#. (itstool) path: messages/message@comment
#: messages.xml:22
msgid "This is a comment <>&""
msgstr ""
#. (itstool) path: message/p
#: messages.xml:23
msgid "This is a test message, with an attribute"
msgstr ""
#. This is a localization note
#. (itstool) path: message/p
#: messages.xml:29
msgid "This is a test message, with a localization note"
msgstr ""
#. This is a local localization note
#. (itstool) path: message/p
#: messages.xml:32
msgid "This is a test message, with a local localization note"
msgstr ""
#. (itstool) path: message/p
#: messages.xml:41
#, no-wrap
msgid " This is a message with space preserved"
msgstr ""
#. This is a comment
#. (itstool) path: message/p
#: messages.xml:51
msgctxt "context"
msgid "A translatable string with a context prefixed"
msgstr ""
#. (itstool) path: message/p
#: messages.xml:54
msgid ""
"Leading/trailing whitespaces are removed,\n"
" but not middle"
msgstr ""
EOF
: ${DIFF=diff}
${XGETTEXT} --itstool --no-wrap --omit-header -o messages.pot messages.xml 2>messages.err || { cat messages.err; exit 1; }
${DIFF} messages.ok messages.pot
result=$?
test $result = 0 || exit $result
# Check if locating rules can work with --directory, and extra ".in"
# file name extension.
test -d data || mkdir data
test -d po || mkdir po
cp messages.xml data/messages.msg.in
cd po
GETTEXTDATADIR=..
export GETTEXTDATADIR
${XGETTEXT} --itstool --no-wrap --omit-header --directory=.. -o messages.pot.in data/messages.msg.in 2>messages.err || { cat messages.err; exit 1; }
sed -e 's!^#: data/messages.msg.in!#: messages.xml!' \
< messages.pot.in > messages.pot
${DIFF} ../messages.ok messages.pot
result=$?
test $result = 0 || exit $result
|