1 1.1 christos #!/bin/sh 2 1.1 christos 3 1.1 christos # Test of Perl support. 4 1.1 christos 5 1.1 christos tmpfiles="" 6 1.1 christos trap 'rm -fr $tmpfiles' 1 2 3 15 7 1.1 christos 8 1.1 christos tmpfiles="$tmpfiles xg-pl-1.pl" 9 1.1 christos cat <<\EOF > xg-pl-1.pl 10 1.1 christos use Locale::Messages qw (textdomain bindtextdomain gettext ngettext dngettext); 11 1.1 christos 12 1.1 christos textdomain "prog"; 13 1.1 christos bindtextdomain "prog", "./"; 14 1.1 christos 15 1.1 christos s/foo/ 16 1.1 christos # stress test for string extraction /xe; 17 1.1 christos 18 1.1 christos print _"'Your command, please?', asked the waiter."; 19 1.1 christos 20 1.1 christos printf ngettext ("a piece of cake", "%d pieces of cake", $n), $n; 21 1.1 christos 22 1.1 christos printf _"%s is replaced by %s.", "FF", "EUR"; 23 1.1 christos 24 1.1 christos # Should be found. 25 1.1 christos printf dngettext prog => ("one file deleted", "%d files deleted"), $n, $n; 26 1.1 christos 27 1.1 christos # Should not be found. 28 1.1 christos printf dngettext ("prog"), ("one file created", "%d files created"), $n, $n; 29 1.1 christos 30 1.1 christos printf dngettext "prog", <<PERL, <<PERL; 31 1.1 christos Singular 32 1.1 christos PERL 33 1.1 christos Plural 34 1.1 christos PERL 35 1.1 christos 36 1.1 christos print <<PERL 37 1.1 christos tied hash $__{ Bareword 38 1.1 christos } 39 1.1 christos tied hash $__->{"quoted string"} 40 1.1 christos tied hash $__->{ "weird 41 1.1 christos formatting"} 42 1.1 christos PERL 43 1.1 christos 44 1.1 christos print $__ # Welcome 45 1.1 christos -> # to the 46 1.1 christos { # Republic of 47 1.1 christos 'Welcome to the Republic of Perl!' # 48 1.1 christos # Perl! 49 1.1 christos }; 50 1.1 christos 51 1.1 christos $! ? ?$__{"pattern match"}? : s # This is no delimiter. 52 1.1 christos {$__{substitution}}<$__-\>{"find me"}>; 53 1.1 christos 54 1.1 christos # No interpolation! 55 1.1 christos m'$__{secret}'; 56 1.1 christos 57 1.1 christos # Multiple here documents invoked from the same line. 58 1.1 christos print gettext <<PERL; print gettext <<PERL; 59 1.1 christos First here document. 60 1.1 christos PERL 61 1.1 christos Second here document. 62 1.1 christos PERL 63 1.1 christos 64 1.1 christos # These are not invalid interpolations, because the dollar is backslashed. 65 1.1 christos printf "%s\n", gettext "abc\$def"; 66 1.1 christos printf "%s\n", gettext "abc\\\$def"; 67 1.1 christos 68 1.1 christos # These are not interpolations. 69 1.1 christos printf "%s\n", gettext 'abc$defg'; 70 1.1 christos printf "%s\n", gettext 'abc\$defg'; 71 1.1 christos printf "%s\n", gettext 'abc\\$defg'; 72 1.1 christos printf "%s\n", gettext 'abc\\\$defg'; 73 1.1 christos 74 1.1 christos # Two consecutive backslashes count as one inside single-quote strings. 75 1.1 christos printf "%s\n", gettext 'ecs\tasy'; 76 1.1 christos printf "%s\n", gettext 'ecs\\tasy'; 77 1.1 christos printf "%s\n", gettext 'ecs\\\tasy'; 78 1.1 christos printf "%s\n", gettext 'ecs\\\\tasy'; 79 1.1 christos printf "%s\n", gettext 'ecs\\\\\tasy'; 80 1.1 christos printf "%s\n", gettext q(ecs\tasy); 81 1.1 christos printf "%s\n", gettext q(ecs\\tasy); 82 1.1 christos printf "%s\n", gettext q(ecs\\\tasy); 83 1.1 christos printf "%s\n", gettext q(ecs\\\\tasy); 84 1.1 christos printf "%s\n", gettext q(ecs\\\\\tasy); 85 1.1 christos 86 1.1 christos # Similarly, inside double-quote strings, two consecutive backslashes count 87 1.1 christos # as one, but the last backslash of a sequence is combined with the following 88 1.1 christos # character if possible. 89 1.1 christos printf "%s\n", gettext "ecs\tasy"; 90 1.1 christos printf "%s\n", gettext "ecs\\tasy"; 91 1.1 christos printf "%s\n", gettext "ecs\\\tasy"; 92 1.1 christos printf "%s\n", gettext "ecs\\\\tasy"; 93 1.1 christos printf "%s\n", gettext "ecs\\\\\tasy"; 94 1.1 christos printf "%s\n", gettext qq(ecs\tasy); 95 1.1 christos printf "%s\n", gettext qq(ecs\\tasy); 96 1.1 christos printf "%s\n", gettext qq(ecs\\\tasy); 97 1.1 christos printf "%s\n", gettext qq(ecs\\\\tasy); 98 1.1 christos printf "%s\n", gettext qq(ecs\\\\\tasy); 99 1.1 christos printf "%s\n", gettext "mari\huana"; 100 1.1 christos printf "%s\n", gettext "mari\\huana"; 101 1.1 christos printf "%s\n", gettext "mari\\\huana"; 102 1.1 christos printf "%s\n", gettext "mari\\\\huana"; 103 1.1 christos printf "%s\n", gettext "mari\\\\\huana"; 104 1.1 christos printf "%s\n", gettext qq(mari\huana); 105 1.1 christos printf "%s\n", gettext qq(mari\\huana); 106 1.1 christos printf "%s\n", gettext qq(mari\\\huana); 107 1.1 christos printf "%s\n", gettext qq(mari\\\\huana); 108 1.1 christos printf "%s\n", gettext qq(mari\\\\\huana); 109 1.1 christos 110 1.1 christos # Recognition of format strings. 111 1.1 christos gettext "This is {only} a brace formatstring."; 112 1.1 christos gettext "This is %s {mixed}."; 113 1.1 christos gettext "This is only %c."; 114 1.1 christos gettext "This is nothing at all."; 115 1.1 christos gettext "And this is %l also no format at all."; 116 1.1 christos 117 1.1 christos # xgettext: no-perl-format, perl-brace-format 118 1.1 christos gettext "The function '{func}' expects '%c' here."; 119 1.1 christos 120 1.1 christos # This is a contradictory case: The same string three times, 121 1.1 christos # with different xgettext comments. 122 1.1 christos # xgettext: perl-brace-format, no-perl-format 123 1.1 christos gettext "Left as an %exercise to {maintainer}."; 124 1.1 christos # xgettext: no-perl-brace-format, perl-format 125 1.1 christos gettext "Left as an %exercise to {maintainer}."; 126 1.1 christos # No xgettext comment this time. 127 1.1 christos gettext "Left as an %exercise to {maintainer}."; 128 1.1 christos 129 1.1 christos # Dollars inside sub argument lists have no effect. 130 1.1 christos sub testFunc($) { } 131 1.1 christos =item TestBug1 132 1.1 christos If you have gettext()'d foo bar test1'... 133 1.1 christos =cut 134 1.1 christos 135 1.1 christos # Dollars inside sub argument lists have no effect. 136 1.1 christos testFunc = sub ($) { } 137 1.1 christos =item TestBug2 138 1.1 christos If you have gettext()'d foo bar test2'... 139 1.1 christos =cut 140 1.1 christos 141 1.1 christos # Dollars inside sub argument lists have no effect. 142 1.1 christos sub testFunc($\$;*@) { } 143 1.1 christos =item TestBug3 144 1.1 christos If you have gettext()'d foo bar test3'... 145 1.1 christos =cut 146 1.1 christos 147 1.1 christos __END__ 148 1.1 christos gettext "Discarded!"; 149 1.1 christos EOF 150 1.1 christos 151 1.1 christos tmpfiles="$tmpfiles xg-pl-1.po" 152 1.1 christos : ${XGETTEXT=xgettext} 153 1.1 christos ${XGETTEXT} --omit-header -n \ 154 1.1 christos -k_ --flag=_:1:pass-perl-format --flag=_:1:pass-perl-brace-format \ 155 1.1 christos -k%__ --flag=%__:1:pass-perl-format --flag=%__:1:pass-perl-brace-format \ 156 1.1 christos -k\$__ --flag=\$__:1:pass-perl-format --flag=\$__:1:pass-perl-brace-format \ 157 1.1 christos -d xg-pl-1 xg-pl-1.pl 158 1.1 christos test $? = 0 || { rm -fr $tmpfiles; exit 1; } 159 1.1 christos 160 1.1 christos tmpfiles="$tmpfiles xg-pl-1.ok" 161 1.1 christos cat <<\EOF > xg-pl-1.ok 162 1.1 christos #: xg-pl-1.pl:9 163 1.1 christos msgid "'Your command, please?', asked the waiter." 164 1.1 christos msgstr "" 165 1.1 christos 166 1.1 christos #: xg-pl-1.pl:11 167 1.1 christos #, perl-format 168 1.1 christos msgid "a piece of cake" 169 1.1 christos msgid_plural "%d pieces of cake" 170 1.1 christos msgstr[0] "" 171 1.1 christos msgstr[1] "" 172 1.1 christos 173 1.1 christos #: xg-pl-1.pl:13 174 1.1 christos #, perl-format 175 1.1 christos msgid "%s is replaced by %s." 176 1.1 christos msgstr "" 177 1.1 christos 178 1.1 christos #: xg-pl-1.pl:16 179 1.1 christos #, perl-format 180 1.1 christos msgid "one file deleted" 181 1.1 christos msgid_plural "%d files deleted" 182 1.1 christos msgstr[0] "" 183 1.1 christos msgstr[1] "" 184 1.1 christos 185 1.1 christos #: xg-pl-1.pl:22 186 1.1 christos #, perl-format 187 1.1 christos msgid "Singular\n" 188 1.1 christos msgid_plural "Plural\n" 189 1.1 christos msgstr[0] "" 190 1.1 christos msgstr[1] "" 191 1.1 christos 192 1.1 christos #: xg-pl-1.pl:28 193 1.1 christos msgid "Bareword" 194 1.1 christos msgstr "" 195 1.1 christos 196 1.1 christos #: xg-pl-1.pl:30 197 1.1 christos msgid "quoted string" 198 1.1 christos msgstr "" 199 1.1 christos 200 1.1 christos #: xg-pl-1.pl:31 201 1.1 christos msgid "" 202 1.1 christos "weird\n" 203 1.1 christos "formatting" 204 1.1 christos msgstr "" 205 1.1 christos 206 1.1 christos #: xg-pl-1.pl:38 207 1.1 christos msgid "Welcome to the Republic of Perl!" 208 1.1 christos msgstr "" 209 1.1 christos 210 1.1 christos #: xg-pl-1.pl:42 211 1.1 christos msgid "pattern match" 212 1.1 christos msgstr "" 213 1.1 christos 214 1.1 christos #: xg-pl-1.pl:43 215 1.1 christos msgid "substitution" 216 1.1 christos msgstr "" 217 1.1 christos 218 1.1 christos #: xg-pl-1.pl:43 219 1.1 christos msgid "find me" 220 1.1 christos msgstr "" 221 1.1 christos 222 1.1 christos #: xg-pl-1.pl:50 223 1.1 christos msgid "First here document.\n" 224 1.1 christos msgstr "" 225 1.1 christos 226 1.1 christos #: xg-pl-1.pl:52 227 1.1 christos msgid "Second here document.\n" 228 1.1 christos msgstr "" 229 1.1 christos 230 1.1 christos #: xg-pl-1.pl:56 231 1.1 christos msgid "abc$def" 232 1.1 christos msgstr "" 233 1.1 christos 234 1.1 christos #: xg-pl-1.pl:57 235 1.1 christos msgid "abc\\$def" 236 1.1 christos msgstr "" 237 1.1 christos 238 1.1 christos #: xg-pl-1.pl:60 239 1.1 christos msgid "abc$defg" 240 1.1 christos msgstr "" 241 1.1 christos 242 1.1 christos #: xg-pl-1.pl:61 xg-pl-1.pl:62 243 1.1 christos msgid "abc\\$defg" 244 1.1 christos msgstr "" 245 1.1 christos 246 1.1 christos #: xg-pl-1.pl:63 247 1.1 christos msgid "abc\\\\$defg" 248 1.1 christos msgstr "" 249 1.1 christos 250 1.1 christos #: xg-pl-1.pl:66 xg-pl-1.pl:67 xg-pl-1.pl:71 xg-pl-1.pl:72 xg-pl-1.pl:81 251 1.1 christos #: xg-pl-1.pl:86 252 1.1 christos msgid "ecs\\tasy" 253 1.1 christos msgstr "" 254 1.1 christos 255 1.1 christos #: xg-pl-1.pl:68 xg-pl-1.pl:69 xg-pl-1.pl:73 xg-pl-1.pl:74 xg-pl-1.pl:83 256 1.1 christos #: xg-pl-1.pl:88 257 1.1 christos msgid "ecs\\\\tasy" 258 1.1 christos msgstr "" 259 1.1 christos 260 1.1 christos #: xg-pl-1.pl:70 xg-pl-1.pl:75 261 1.1 christos msgid "ecs\\\\\\tasy" 262 1.1 christos msgstr "" 263 1.1 christos 264 1.1 christos #: xg-pl-1.pl:80 xg-pl-1.pl:85 265 1.1 christos msgid "ecs\tasy" 266 1.1 christos msgstr "" 267 1.1 christos 268 1.1 christos #: xg-pl-1.pl:82 xg-pl-1.pl:87 269 1.1 christos msgid "ecs\\\tasy" 270 1.1 christos msgstr "" 271 1.1 christos 272 1.1 christos #: xg-pl-1.pl:84 xg-pl-1.pl:89 273 1.1 christos msgid "ecs\\\\\tasy" 274 1.1 christos msgstr "" 275 1.1 christos 276 1.1 christos #: xg-pl-1.pl:90 xg-pl-1.pl:95 277 1.1 christos msgid "marihuana" 278 1.1 christos msgstr "" 279 1.1 christos 280 1.1 christos #: xg-pl-1.pl:91 xg-pl-1.pl:92 xg-pl-1.pl:96 xg-pl-1.pl:97 281 1.1 christos msgid "mari\\huana" 282 1.1 christos msgstr "" 283 1.1 christos 284 1.1 christos #: xg-pl-1.pl:93 xg-pl-1.pl:94 xg-pl-1.pl:98 xg-pl-1.pl:99 285 1.1 christos msgid "mari\\\\huana" 286 1.1 christos msgstr "" 287 1.1 christos 288 1.1 christos #: xg-pl-1.pl:102 289 1.1 christos #, perl-brace-format 290 1.1 christos msgid "This is {only} a brace formatstring." 291 1.1 christos msgstr "" 292 1.1 christos 293 1.1 christos #: xg-pl-1.pl:103 294 1.1 christos #, perl-format, perl-brace-format 295 1.1 christos msgid "This is %s {mixed}." 296 1.1 christos msgstr "" 297 1.1 christos 298 1.1 christos #: xg-pl-1.pl:104 299 1.1 christos #, perl-format 300 1.1 christos msgid "This is only %c." 301 1.1 christos msgstr "" 302 1.1 christos 303 1.1 christos #: xg-pl-1.pl:105 304 1.1 christos msgid "This is nothing at all." 305 1.1 christos msgstr "" 306 1.1 christos 307 1.1 christos #: xg-pl-1.pl:106 308 1.1 christos msgid "And this is %l also no format at all." 309 1.1 christos msgstr "" 310 1.1 christos 311 1.1 christos #: xg-pl-1.pl:109 312 1.1 christos #, no-perl-format, perl-brace-format 313 1.1 christos msgid "The function '{func}' expects '%c' here." 314 1.1 christos msgstr "" 315 1.1 christos 316 1.1 christos #: xg-pl-1.pl:114 xg-pl-1.pl:116 xg-pl-1.pl:118 317 1.1 christos #, perl-format, no-perl-brace-format 318 1.1 christos msgid "Left as an %exercise to {maintainer}." 319 1.1 christos msgstr "" 320 1.1 christos EOF 321 1.1 christos 322 1.1 christos : ${DIFF=diff} 323 1.1 christos ${DIFF} xg-pl-1.ok xg-pl-1.po 324 1.1 christos result=$? 325 1.1 christos 326 1.1 christos rm -fr $tmpfiles 327 1.1 christos 328 1.1 christos exit $result 329