Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 1 | import os |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 2 | import base64 |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 3 | import gettext |
| 4 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 5 | def test(localedir, mofile): |
| 6 | # Test basic interface |
| 7 | os.environ['LANGUAGE'] = 'xx' |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 8 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 9 | print 'installing gettext' |
| 10 | gettext.install() |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 11 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 12 | print _('calling bindtextdomain with localedir %s') % localedir |
| 13 | print gettext.bindtextdomain('gettext', localedir) |
| 14 | print gettext.bindtextdomain() |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 15 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 16 | print gettext.textdomain('gettext') |
| 17 | print gettext.textdomain() |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 18 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 19 | # test some translations |
| 20 | print _(u'mullusk') |
| 21 | print _(r'Raymond Luxury Yach-t') |
| 22 | print _(ur'nudge nudge') |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 23 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 24 | # double quotes |
| 25 | print _(u"mullusk") |
| 26 | print _(r"Raymond Luxury Yach-t") |
| 27 | print _(ur"nudge nudge") |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 28 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 29 | # triple single quotes |
| 30 | print _(u'''mullusk''') |
| 31 | print _(r'''Raymond Luxury Yach-t''') |
| 32 | print _(ur'''nudge nudge''') |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 33 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 34 | # triple double quotes |
| 35 | print _(u"""mullusk""") |
| 36 | print _(r"""Raymond Luxury Yach-t""") |
| 37 | print _(ur"""nudge nudge""") |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 38 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 39 | # multiline strings |
| 40 | print _('''This module provides internationalization and localization |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 41 | support for your Python programs by providing an interface to the GNU |
| 42 | gettext message catalog library.''') |
| 43 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 44 | print gettext.dgettext('gettext', 'nudge nudge') |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 45 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 46 | # test the alternative interface |
| 47 | fp = open(os.path.join(mofile), 'rb') |
| 48 | t = gettext.GNUTranslations(fp) |
| 49 | fp.close() |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 50 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 51 | gettext.set(t) |
| 52 | print t == gettext.get() |
Barry Warsaw | 9e03592 | 2000-08-25 19:14:25 +0000 | [diff] [blame] | 53 | |
Barry Warsaw | ff6d813 | 2000-08-25 19:50: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2bW5ndmJh |
| 69 | IG5hcSB5YnBueXZtbmd2YmEKZmhjY2JlZyBzYmUgbGJoZSBDbGd1YmEgY2VidGVuemYgb2wgY2Vi |
| 70 | aXZxdmF0IG5hIHZhZ3Jlc25wciBnYiBndXIgVEFICnRyZ2dya2cgenJmZm50ciBwbmdueWJ0IHl2 |
| 71 | b2VuZWwuAGJhY29uAHdpbmsgd2luawA= |
| 72 | ''' |
| 73 | |
| 74 | SOLARIS_MO_DATA = '''\ |
| 75 | AAAACAAAABEAAAIXAAAB0gAAARD///+d////nQAAAAAAAAAAAAAAAAAAAAIAAAAkAAAAAf///53/ |
| 76 | //+dAAAAQgAAAAIAAAABAAAABQAAAGgAAAAD////nf///50AAAB0AAAADQAAAAQAAAAGAAAAmAAA |
| 77 | AA7///+dAAAABwAAAKAAAAAU////nf///50AAAC5AAAAFQAAAAMAAAAMAAAAywAAABb///+d//// |
| 78 | nQAAANsAAAAXAAAACQAAAAsAAADsAAAAGP///53///+dAAAA/wAAABkAAAAKAAAADgAAAScAAAAa |
| 79 | ////nf///50AAAFDAAAAGwAAAA0AAAAPAAABXgAAABz///+dAAAAEAAAAgAAAAC+////nf///50A |
| 80 | AAIWAAAA1XRleHQgZG9tYWluIGRpZG4ndCBnZXQgc2V0IHByb3Blcmx5AHJhdyBzdHJpbmcgdHJh |
| 81 | bnNsYXRpb24gZmFpbGVkAHJhdyBVbmljb2RlIHN0cmluZyB0cmFuc2xhdGlvbiBmYWlsZWQAbnVk |
| 82 | Z2UgbnVkZ2UAbXVsdGlsaW5lIHN0cmluZyB0cmFuc2xhdGlvbiBmYWlsZWQAbXVsbHVzawBnb3Qg |
| 83 | dW5leHBlY3RlZCBsb2NhbGVkaXIAZ2V0dGV4dCBpbnN0YWxsZWQAZGdldHRleHQgZmFpbGVkAGRj |
| 84 | Z2V0dGV4dCBmYWlsZWQAY2FsbGluZyB0ZXh0ZG9tYWluAGNhbGxpbmcgYmluZHRleHRkb21haW4g |
| 85 | d2l0aCBsb2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| |
| 100 | LOCALEDIR = os.path.join('xx', 'LC_MESSAGES') |
| 101 | MOFILE = os.path.join(LOCALEDIR, 'gettext.mo') |
| 102 | |
| 103 | def setup(): |
| 104 | os.makedirs(LOCALEDIR) |
Tim Peters | c795195 | 2000-08-26 21:01:27 +0000 | [diff] [blame] | 105 | fp = open(MOFILE, 'wb') |
Barry Warsaw | ff6d813 | 2000-08-25 19:50:38 +0000 | [diff] [blame] | 106 | fp.write(base64.decodestring(GNU_MO_DATA)) |
| 107 | fp.close() |
| 108 | |
| 109 | def teardown(): |
| 110 | os.unlink(MOFILE) |
| 111 | os.removedirs(LOCALEDIR) |
| 112 | |
| 113 | |
| 114 | |
| 115 | try: |
| 116 | setup() |
| 117 | test('.', MOFILE) |
| 118 | finally: |
| 119 | teardown() |
| 120 | pass |
| 121 | |
| 122 | |
| 123 | |
| 124 | # For reference, here's the .pot and .po files used to created the .mo data |
| 125 | # above. The .pot file was generated by pygettext. |
| 126 | |
| 127 | # =============================== messages.pot |
| 128 | |
| 129 | ### SOME DESCRIPTIVE TITLE. |
| 130 | ### Copyright (C) YEAR ORGANIZATION |
| 131 | ### FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
| 132 | ### |
| 133 | ##msgid "" |
| 134 | ##msgstr "" |
| 135 | ##"Project-Id-Version: PACKAGE VERSION\n" |
| 136 | ##"PO-Revision-Date: Fri Aug 18 20:45:03 2000\n" |
| 137 | ##"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 138 | ##"Language-Team: LANGUAGE <LL@li.org>\n" |
| 139 | ##"MIME-Version: 1.0\n" |
| 140 | ##"Content-Type: text/plain; charset=CHARSET\n" |
| 141 | ##"Content-Transfer-Encoding: ENCODING\n" |
| 142 | ##"Generated-By: pygettext.py 1.1\n" |
| 143 | |
| 144 | |
| 145 | ###: Lib/test/test_gettext.py:34 |
| 146 | ##msgid "calling textdomain" |
| 147 | ##msgstr "" |
| 148 | |
| 149 | ###: Lib/test/test_gettext.py:94 |
| 150 | ##msgid "dgettext failed" |
| 151 | ##msgstr "" |
| 152 | |
| 153 | ###: Lib/test/test_gettext.py:25 |
| 154 | ##msgid "gettext installed" |
| 155 | ##msgstr "" |
| 156 | |
| 157 | ###: Lib/test/test_gettext.py:32 |
| 158 | ##msgid "bindtextdomain(None) failed" |
| 159 | ##msgstr "" |
| 160 | |
| 161 | ###: Lib/test/test_gettext.py:44 Lib/test/test_gettext.py:54 |
| 162 | ###: Lib/test/test_gettext.py:64 Lib/test/test_gettext.py:74 |
| 163 | ##msgid "Raymond Luxury Yach-t" |
| 164 | ##msgstr "" |
| 165 | |
| 166 | ###: Lib/test/test_gettext.py:41 Lib/test/test_gettext.py:51 |
| 167 | ###: Lib/test/test_gettext.py:61 Lib/test/test_gettext.py:71 |
| 168 | ##msgid "mullusk" |
| 169 | ##msgstr "" |
| 170 | |
| 171 | ###: Lib/test/test_gettext.py:38 |
| 172 | ##msgid "text domain didn't get set properly" |
| 173 | ##msgstr "" |
| 174 | |
| 175 | ###: Lib/test/test_gettext.py:98 |
| 176 | ##msgid "dcgettext failed" |
| 177 | ##msgstr "" |
| 178 | |
| 179 | ###: Lib/test/test_gettext.py:47 Lib/test/test_gettext.py:57 |
| 180 | ###: Lib/test/test_gettext.py:67 Lib/test/test_gettext.py:77 |
| 181 | ##msgid "nudge nudge" |
| 182 | ##msgstr "" |
| 183 | |
| 184 | ###: Lib/test/test_gettext.py:45 Lib/test/test_gettext.py:55 |
| 185 | ###: Lib/test/test_gettext.py:65 Lib/test/test_gettext.py:75 |
| 186 | ##msgid "raw string translation failed" |
| 187 | ##msgstr "" |
| 188 | |
| 189 | ###: Lib/test/test_gettext.py:30 |
| 190 | ##msgid "got unexpected localedir" |
| 191 | ##msgstr "" |
| 192 | |
| 193 | ###: Lib/test/test_gettext.py:48 Lib/test/test_gettext.py:58 |
| 194 | ###: Lib/test/test_gettext.py:68 Lib/test/test_gettext.py:78 |
| 195 | ##msgid "raw Unicode string translation failed" |
| 196 | ##msgstr "" |
| 197 | |
| 198 | ###: Lib/test/test_gettext.py:42 Lib/test/test_gettext.py:52 |
| 199 | ###: Lib/test/test_gettext.py:62 Lib/test/test_gettext.py:72 |
| 200 | ##msgid "Unicode translation failed" |
| 201 | ##msgstr "" |
| 202 | |
| 203 | ###: Lib/test/test_gettext.py:90 |
| 204 | ##msgid "multiline string translation failed" |
| 205 | ##msgstr "" |
| 206 | |
| 207 | ###: Lib/test/test_gettext.py:81 |
| 208 | ##msgid "" |
| 209 | ##"This module provides internationalization and localization\n" |
| 210 | ##"support for your Python programs by providing an interface to the GNU\n" |
| 211 | ##"gettext message catalog library." |
| 212 | ##msgstr "" |
| 213 | |
| 214 | ###: Lib/test/test_gettext.py:26 |
| 215 | ##msgid "calling bindtextdomain with localdir %s" |
| 216 | ##msgstr "" |
| 217 | |
| 218 | # =============================== messages.po |
| 219 | |
| 220 | ### Dummy translation for Python's test_gettext.py module. |
| 221 | ### Copyright (C) 2000 BeOpen.com |
| 222 | ### Barry Warsaw <bwarsaw@beopen.com>, 2000. |
| 223 | ### |
| 224 | ###, fuzzy |
| 225 | ##msgid "" |
| 226 | ##msgstr "" |
| 227 | ##"Project-Id-Version: PACKAGE VERSION\n" |
| 228 | ##"PO-Revision-Date: 2000-08-18 21:01-04:00\n" |
| 229 | ##"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 230 | ##"Language-Team: LANGUAGE <LL@li.org>\n" |
| 231 | ##"MIME-Version: 1.0\n" |
| 232 | ##"Content-Type: text/plain; charset=CHARSET\n" |
| 233 | ##"Content-Transfer-Encoding: ENCODING\n" |
| 234 | |
| 235 | ### SOME DESCRIPTIVE TITLE. |
| 236 | ### Copyright (C) YEAR ORGANIZATION |
| 237 | ### FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
| 238 | ### |
| 239 | ##msgid "" |
| 240 | ##msgstr "" |
| 241 | ##"Project-Id-Version: 2.0\n" |
| 242 | ##"PO-Revision-Date: Fri Aug 18 20:45:03 2000\n" |
| 243 | ##"Last-Translator: Barry Warsaw <bwarsaw@beopen.com>\n" |
| 244 | ##"Language-Team: XX <python-dev@python.org>\n" |
| 245 | ##"MIME-Version: 1.0\n" |
| 246 | ##"Content-Type: text/plain; charset=en\n" |
| 247 | ##"Content-Transfer-Encoding: none\n" |
| 248 | ##"Generated-By: pygettext.py 1.1\n" |
| 249 | |
| 250 | |
| 251 | ###: Lib/test/test_gettext.py:34 |
| 252 | ##msgid "calling textdomain" |
| 253 | ##msgstr "" |
| 254 | |
| 255 | ###: Lib/test/test_gettext.py:94 |
| 256 | ##msgid "dgettext failed" |
| 257 | ##msgstr "" |
| 258 | |
| 259 | ###: Lib/test/test_gettext.py:25 |
| 260 | ##msgid "gettext installed" |
| 261 | ##msgstr "" |
| 262 | |
| 263 | ###: Lib/test/test_gettext.py:32 |
| 264 | ##msgid "bindtextdomain(None) failed" |
| 265 | ##msgstr "" |
| 266 | |
| 267 | ###: Lib/test/test_gettext.py:44 Lib/test/test_gettext.py:54 |
| 268 | ###: Lib/test/test_gettext.py:64 Lib/test/test_gettext.py:74 |
| 269 | ##msgid "Raymond Luxury Yach-t" |
| 270 | ##msgstr "Throatwobbler Mangrove" |
| 271 | |
| 272 | ###: Lib/test/test_gettext.py:41 Lib/test/test_gettext.py:51 |
| 273 | ###: Lib/test/test_gettext.py:61 Lib/test/test_gettext.py:71 |
| 274 | ##msgid "mullusk" |
| 275 | ##msgstr "bacon" |
| 276 | |
| 277 | ###: Lib/test/test_gettext.py:38 |
| 278 | ##msgid "text domain didn't get set properly" |
| 279 | ##msgstr "" |
| 280 | |
| 281 | ###: Lib/test/test_gettext.py:98 |
| 282 | ##msgid "dcgettext failed" |
| 283 | ##msgstr "" |
| 284 | |
| 285 | ###: Lib/test/test_gettext.py:47 Lib/test/test_gettext.py:57 |
| 286 | ###: Lib/test/test_gettext.py:67 Lib/test/test_gettext.py:77 |
| 287 | ##msgid "nudge nudge" |
| 288 | ##msgstr "wink wink" |
| 289 | |
| 290 | ###: Lib/test/test_gettext.py:45 Lib/test/test_gettext.py:55 |
| 291 | ###: Lib/test/test_gettext.py:65 Lib/test/test_gettext.py:75 |
| 292 | ##msgid "raw string translation failed" |
| 293 | ##msgstr "" |
| 294 | |
| 295 | ###: Lib/test/test_gettext.py:30 |
| 296 | ##msgid "got unexpected localedir" |
| 297 | ##msgstr "" |
| 298 | |
| 299 | ###: Lib/test/test_gettext.py:48 Lib/test/test_gettext.py:58 |
| 300 | ###: Lib/test/test_gettext.py:68 Lib/test/test_gettext.py:78 |
| 301 | ##msgid "raw Unicode string translation failed" |
| 302 | ##msgstr "" |
| 303 | |
| 304 | ###: Lib/test/test_gettext.py:42 Lib/test/test_gettext.py:52 |
| 305 | ###: Lib/test/test_gettext.py:62 Lib/test/test_gettext.py:72 |
| 306 | ##msgid "Unicode translation failed" |
| 307 | ##msgstr "" |
| 308 | |
| 309 | ###: Lib/test/test_gettext.py:90 |
| 310 | ##msgid "multiline string translation failed" |
| 311 | ##msgstr "" |
| 312 | |
| 313 | ###: Lib/test/test_gettext.py:81 |
| 314 | ##msgid "" |
| 315 | ##"This module provides internationalization and localization\n" |
| 316 | ##"support for your Python programs by providing an interface to the GNU\n" |
| 317 | ##"gettext message catalog library." |
| 318 | ##msgstr "Guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba\n" |
| 319 | ##"fhccbeg sbe lbhe Clguba cebtenzf ol cebivqvat na vagresnpr gb gur TAH\n" |
| 320 | ##"trggrkg zrffntr pngnybt yvoenel." |
| 321 | |
| 322 | ###: Lib/test/test_gettext.py:26 |
| 323 | ##msgid "calling bindtextdomain with localdir %s" |
| 324 | ##msgstr "" |