2000-08-25 16:14:25 -03:00
|
|
|
import os
|
2000-08-25 16:50:38 -03:00
|
|
|
import base64
|
2000-08-25 16:14:25 -03:00
|
|
|
import gettext
|
2002-11-21 17:45:32 -04:00
|
|
|
import unittest
|
2023-10-09 10:45:22 -03:00
|
|
|
from functools import partial
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
|
2008-05-20 18:35:26 -03:00
|
|
|
from test import support
|
2020-07-09 10:25:10 -03:00
|
|
|
from test.support import os_helper
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
|
2000-10-23 14:22:08 -03:00
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
# TODO:
|
|
|
|
# - Add new tests, for example for "dgettext"
|
|
|
|
# - Remove dummy tests, for example testing for single and double quotes
|
|
|
|
# has no sense, it would have if we were testing a parser (i.e. pygettext)
|
|
|
|
# - Tests should have only one assert.
|
2000-08-30 00:32:07 -03:00
|
|
|
|
2007-08-27 14:23:59 -03:00
|
|
|
GNU_MO_DATA = b'''\
|
2018-11-07 10:12:20 -04:00
|
|
|
3hIElQAAAAAJAAAAHAAAAGQAAAAAAAAArAAAAAAAAACsAAAAFQAAAK0AAAAjAAAAwwAAAKEAAADn
|
|
|
|
AAAAMAAAAIkBAAAHAAAAugEAABYAAADCAQAAHAAAANkBAAALAAAA9gEAAEIBAAACAgAAFgAAAEUD
|
|
|
|
AAAeAAAAXAMAAKEAAAB7AwAAMgAAAB0EAAAFAAAAUAQAABsAAABWBAAAIQAAAHIEAAAJAAAAlAQA
|
|
|
|
AABSYXltb25kIEx1eHVyeSBZYWNoLXQAVGhlcmUgaXMgJXMgZmlsZQBUaGVyZSBhcmUgJXMgZmls
|
|
|
|
ZXMAVGhpcyBtb2R1bGUgcHJvdmlkZXMgaW50ZXJuYXRpb25hbGl6YXRpb24gYW5kIGxvY2FsaXph
|
|
|
|
dGlvbgpzdXBwb3J0IGZvciB5b3VyIFB5dGhvbiBwcm9ncmFtcyBieSBwcm92aWRpbmcgYW4gaW50
|
|
|
|
ZXJmYWNlIHRvIHRoZSBHTlUKZ2V0dGV4dCBtZXNzYWdlIGNhdGFsb2cgbGlicmFyeS4AV2l0aCBj
|
|
|
|
b250ZXh0BFRoZXJlIGlzICVzIGZpbGUAVGhlcmUgYXJlICVzIGZpbGVzAG11bGx1c2sAbXkgY29u
|
|
|
|
dGV4dARudWRnZSBudWRnZQBteSBvdGhlciBjb250ZXh0BG51ZGdlIG51ZGdlAG51ZGdlIG51ZGdl
|
|
|
|
AFByb2plY3QtSWQtVmVyc2lvbjogMi4wClBPLVJldmlzaW9uLURhdGU6IDIwMDMtMDQtMTEgMTQ6
|
|
|
|
MzItMDQwMApMYXN0LVRyYW5zbGF0b3I6IEouIERhdmlkIEliYW5leiA8ai1kYXZpZEBub29zLmZy
|
|
|
|
PgpMYW5ndWFnZS1UZWFtOiBYWCA8cHl0aG9uLWRldkBweXRob24ub3JnPgpNSU1FLVZlcnNpb246
|
|
|
|
IDEuMApDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9aXNvLTg4NTktMQpDb250ZW50
|
|
|
|
LVRyYW5zZmVyLUVuY29kaW5nOiA4Yml0CkdlbmVyYXRlZC1CeTogcHlnZXR0ZXh0LnB5IDEuMQpQ
|
|
|
|
bHVyYWwtRm9ybXM6IG5wbHVyYWxzPTI7IHBsdXJhbD1uIT0xOwoAVGhyb2F0d29iYmxlciBNYW5n
|
|
|
|
cm92ZQBIYXkgJXMgZmljaGVybwBIYXkgJXMgZmljaGVyb3MAR3V2ZiB6YnFoeXIgY2ViaXZxcmYg
|
|
|
|
dmFncmVhbmd2YmFueXZtbmd2YmEgbmFxIHlicG55dm1uZ3ZiYQpmaGNjYmVnIHNiZSBsYmhlIENs
|
|
|
|
Z3ViYSBjZWJ0ZW56ZiBvbCBjZWJpdnF2YXQgbmEgdmFncmVzbnByIGdiIGd1ciBUQUgKdHJnZ3Jr
|
|
|
|
ZyB6cmZmbnRyIHBuZ255YnQgeXZvZW5lbC4ASGF5ICVzIGZpY2hlcm8gKGNvbnRleHQpAEhheSAl
|
|
|
|
cyBmaWNoZXJvcyAoY29udGV4dCkAYmFjb24Ad2luayB3aW5rIChpbiAibXkgY29udGV4dCIpAHdp
|
|
|
|
bmsgd2luayAoaW4gIm15IG90aGVyIGNvbnRleHQiKQB3aW5rIHdpbmsA
|
2002-11-21 17:45:32 -04:00
|
|
|
'''
|
|
|
|
|
2014-10-28 16:17:51 -03:00
|
|
|
# This data contains an invalid major version number (5)
|
|
|
|
# An unexpected major version number should be treated as an error when
|
|
|
|
# parsing a .mo file
|
|
|
|
|
|
|
|
GNU_MO_DATA_BAD_MAJOR_VERSION = b'''\
|
|
|
|
3hIElQAABQAGAAAAHAAAAEwAAAALAAAAfAAAAAAAAACoAAAAFQAAAKkAAAAjAAAAvwAAAKEAAADj
|
|
|
|
AAAABwAAAIUBAAALAAAAjQEAAEUBAACZAQAAFgAAAN8CAAAeAAAA9gIAAKEAAAAVAwAABQAAALcD
|
|
|
|
AAAJAAAAvQMAAAEAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABQAAAAYAAAACAAAAAFJh
|
|
|
|
eW1vbmQgTHV4dXJ5IFlhY2gtdABUaGVyZSBpcyAlcyBmaWxlAFRoZXJlIGFyZSAlcyBmaWxlcwBU
|
|
|
|
aGlzIG1vZHVsZSBwcm92aWRlcyBpbnRlcm5hdGlvbmFsaXphdGlvbiBhbmQgbG9jYWxpemF0aW9u
|
|
|
|
CnN1cHBvcnQgZm9yIHlvdXIgUHl0aG9uIHByb2dyYW1zIGJ5IHByb3ZpZGluZyBhbiBpbnRlcmZh
|
|
|
|
Y2UgdG8gdGhlIEdOVQpnZXR0ZXh0IG1lc3NhZ2UgY2F0YWxvZyBsaWJyYXJ5LgBtdWxsdXNrAG51
|
|
|
|
ZGdlIG51ZGdlAFByb2plY3QtSWQtVmVyc2lvbjogMi4wClBPLVJldmlzaW9uLURhdGU6IDIwMDAt
|
|
|
|
MDgtMjkgMTI6MTktMDQ6MDAKTGFzdC1UcmFuc2xhdG9yOiBKLiBEYXZpZCBJYsOhw7FleiA8ai1k
|
|
|
|
YXZpZEBub29zLmZyPgpMYW5ndWFnZS1UZWFtOiBYWCA8cHl0aG9uLWRldkBweXRob24ub3JnPgpN
|
|
|
|
SU1FLVZlcnNpb246IDEuMApDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9aXNvLTg4
|
|
|
|
NTktMQpDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nOiBub25lCkdlbmVyYXRlZC1CeTogcHlnZXR0
|
|
|
|
ZXh0LnB5IDEuMQpQbHVyYWwtRm9ybXM6IG5wbHVyYWxzPTI7IHBsdXJhbD1uIT0xOwoAVGhyb2F0
|
|
|
|
d29iYmxlciBNYW5ncm92ZQBIYXkgJXMgZmljaGVybwBIYXkgJXMgZmljaGVyb3MAR3V2ZiB6YnFo
|
|
|
|
eXIgY2ViaXZxcmYgdmFncmVhbmd2YmFueXZtbmd2YmEgbmFxIHlicG55dm1uZ3ZiYQpmaGNjYmVn
|
|
|
|
IHNiZSBsYmhlIENsZ3ViYSBjZWJ0ZW56ZiBvbCBjZWJpdnF2YXQgbmEgdmFncmVzbnByIGdiIGd1
|
|
|
|
ciBUQUgKdHJnZ3JrZyB6cmZmbnRyIHBuZ255YnQgeXZvZW5lbC4AYmFjb24Ad2luayB3aW5rAA==
|
|
|
|
'''
|
|
|
|
|
|
|
|
# This data contains an invalid minor version number (7)
|
|
|
|
# An unexpected minor version number only indicates that some of the file's
|
|
|
|
# contents may not be able to be read. It does not indicate an error.
|
|
|
|
|
|
|
|
GNU_MO_DATA_BAD_MINOR_VERSION = b'''\
|
|
|
|
3hIElQcAAAAGAAAAHAAAAEwAAAALAAAAfAAAAAAAAACoAAAAFQAAAKkAAAAjAAAAvwAAAKEAAADj
|
|
|
|
AAAABwAAAIUBAAALAAAAjQEAAEUBAACZAQAAFgAAAN8CAAAeAAAA9gIAAKEAAAAVAwAABQAAALcD
|
|
|
|
AAAJAAAAvQMAAAEAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABQAAAAYAAAACAAAAAFJh
|
|
|
|
eW1vbmQgTHV4dXJ5IFlhY2gtdABUaGVyZSBpcyAlcyBmaWxlAFRoZXJlIGFyZSAlcyBmaWxlcwBU
|
|
|
|
aGlzIG1vZHVsZSBwcm92aWRlcyBpbnRlcm5hdGlvbmFsaXphdGlvbiBhbmQgbG9jYWxpemF0aW9u
|
|
|
|
CnN1cHBvcnQgZm9yIHlvdXIgUHl0aG9uIHByb2dyYW1zIGJ5IHByb3ZpZGluZyBhbiBpbnRlcmZh
|
|
|
|
Y2UgdG8gdGhlIEdOVQpnZXR0ZXh0IG1lc3NhZ2UgY2F0YWxvZyBsaWJyYXJ5LgBtdWxsdXNrAG51
|
|
|
|
ZGdlIG51ZGdlAFByb2plY3QtSWQtVmVyc2lvbjogMi4wClBPLVJldmlzaW9uLURhdGU6IDIwMDAt
|
|
|
|
MDgtMjkgMTI6MTktMDQ6MDAKTGFzdC1UcmFuc2xhdG9yOiBKLiBEYXZpZCBJYsOhw7FleiA8ai1k
|
|
|
|
YXZpZEBub29zLmZyPgpMYW5ndWFnZS1UZWFtOiBYWCA8cHl0aG9uLWRldkBweXRob24ub3JnPgpN
|
|
|
|
SU1FLVZlcnNpb246IDEuMApDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9aXNvLTg4
|
|
|
|
NTktMQpDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nOiBub25lCkdlbmVyYXRlZC1CeTogcHlnZXR0
|
|
|
|
ZXh0LnB5IDEuMQpQbHVyYWwtRm9ybXM6IG5wbHVyYWxzPTI7IHBsdXJhbD1uIT0xOwoAVGhyb2F0
|
|
|
|
d29iYmxlciBNYW5ncm92ZQBIYXkgJXMgZmljaGVybwBIYXkgJXMgZmljaGVyb3MAR3V2ZiB6YnFo
|
|
|
|
eXIgY2ViaXZxcmYgdmFncmVhbmd2YmFueXZtbmd2YmEgbmFxIHlicG55dm1uZ3ZiYQpmaGNjYmVn
|
|
|
|
IHNiZSBsYmhlIENsZ3ViYSBjZWJ0ZW56ZiBvbCBjZWJpdnF2YXQgbmEgdmFncmVzbnByIGdiIGd1
|
|
|
|
ciBUQUgKdHJnZ3JrZyB6cmZmbnRyIHBuZ255YnQgeXZvZW5lbC4AYmFjb24Ad2luayB3aW5rAA==
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
2007-08-27 14:23:59 -03:00
|
|
|
UMO_DATA = b'''\
|
2018-11-07 10:12:20 -04:00
|
|
|
3hIElQAAAAADAAAAHAAAADQAAAAAAAAAAAAAAAAAAABMAAAABAAAAE0AAAAQAAAAUgAAAA8BAABj
|
|
|
|
AAAABAAAAHMBAAAWAAAAeAEAAABhYsOeAG15Y29udGV4dMOeBGFiw54AUHJvamVjdC1JZC1WZXJz
|
|
|
|
aW9uOiAyLjAKUE8tUmV2aXNpb24tRGF0ZTogMjAwMy0wNC0xMSAxMjo0Mi0wNDAwCkxhc3QtVHJh
|
|
|
|
bnNsYXRvcjogQmFycnkgQS4gV0Fyc2F3IDxiYXJyeUBweXRob24ub3JnPgpMYW5ndWFnZS1UZWFt
|
|
|
|
OiBYWCA8cHl0aG9uLWRldkBweXRob24ub3JnPgpNSU1FLVZlcnNpb246IDEuMApDb250ZW50LVR5
|
|
|
|
cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgKQ29udGVudC1UcmFuc2Zlci1FbmNvZGluZzog
|
|
|
|
N2JpdApHZW5lcmF0ZWQtQnk6IG1hbnVhbGx5CgDCpHl6AMKkeXogKGNvbnRleHQgdmVyc2lvbikA
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
'''
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2007-08-27 14:23:59 -03:00
|
|
|
MMO_DATA = b'''\
|
2003-05-20 14:28:54 -03:00
|
|
|
3hIElQAAAAABAAAAHAAAACQAAAADAAAALAAAAAAAAAA4AAAAeAEAADkAAAABAAAAAAAAAAAAAAAA
|
|
|
|
UHJvamVjdC1JZC1WZXJzaW9uOiBObyBQcm9qZWN0IDAuMApQT1QtQ3JlYXRpb24tRGF0ZTogV2Vk
|
|
|
|
IERlYyAxMSAwNzo0NDoxNSAyMDAyClBPLVJldmlzaW9uLURhdGU6IDIwMDItMDgtMTQgMDE6MTg6
|
|
|
|
NTgrMDA6MDAKTGFzdC1UcmFuc2xhdG9yOiBKb2huIERvZSA8amRvZUBleGFtcGxlLmNvbT4KSmFu
|
|
|
|
ZSBGb29iYXIgPGpmb29iYXJAZXhhbXBsZS5jb20+Ckxhbmd1YWdlLVRlYW06IHh4IDx4eEBleGFt
|
|
|
|
cGxlLmNvbT4KTUlNRS1WZXJzaW9uOiAxLjAKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFy
|
|
|
|
c2V0PWlzby04ODU5LTE1CkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IHF1b3RlZC1wcmludGFi
|
|
|
|
bGUKR2VuZXJhdGVkLUJ5OiBweWdldHRleHQucHkgMS4zCgA=
|
|
|
|
'''
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
|
|
|
|
MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
|
2014-10-28 16:17:51 -03:00
|
|
|
MOFILE_BAD_MAJOR_VERSION = os.path.join(LOCALEDIR, 'gettext_bad_major_version.mo')
|
|
|
|
MOFILE_BAD_MINOR_VERSION = os.path.join(LOCALEDIR, 'gettext_bad_minor_version.mo')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
UMOFILE = os.path.join(LOCALEDIR, 'ugettext.mo')
|
2003-05-20 14:28:54 -03:00
|
|
|
MMOFILE = os.path.join(LOCALEDIR, 'metadata.mo')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
|
2023-10-07 10:00:28 -03:00
|
|
|
def reset_gettext():
|
|
|
|
gettext._localedirs.clear()
|
|
|
|
gettext._current_domain = 'messages'
|
|
|
|
gettext._translations.clear()
|
|
|
|
|
|
|
|
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
class GettextBaseTest(unittest.TestCase):
|
2023-10-09 10:45:22 -03:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
cls.addClassCleanup(os_helper.rmtree, os.path.split(LOCALEDIR)[0])
|
2004-07-18 21:08:59 -03:00
|
|
|
if not os.path.isdir(LOCALEDIR):
|
|
|
|
os.makedirs(LOCALEDIR)
|
2010-11-06 01:11:59 -03:00
|
|
|
with open(MOFILE, 'wb') as fp:
|
|
|
|
fp.write(base64.decodebytes(GNU_MO_DATA))
|
2014-10-28 16:17:51 -03:00
|
|
|
with open(MOFILE_BAD_MAJOR_VERSION, 'wb') as fp:
|
|
|
|
fp.write(base64.decodebytes(GNU_MO_DATA_BAD_MAJOR_VERSION))
|
|
|
|
with open(MOFILE_BAD_MINOR_VERSION, 'wb') as fp:
|
|
|
|
fp.write(base64.decodebytes(GNU_MO_DATA_BAD_MINOR_VERSION))
|
2010-11-06 01:11:59 -03:00
|
|
|
with open(UMOFILE, 'wb') as fp:
|
|
|
|
fp.write(base64.decodebytes(UMO_DATA))
|
|
|
|
with open(MMOFILE, 'wb') as fp:
|
|
|
|
fp.write(base64.decodebytes(MMO_DATA))
|
2023-10-09 10:45:22 -03:00
|
|
|
|
|
|
|
def setUp(self):
|
2022-05-08 11:49:09 -03:00
|
|
|
self.env = self.enterContext(os_helper.EnvironmentVarGuard())
|
2009-05-01 16:58:58 -03:00
|
|
|
self.env['LANGUAGE'] = 'xx'
|
2023-10-07 10:00:28 -03:00
|
|
|
reset_gettext()
|
|
|
|
self.addCleanup(reset_gettext)
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2015-04-13 11:38:56 -03:00
|
|
|
GNU_MO_DATA_ISSUE_17898 = b'''\
|
|
|
|
3hIElQAAAAABAAAAHAAAACQAAAAAAAAAAAAAAAAAAAAsAAAAggAAAC0AAAAAUGx1cmFsLUZvcm1z
|
|
|
|
OiBucGx1cmFscz0yOyBwbHVyYWw9KG4gIT0gMSk7CiMtIy0jLSMtIyAgbWVzc2FnZXMucG8gKEVk
|
|
|
|
WCBTdHVkaW8pICAjLSMtIy0jLSMKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PVVU
|
|
|
|
Ri04CgA=
|
|
|
|
'''
|
2000-08-25 16:50:38 -03:00
|
|
|
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
class GettextTestCase1(GettextBaseTest):
|
2002-11-21 17:45:32 -04:00
|
|
|
def setUp(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
GettextBaseTest.setUp(self)
|
2002-11-21 17:45:32 -04:00
|
|
|
self.localedir = os.curdir
|
|
|
|
self.mofile = MOFILE
|
2018-11-07 10:12:20 -04:00
|
|
|
gettext.install('gettext', self.localedir, names=['pgettext'])
|
2000-08-25 16:50:38 -03:00
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_some_translations(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# test some translations
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_('albatross'), 'albatross')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(_('mullusk'), 'bacon')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_(r'Raymond Luxury Yach-t'), 'Throatwobbler Mangrove')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(_(r'nudge nudge'), 'wink wink')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2018-11-07 10:12:20 -04:00
|
|
|
def test_some_translations_with_context(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
eq(pgettext('my context', 'nudge nudge'),
|
|
|
|
'wink wink (in "my context")')
|
|
|
|
eq(pgettext('my other context', 'nudge nudge'),
|
|
|
|
'wink wink (in "my other context")')
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_double_quotes(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# double quotes
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_("albatross"), 'albatross')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(_("mullusk"), 'bacon')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_(r"Raymond Luxury Yach-t"), 'Throatwobbler Mangrove')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(_(r"nudge nudge"), 'wink wink')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_triple_single_quotes(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# triple single quotes
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_('''albatross'''), 'albatross')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(_('''mullusk'''), 'bacon')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_(r'''Raymond Luxury Yach-t'''), 'Throatwobbler Mangrove')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(_(r'''nudge nudge'''), 'wink wink')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_triple_double_quotes(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# triple double quotes
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_("""albatross"""), 'albatross')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(_("""mullusk"""), 'bacon')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_(r"""Raymond Luxury Yach-t"""), 'Throatwobbler Mangrove')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(_(r"""nudge nudge"""), 'wink wink')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_multiline_strings(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# multiline strings
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_('''This module provides internationalization and localization
|
2000-08-25 16:14:25 -03:00
|
|
|
support for your Python programs by providing an interface to the GNU
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
gettext message catalog library.'''),
|
|
|
|
'''Guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba
|
2002-11-21 17:45:32 -04:00
|
|
|
fhccbeg sbe lbhe Clguba cebtenzf ol cebivqvat na vagresnpr gb gur TAH
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
trggrkg zrffntr pngnybt yvoenel.''')
|
2000-08-25 16:50:38 -03:00
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_the_alternative_interface(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2021-05-29 22:29:45 -03:00
|
|
|
neq = self.assertNotEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# test the alternative interface
|
2010-11-06 01:11:59 -03:00
|
|
|
with open(self.mofile, 'rb') as fp:
|
|
|
|
t = gettext.GNUTranslations(fp)
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
# Install the translation object
|
2002-11-21 17:45:32 -04:00
|
|
|
t.install()
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_('nudge nudge'), 'wink wink')
|
|
|
|
# Try unicode return type
|
2008-07-14 11:32:15 -03:00
|
|
|
t.install()
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(_('mullusk'), 'bacon')
|
2006-02-19 09:26:36 -04:00
|
|
|
# Test installation of other methods
|
2007-12-02 05:40:06 -04:00
|
|
|
import builtins
|
2021-05-29 22:29:45 -03:00
|
|
|
t.install(names=["gettext", "ngettext"])
|
2008-07-14 11:32:15 -03:00
|
|
|
eq(_, t.gettext)
|
|
|
|
eq(builtins.gettext, t.gettext)
|
2021-05-29 22:29:45 -03:00
|
|
|
eq(ngettext, t.ngettext)
|
|
|
|
neq(pgettext, t.pgettext)
|
2007-12-02 05:40:06 -04:00
|
|
|
del builtins.gettext
|
2021-05-29 22:29:45 -03:00
|
|
|
del builtins.ngettext
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2000-08-25 16:50:38 -03:00
|
|
|
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
class GettextTestCase2(GettextBaseTest):
|
2002-11-21 17:45:32 -04:00
|
|
|
def setUp(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
GettextBaseTest.setUp(self)
|
2002-11-21 17:45:32 -04:00
|
|
|
self.localedir = os.curdir
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
# Set up the bindings
|
2002-11-21 17:45:32 -04:00
|
|
|
gettext.bindtextdomain('gettext', self.localedir)
|
|
|
|
gettext.textdomain('gettext')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
# For convenience
|
2002-11-21 17:45:32 -04:00
|
|
|
self._ = gettext.gettext
|
2000-08-30 00:32:07 -03:00
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_bindtextdomain(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir)
|
2000-08-30 00:32:07 -03:00
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_textdomain(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
self.assertEqual(gettext.textdomain(), 'gettext')
|
2000-08-30 00:32:07 -03:00
|
|
|
|
2014-10-28 16:17:51 -03:00
|
|
|
def test_bad_major_version(self):
|
|
|
|
with open(MOFILE_BAD_MAJOR_VERSION, 'rb') as fp:
|
|
|
|
with self.assertRaises(OSError) as cm:
|
|
|
|
gettext.GNUTranslations(fp)
|
|
|
|
|
|
|
|
exception = cm.exception
|
|
|
|
self.assertEqual(exception.errno, 0)
|
|
|
|
self.assertEqual(exception.strerror, "Bad version number 5")
|
|
|
|
self.assertEqual(exception.filename, MOFILE_BAD_MAJOR_VERSION)
|
|
|
|
|
|
|
|
def test_bad_minor_version(self):
|
|
|
|
with open(MOFILE_BAD_MINOR_VERSION, 'rb') as fp:
|
|
|
|
# Check that no error is thrown with a bad minor version number
|
|
|
|
gettext.GNUTranslations(fp)
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_some_translations(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# test some translations
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._('albatross'), 'albatross')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(self._('mullusk'), 'bacon')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._(r'Raymond Luxury Yach-t'), 'Throatwobbler Mangrove')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(self._(r'nudge nudge'), 'wink wink')
|
2000-08-30 00:32:07 -03:00
|
|
|
|
2018-11-07 10:12:20 -04:00
|
|
|
def test_some_translations_with_context(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
eq(gettext.pgettext('my context', 'nudge nudge'),
|
|
|
|
'wink wink (in "my context")')
|
|
|
|
eq(gettext.pgettext('my other context', 'nudge nudge'),
|
|
|
|
'wink wink (in "my other context")')
|
|
|
|
|
|
|
|
def test_some_translations_with_context_and_domain(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
eq(gettext.dpgettext('gettext', 'my context', 'nudge nudge'),
|
|
|
|
'wink wink (in "my context")')
|
|
|
|
eq(gettext.dpgettext('gettext', 'my other context', 'nudge nudge'),
|
|
|
|
'wink wink (in "my other context")')
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_double_quotes(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# double quotes
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._("albatross"), 'albatross')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(self._("mullusk"), 'bacon')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._(r"Raymond Luxury Yach-t"), 'Throatwobbler Mangrove')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(self._(r"nudge nudge"), 'wink wink')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_triple_single_quotes(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# triple single quotes
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._('''albatross'''), 'albatross')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(self._('''mullusk'''), 'bacon')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._(r'''Raymond Luxury Yach-t'''), 'Throatwobbler Mangrove')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(self._(r'''nudge nudge'''), 'wink wink')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_triple_double_quotes(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# triple double quotes
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._("""albatross"""), 'albatross')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(self._("""mullusk"""), 'bacon')
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._(r"""Raymond Luxury Yach-t"""), 'Throatwobbler Mangrove')
|
2007-05-02 16:09:54 -03:00
|
|
|
eq(self._(r"""nudge nudge"""), 'wink wink')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_multiline_strings(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# multiline strings
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(self._('''This module provides internationalization and localization
|
2000-08-30 00:32:07 -03:00
|
|
|
support for your Python programs by providing an interface to the GNU
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
gettext message catalog library.'''),
|
|
|
|
'''Guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba
|
2002-11-21 17:45:32 -04:00
|
|
|
fhccbeg sbe lbhe Clguba cebtenzf ol cebivqvat na vagresnpr gb gur TAH
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
trggrkg zrffntr pngnybt yvoenel.''')
|
2000-08-30 00:32:07 -03:00
|
|
|
|
|
|
|
|
2023-10-09 10:45:22 -03:00
|
|
|
class PluralFormsTests:
|
|
|
|
|
|
|
|
def _test_plural_forms(self, ngettext, gettext,
|
|
|
|
singular, plural, tsingular, tplural,
|
|
|
|
numbers_only=True):
|
|
|
|
x = ngettext(singular, plural, 1)
|
|
|
|
self.assertEqual(x, tsingular)
|
|
|
|
x = ngettext(singular, plural, 2)
|
|
|
|
self.assertEqual(x, tplural)
|
|
|
|
x = gettext(singular)
|
|
|
|
self.assertEqual(x, tsingular)
|
|
|
|
|
2023-10-14 03:07:02 -03:00
|
|
|
lineno = self._test_plural_forms.__code__.co_firstlineno + 12
|
|
|
|
with self.assertWarns(DeprecationWarning) as cm:
|
|
|
|
x = ngettext(singular, plural, 1.0)
|
|
|
|
self.assertEqual(cm.filename, __file__)
|
|
|
|
self.assertEqual(cm.lineno, lineno)
|
|
|
|
self.assertEqual(x, tsingular)
|
|
|
|
with self.assertWarns(DeprecationWarning) as cm:
|
|
|
|
x = ngettext(singular, plural, 1.1)
|
|
|
|
self.assertEqual(cm.filename, __file__)
|
|
|
|
self.assertEqual(cm.lineno, lineno + 5)
|
|
|
|
self.assertEqual(x, tplural)
|
|
|
|
|
2023-10-09 10:45:22 -03:00
|
|
|
if numbers_only:
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
ngettext(singular, plural, None)
|
|
|
|
else:
|
2023-10-14 03:07:02 -03:00
|
|
|
with self.assertWarns(DeprecationWarning) as cm:
|
|
|
|
x = ngettext(singular, plural, None)
|
2023-10-09 10:45:22 -03:00
|
|
|
self.assertEqual(x, tplural)
|
|
|
|
|
|
|
|
def test_plural_forms(self):
|
|
|
|
self._test_plural_forms(
|
|
|
|
self.ngettext, self.gettext,
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
'Hay %s fichero', 'Hay %s ficheros')
|
|
|
|
self._test_plural_forms(
|
|
|
|
self.ngettext, self.gettext,
|
|
|
|
'%d file deleted', '%d files deleted',
|
|
|
|
'%d file deleted', '%d files deleted')
|
|
|
|
|
|
|
|
def test_plural_context_forms(self):
|
|
|
|
ngettext = partial(self.npgettext, 'With context')
|
|
|
|
gettext = partial(self.pgettext, 'With context')
|
|
|
|
self._test_plural_forms(
|
|
|
|
ngettext, gettext,
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
'Hay %s fichero (context)', 'Hay %s ficheros (context)')
|
|
|
|
self._test_plural_forms(
|
|
|
|
ngettext, gettext,
|
|
|
|
'%d file deleted', '%d files deleted',
|
|
|
|
'%d file deleted', '%d files deleted')
|
|
|
|
|
|
|
|
def test_plural_wrong_context_forms(self):
|
|
|
|
self._test_plural_forms(
|
|
|
|
partial(self.npgettext, 'Unknown context'),
|
|
|
|
partial(self.pgettext, 'Unknown context'),
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
'There is %s file', 'There are %s files')
|
|
|
|
|
|
|
|
|
|
|
|
class GNUTranslationsPluralFormsTestCase(PluralFormsTests, GettextBaseTest):
|
2002-11-21 17:45:32 -04:00
|
|
|
def setUp(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
GettextBaseTest.setUp(self)
|
2023-10-07 10:00:28 -03:00
|
|
|
# Set up the bindings
|
2023-10-09 10:45:22 -03:00
|
|
|
gettext.bindtextdomain('gettext', os.curdir)
|
2023-10-07 10:00:28 -03:00
|
|
|
gettext.textdomain('gettext')
|
2000-08-25 16:50:38 -03:00
|
|
|
|
2023-10-09 10:45:22 -03:00
|
|
|
self.gettext = gettext.gettext
|
|
|
|
self.ngettext = gettext.ngettext
|
|
|
|
self.pgettext = gettext.pgettext
|
|
|
|
self.npgettext = gettext.npgettext
|
|
|
|
|
|
|
|
|
|
|
|
class GNUTranslationsWithDomainPluralFormsTestCase(PluralFormsTests, GettextBaseTest):
|
|
|
|
def setUp(self):
|
|
|
|
GettextBaseTest.setUp(self)
|
|
|
|
# Set up the bindings
|
|
|
|
gettext.bindtextdomain('gettext', os.curdir)
|
|
|
|
|
|
|
|
self.gettext = partial(gettext.dgettext, 'gettext')
|
|
|
|
self.ngettext = partial(gettext.dngettext, 'gettext')
|
|
|
|
self.pgettext = partial(gettext.dpgettext, 'gettext')
|
|
|
|
self.npgettext = partial(gettext.dnpgettext, 'gettext')
|
|
|
|
|
|
|
|
def test_plural_forms_wrong_domain(self):
|
|
|
|
self._test_plural_forms(
|
|
|
|
partial(gettext.dngettext, 'unknown'),
|
|
|
|
partial(gettext.dgettext, 'unknown'),
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
numbers_only=False)
|
|
|
|
|
|
|
|
def test_plural_context_forms_wrong_domain(self):
|
|
|
|
self._test_plural_forms(
|
|
|
|
partial(gettext.dnpgettext, 'unknown', 'With context'),
|
|
|
|
partial(gettext.dpgettext, 'unknown', 'With context'),
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
numbers_only=False)
|
|
|
|
|
|
|
|
|
|
|
|
class GNUTranslationsClassPluralFormsTestCase(PluralFormsTests, GettextBaseTest):
|
|
|
|
def setUp(self):
|
|
|
|
GettextBaseTest.setUp(self)
|
|
|
|
with open(MOFILE, 'rb') as fp:
|
2018-11-07 10:12:20 -04:00
|
|
|
t = gettext.GNUTranslations(fp)
|
|
|
|
|
2023-10-09 10:45:22 -03:00
|
|
|
self.gettext = t.gettext
|
|
|
|
self.ngettext = t.ngettext
|
|
|
|
self.pgettext = t.pgettext
|
|
|
|
self.npgettext = t.npgettext
|
|
|
|
|
|
|
|
def test_plural_forms_null_translations(self):
|
|
|
|
t = gettext.NullTranslations()
|
|
|
|
self._test_plural_forms(
|
|
|
|
t.ngettext, t.gettext,
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
numbers_only=False)
|
|
|
|
|
|
|
|
def test_plural_context_forms_null_translations(self):
|
|
|
|
t = gettext.NullTranslations()
|
|
|
|
self._test_plural_forms(
|
|
|
|
partial(t.npgettext, 'With context'),
|
|
|
|
partial(t.pgettext, 'With context'),
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
'There is %s file', 'There are %s files',
|
|
|
|
numbers_only=False)
|
|
|
|
|
|
|
|
|
|
|
|
class PluralFormsInternalTestCase:
|
2016-11-08 15:17:46 -04:00
|
|
|
# Examples from http://www.gnu.org/software/gettext/manual/gettext.html
|
|
|
|
|
|
|
|
def test_ja(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
f = gettext.c2py('0')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_de(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
f = gettext.c2py('n != 1')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_fr(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
f = gettext.c2py('n>1')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "00111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
|
2000-08-25 16:50:38 -03:00
|
|
|
|
2016-11-08 15:17:46 -04:00
|
|
|
def test_lv(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
|
|
|
eq(s, "20111111111111111111101111111110111111111011111111101111111110111111111011111111101111111110111111111011111111111111111110111111111011111111101111111110111111111011111111101111111110111111111011111111")
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_gd(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
f = gettext.c2py('n==1 ? 0 : n==2 ? 1 : 2')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "20122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_gd2(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
# Tests the combination of parentheses and "?:"
|
|
|
|
f = gettext.c2py('n==1 ? 0 : (n==2 ? 1 : 2)')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "20122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2016-11-08 15:17:46 -04:00
|
|
|
def test_ro(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
f = gettext.c2py('n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
|
|
|
eq(s, "10111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222")
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_lt(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "20111111112222222222201111111120111111112011111111201111111120111111112011111111201111111120111111112011111111222222222220111111112011111111201111111120111111112011111111201111111120111111112011111111")
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_ru(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "20111222222222222222201112222220111222222011122222201112222220111222222011122222201112222220111222222011122222222222222220111222222011122222201112222220111222222011122222201112222220111222222011122222")
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2016-11-08 15:17:46 -04:00
|
|
|
def test_cs(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
f = gettext.c2py('(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
|
|
|
eq(s, "20111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_pl(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
f = gettext.c2py('n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "20111222222222222222221112222222111222222211122222221112222222111222222211122222221112222222111222222211122222222222222222111222222211122222221112222222111222222211122222221112222222111222222211122222")
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
def test_sl(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq = self.assertEqual
|
2002-11-21 17:45:32 -04:00
|
|
|
f = gettext.c2py('n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
eq(s, "30122333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333012233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333")
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2016-11-08 15:17:46 -04:00
|
|
|
def test_ar(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
f = gettext.c2py('n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5')
|
|
|
|
s = ''.join([ str(f(x)) for x in range(200) ])
|
|
|
|
eq(s, "01233333333444444444444444444444444444444444444444444444444444444444444444444444444444444444444444445553333333344444444444444444444444444444444444444444444444444444444444444444444444444444444444444444")
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
def test_security(self):
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
raises = self.assertRaises
|
2002-11-21 17:45:32 -04:00
|
|
|
# Test for a dangerous expression
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
raises(ValueError, gettext.c2py, "os.chmod('/etc/passwd',0777)")
|
2016-11-08 15:17:46 -04:00
|
|
|
# issue28563
|
|
|
|
raises(ValueError, gettext.c2py, '"(eval(foo) && ""')
|
|
|
|
raises(ValueError, gettext.c2py, 'f"{os.system(\'sh\')}"')
|
|
|
|
# Maximum recursion depth exceeded during compilation
|
|
|
|
raises(ValueError, gettext.c2py, 'n+'*10000 + 'n')
|
|
|
|
self.assertEqual(gettext.c2py('n+'*100 + 'n')(1), 101)
|
|
|
|
# MemoryError during compilation
|
|
|
|
raises(ValueError, gettext.c2py, '('*100 + 'n' + ')'*100)
|
|
|
|
# Maximum recursion depth exceeded in C to Python translator
|
|
|
|
raises(ValueError, gettext.c2py, '('*10000 + 'n' + ')'*10000)
|
|
|
|
self.assertEqual(gettext.c2py('('*20 + 'n' + ')'*20)(1), 1)
|
|
|
|
|
|
|
|
def test_chained_comparison(self):
|
|
|
|
# C doesn't chain comparison as Python so 2 == 2 == 2 gets different results
|
|
|
|
f = gettext.c2py('n == n == n')
|
|
|
|
self.assertEqual(''.join(str(f(x)) for x in range(3)), '010')
|
|
|
|
f = gettext.c2py('1 < n == n')
|
|
|
|
self.assertEqual(''.join(str(f(x)) for x in range(3)), '100')
|
|
|
|
f = gettext.c2py('n == n < 2')
|
|
|
|
self.assertEqual(''.join(str(f(x)) for x in range(3)), '010')
|
|
|
|
f = gettext.c2py('0 < n < 2')
|
|
|
|
self.assertEqual(''.join(str(f(x)) for x in range(3)), '111')
|
|
|
|
|
|
|
|
def test_decimal_number(self):
|
|
|
|
self.assertEqual(gettext.c2py('0123')(1), 123)
|
|
|
|
|
|
|
|
def test_invalid_syntax(self):
|
|
|
|
invalid_expressions = [
|
|
|
|
'x>1', '(n>1', 'n>1)', '42**42**42', '0xa', '1.0', '1e2',
|
|
|
|
'n>0x1', '+n', '-n', 'n()', 'n(1)', '1+', 'nn', 'n n',
|
|
|
|
]
|
|
|
|
for expr in invalid_expressions:
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
gettext.c2py(expr)
|
|
|
|
|
|
|
|
def test_nested_condition_operator(self):
|
|
|
|
self.assertEqual(gettext.c2py('n?1?2:3:4')(0), 4)
|
|
|
|
self.assertEqual(gettext.c2py('n?1?2:3:4')(1), 2)
|
|
|
|
self.assertEqual(gettext.c2py('n?1:3?4:5')(0), 4)
|
|
|
|
self.assertEqual(gettext.c2py('n?1:3?4:5')(1), 1)
|
|
|
|
|
|
|
|
def test_division(self):
|
|
|
|
f = gettext.c2py('2/n*3')
|
|
|
|
self.assertEqual(f(1), 6)
|
|
|
|
self.assertEqual(f(2), 3)
|
|
|
|
self.assertEqual(f(3), 0)
|
|
|
|
self.assertEqual(f(-1), -6)
|
|
|
|
self.assertRaises(ZeroDivisionError, f, 0)
|
|
|
|
|
|
|
|
def test_plural_number(self):
|
2016-11-14 13:22:12 -04:00
|
|
|
f = gettext.c2py('n != 1')
|
|
|
|
self.assertEqual(f(1), 0)
|
|
|
|
self.assertEqual(f(2), 1)
|
2017-03-12 08:15:01 -03:00
|
|
|
with self.assertWarns(DeprecationWarning):
|
|
|
|
self.assertEqual(f(1.0), 0)
|
|
|
|
with self.assertWarns(DeprecationWarning):
|
|
|
|
self.assertEqual(f(2.0), 1)
|
|
|
|
with self.assertWarns(DeprecationWarning):
|
|
|
|
self.assertEqual(f(1.1), 1)
|
2016-11-14 13:22:12 -04:00
|
|
|
self.assertRaises(TypeError, f, '2')
|
|
|
|
self.assertRaises(TypeError, f, b'2')
|
|
|
|
self.assertRaises(TypeError, f, [])
|
|
|
|
self.assertRaises(TypeError, f, object())
|
2016-11-08 15:17:46 -04:00
|
|
|
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
|
2015-04-13 11:38:56 -03:00
|
|
|
class GNUTranslationParsingTest(GettextBaseTest):
|
|
|
|
def test_plural_form_error_issue17898(self):
|
|
|
|
with open(MOFILE, 'wb') as fp:
|
|
|
|
fp.write(base64.decodebytes(GNU_MO_DATA_ISSUE_17898))
|
|
|
|
with open(MOFILE, 'rb') as fp:
|
|
|
|
# If this runs cleanly, the bug is fixed.
|
|
|
|
t = gettext.GNUTranslations(fp)
|
|
|
|
|
2019-05-09 11:22:15 -03:00
|
|
|
def test_ignore_comments_in_headers_issue36239(self):
|
|
|
|
"""Checks that comments like:
|
|
|
|
|
|
|
|
#-#-#-#-# messages.po (EdX Studio) #-#-#-#-#
|
|
|
|
|
|
|
|
are ignored.
|
|
|
|
"""
|
|
|
|
with open(MOFILE, 'wb') as fp:
|
|
|
|
fp.write(base64.decodebytes(GNU_MO_DATA_ISSUE_17898))
|
|
|
|
with open(MOFILE, 'rb') as fp:
|
|
|
|
t = gettext.GNUTranslations(fp)
|
|
|
|
self.assertEqual(t.info()["plural-forms"], "nplurals=2; plural=(n != 1);")
|
|
|
|
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
|
|
|
|
class UnicodeTranslationsTest(GettextBaseTest):
|
|
|
|
def setUp(self):
|
|
|
|
GettextBaseTest.setUp(self)
|
2010-11-06 01:11:59 -03:00
|
|
|
with open(UMOFILE, 'rb') as fp:
|
2003-04-24 15:08:13 -03:00
|
|
|
self.t = gettext.GNUTranslations(fp)
|
2008-07-14 11:32:15 -03:00
|
|
|
self._ = self.t.gettext
|
2018-11-07 10:12:20 -04:00
|
|
|
self.pgettext = self.t.pgettext
|
2002-11-21 17:45:32 -04:00
|
|
|
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
def test_unicode_msgid(self):
|
2017-06-20 11:13:29 -03:00
|
|
|
self.assertIsInstance(self._(''), str)
|
2002-11-21 17:45:32 -04:00
|
|
|
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
def test_unicode_msgstr(self):
|
2017-06-20 11:13:29 -03:00
|
|
|
self.assertEqual(self._('ab\xde'), '\xa4yz')
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2018-11-07 10:12:20 -04:00
|
|
|
def test_unicode_context_msgstr(self):
|
|
|
|
t = self.pgettext('mycontext\xde', 'ab\xde')
|
|
|
|
self.assertTrue(isinstance(t, str))
|
|
|
|
self.assertEqual(t, '\xa4yz (context version)')
|
|
|
|
|
|
|
|
|
|
|
|
class UnicodeTranslationsPluralTest(GettextBaseTest):
|
|
|
|
def setUp(self):
|
|
|
|
GettextBaseTest.setUp(self)
|
|
|
|
with open(MOFILE, 'rb') as fp:
|
|
|
|
self.t = gettext.GNUTranslations(fp)
|
|
|
|
self.ngettext = self.t.ngettext
|
|
|
|
self.npgettext = self.t.npgettext
|
|
|
|
|
|
|
|
def test_unicode_msgid(self):
|
|
|
|
unless = self.assertTrue
|
|
|
|
unless(isinstance(self.ngettext('', '', 1), str))
|
|
|
|
unless(isinstance(self.ngettext('', '', 2), str))
|
|
|
|
|
|
|
|
def test_unicode_context_msgid(self):
|
|
|
|
unless = self.assertTrue
|
|
|
|
unless(isinstance(self.npgettext('', '', '', 1), str))
|
|
|
|
unless(isinstance(self.npgettext('', '', '', 2), str))
|
|
|
|
|
|
|
|
def test_unicode_msgstr(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
unless = self.assertTrue
|
|
|
|
t = self.ngettext("There is %s file", "There are %s files", 1)
|
|
|
|
unless(isinstance(t, str))
|
|
|
|
eq(t, "Hay %s fichero")
|
|
|
|
unless(isinstance(t, str))
|
|
|
|
t = self.ngettext("There is %s file", "There are %s files", 5)
|
|
|
|
unless(isinstance(t, str))
|
|
|
|
eq(t, "Hay %s ficheros")
|
|
|
|
|
|
|
|
def test_unicode_msgstr_with_context(self):
|
|
|
|
eq = self.assertEqual
|
|
|
|
unless = self.assertTrue
|
|
|
|
t = self.npgettext("With context",
|
|
|
|
"There is %s file", "There are %s files", 1)
|
|
|
|
unless(isinstance(t, str))
|
|
|
|
eq(t, "Hay %s fichero (context)")
|
|
|
|
t = self.npgettext("With context",
|
|
|
|
"There is %s file", "There are %s files", 5)
|
|
|
|
unless(isinstance(t, str))
|
|
|
|
eq(t, "Hay %s ficheros (context)")
|
|
|
|
|
2002-11-21 17:45:32 -04:00
|
|
|
|
2003-05-20 14:28:54 -03:00
|
|
|
class WeirdMetadataTest(GettextBaseTest):
|
|
|
|
def setUp(self):
|
|
|
|
GettextBaseTest.setUp(self)
|
2010-11-06 01:11:59 -03:00
|
|
|
with open(MMOFILE, 'rb') as fp:
|
2003-05-20 14:28:54 -03:00
|
|
|
try:
|
|
|
|
self.t = gettext.GNUTranslations(fp)
|
|
|
|
except:
|
|
|
|
self.tearDown()
|
|
|
|
raise
|
|
|
|
|
|
|
|
def test_weird_metadata(self):
|
|
|
|
info = self.t.info()
|
2007-10-31 15:53:44 -03:00
|
|
|
self.assertEqual(len(info), 9)
|
2003-05-20 14:28:54 -03:00
|
|
|
self.assertEqual(info['last-translator'],
|
|
|
|
'John Doe <jdoe@example.com>\nJane Foobar <jfoobar@example.com>')
|
|
|
|
|
|
|
|
|
2010-10-04 20:52:37 -03:00
|
|
|
class DummyGNUTranslations(gettext.GNUTranslations):
|
|
|
|
def foo(self):
|
|
|
|
return 'foo'
|
|
|
|
|
|
|
|
|
|
|
|
class GettextCacheTestCase(GettextBaseTest):
|
|
|
|
def test_cache(self):
|
|
|
|
self.localedir = os.curdir
|
|
|
|
self.mofile = MOFILE
|
|
|
|
|
|
|
|
self.assertEqual(len(gettext._translations), 0)
|
|
|
|
|
|
|
|
t = gettext.translation('gettext', self.localedir)
|
|
|
|
|
|
|
|
self.assertEqual(len(gettext._translations), 1)
|
|
|
|
|
|
|
|
t = gettext.translation('gettext', self.localedir,
|
|
|
|
class_=DummyGNUTranslations)
|
|
|
|
|
|
|
|
self.assertEqual(len(gettext._translations), 2)
|
|
|
|
self.assertEqual(t.__class__, DummyGNUTranslations)
|
|
|
|
|
|
|
|
# Calling it again doesn't add to the cache
|
|
|
|
|
|
|
|
t = gettext.translation('gettext', self.localedir,
|
|
|
|
class_=DummyGNUTranslations)
|
|
|
|
|
|
|
|
self.assertEqual(len(gettext._translations), 2)
|
|
|
|
self.assertEqual(t.__class__, DummyGNUTranslations)
|
|
|
|
|
|
|
|
|
2015-11-14 07:47:00 -04:00
|
|
|
class MiscTestCase(unittest.TestCase):
|
|
|
|
def test__all__(self):
|
2020-08-17 02:20:40 -03:00
|
|
|
support.check__all__(self, gettext,
|
|
|
|
not_exported={'c2py', 'ENOENT'})
|
2015-11-14 07:47:00 -04:00
|
|
|
|
|
|
|
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
if __name__ == '__main__':
|
2018-10-27 02:00:41 -03:00
|
|
|
unittest.main()
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
|
|
|
|
|
|
|
|
# For reference, here's the .po file used to created the GNU_MO_DATA above.
|
2002-11-21 17:45:32 -04:00
|
|
|
#
|
|
|
|
# The original version was automatically generated from the sources with
|
|
|
|
# pygettext. Later it was manually modified to add plural forms support.
|
2000-08-30 00:32:07 -03:00
|
|
|
|
2017-06-20 11:13:29 -03:00
|
|
|
b'''
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
# Dummy translation for the Python test_gettext.py module.
|
2001-08-24 16:11:57 -03:00
|
|
|
# Copyright (C) 2001 Python Software Foundation
|
|
|
|
# Barry Warsaw <barry@python.org>, 2000.
|
2000-08-30 00:32:07 -03:00
|
|
|
#
|
|
|
|
msgid ""
|
|
|
|
msgstr ""
|
|
|
|
"Project-Id-Version: 2.0\n"
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
"PO-Revision-Date: 2003-04-11 14:32-0400\n"
|
2002-11-21 17:45:32 -04:00
|
|
|
"Last-Translator: J. David Ibanez <j-david@noos.fr>\n"
|
2000-08-30 00:32:07 -03:00
|
|
|
"Language-Team: XX <python-dev@python.org>\n"
|
|
|
|
"MIME-Version: 1.0\n"
|
2002-11-21 17:45:32 -04:00
|
|
|
"Content-Type: text/plain; charset=iso-8859-1\n"
|
|
|
|
"Content-Transfer-Encoding: 8bit\n"
|
2000-08-30 00:32:07 -03:00
|
|
|
"Generated-By: pygettext.py 1.1\n"
|
2002-11-21 17:45:32 -04:00
|
|
|
"Plural-Forms: nplurals=2; plural=n!=1;\n"
|
2000-08-30 00:32:07 -03:00
|
|
|
|
|
|
|
#: test_gettext.py:19 test_gettext.py:25 test_gettext.py:31 test_gettext.py:37
|
|
|
|
#: test_gettext.py:51 test_gettext.py:80 test_gettext.py:86 test_gettext.py:92
|
|
|
|
#: test_gettext.py:98
|
|
|
|
msgid "nudge nudge"
|
|
|
|
msgstr "wink wink"
|
|
|
|
|
2018-11-07 10:12:20 -04:00
|
|
|
msgctxt "my context"
|
|
|
|
msgid "nudge nudge"
|
|
|
|
msgstr "wink wink (in \"my context\")"
|
|
|
|
|
|
|
|
msgctxt "my other context"
|
|
|
|
msgid "nudge nudge"
|
|
|
|
msgstr "wink wink (in \"my other context\")"
|
|
|
|
|
2000-08-30 00:32:07 -03:00
|
|
|
#: test_gettext.py:16 test_gettext.py:22 test_gettext.py:28 test_gettext.py:34
|
|
|
|
#: test_gettext.py:77 test_gettext.py:83 test_gettext.py:89 test_gettext.py:95
|
|
|
|
msgid "albatross"
|
|
|
|
msgstr ""
|
|
|
|
|
|
|
|
#: test_gettext.py:18 test_gettext.py:24 test_gettext.py:30 test_gettext.py:36
|
|
|
|
#: test_gettext.py:79 test_gettext.py:85 test_gettext.py:91 test_gettext.py:97
|
|
|
|
msgid "Raymond Luxury Yach-t"
|
|
|
|
msgstr "Throatwobbler Mangrove"
|
|
|
|
|
|
|
|
#: test_gettext.py:17 test_gettext.py:23 test_gettext.py:29 test_gettext.py:35
|
|
|
|
#: test_gettext.py:56 test_gettext.py:78 test_gettext.py:84 test_gettext.py:90
|
|
|
|
#: test_gettext.py:96
|
|
|
|
msgid "mullusk"
|
|
|
|
msgstr "bacon"
|
|
|
|
|
|
|
|
#: test_gettext.py:40 test_gettext.py:101
|
|
|
|
msgid ""
|
|
|
|
"This module provides internationalization and localization\n"
|
|
|
|
"support for your Python programs by providing an interface to the GNU\n"
|
|
|
|
"gettext message catalog library."
|
|
|
|
msgstr ""
|
|
|
|
"Guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba\n"
|
|
|
|
"fhccbeg sbe lbhe Clguba cebtenzf ol cebivqvat na vagresnpr gb gur TAH\n"
|
|
|
|
"trggrkg zrffntr pngnybt yvoenel."
|
2002-11-21 17:45:32 -04:00
|
|
|
|
|
|
|
# Manually added, as neither pygettext nor xgettext support plural forms
|
|
|
|
# in Python.
|
|
|
|
msgid "There is %s file"
|
|
|
|
msgid_plural "There are %s files"
|
|
|
|
msgstr[0] "Hay %s fichero"
|
|
|
|
msgstr[1] "Hay %s ficheros"
|
2018-11-07 10:12:20 -04:00
|
|
|
|
|
|
|
# Manually added, as neither pygettext nor xgettext support plural forms
|
|
|
|
# and context in Python.
|
|
|
|
msgctxt "With context"
|
|
|
|
msgid "There is %s file"
|
|
|
|
msgid_plural "There are %s files"
|
|
|
|
msgstr[0] "Hay %s fichero (context)"
|
|
|
|
msgstr[1] "Hay %s ficheros (context)"
|
2000-08-30 00:32:07 -03:00
|
|
|
'''
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
|
|
|
|
# Here's the second example po file example, used to generate the UMO_DATA
|
|
|
|
# containing utf-8 encoded Unicode strings
|
|
|
|
|
2017-06-20 11:13:29 -03:00
|
|
|
b'''
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
# Dummy translation for the Python test_gettext.py module.
|
|
|
|
# Copyright (C) 2001 Python Software Foundation
|
|
|
|
# Barry Warsaw <barry@python.org>, 2000.
|
|
|
|
#
|
|
|
|
msgid ""
|
|
|
|
msgstr ""
|
|
|
|
"Project-Id-Version: 2.0\n"
|
|
|
|
"PO-Revision-Date: 2003-04-11 12:42-0400\n"
|
|
|
|
"Last-Translator: Barry A. WArsaw <barry@python.org>\n"
|
|
|
|
"Language-Team: XX <python-dev@python.org>\n"
|
|
|
|
"MIME-Version: 1.0\n"
|
|
|
|
"Content-Type: text/plain; charset=utf-8\n"
|
|
|
|
"Content-Transfer-Encoding: 7bit\n"
|
|
|
|
"Generated-By: manually\n"
|
|
|
|
|
|
|
|
#: nofile:0
|
|
|
|
msgid "ab\xc3\x9e"
|
|
|
|
msgstr "\xc2\xa4yz"
|
2018-11-07 10:12:20 -04:00
|
|
|
|
|
|
|
#: nofile:1
|
|
|
|
msgctxt "mycontext\xc3\x9e"
|
|
|
|
msgid "ab\xc3\x9e"
|
|
|
|
msgstr "\xc2\xa4yz (context version)"
|
From http://mail.python.org/pipermail/i18n-sig/2003-April/001557.html
- Expose NullTranslations and GNUTranslations to __all__
- Set the default charset to iso-8859-1. It used to be None, which
would cause problems with .ugettext() if the file had no charset
parameter. Arguably, the po/mo file would be broken, but I still think
iso-8859-1 is a reasonable default.
- Add a "coerce" default argument to GNUTranslations's constructor. The
reason for this is that in Zope, we want all msgids and msgstrs to be
Unicode. For the latter, we could use .ugettext() but there isn't
currently a mechanism for Unicode-ifying msgids.
The plan then is that the charset parameter specifies the encoding for
both the msgids and msgstrs, and both are decoded to Unicode when read.
For example, we might encode po files with utf-8. I think the GNU
gettext tools don't care.
Since this could potentially break code [*] that wants to use the
encoded interface .gettext(), the constructor flag is added, defaulting
to False. Most code I suspect will want to set this to True and use
.ugettext().
- A few other minor changes from the Zope project, including asserting
that a zero-length msgid must have a Project-ID-Version header for it to
be counted as the metadata record.
2003-04-11 15:36:43 -03:00
|
|
|
'''
|
2003-05-20 14:28:54 -03:00
|
|
|
|
|
|
|
# Here's the third example po file, used to generate MMO_DATA
|
|
|
|
|
2017-06-20 11:13:29 -03:00
|
|
|
b'''
|
2003-05-20 14:28:54 -03:00
|
|
|
msgid ""
|
|
|
|
msgstr ""
|
|
|
|
"Project-Id-Version: No Project 0.0\n"
|
|
|
|
"POT-Creation-Date: Wed Dec 11 07:44:15 2002\n"
|
|
|
|
"PO-Revision-Date: 2002-08-14 01:18:58+00:00\n"
|
|
|
|
"Last-Translator: John Doe <jdoe@example.com>\n"
|
|
|
|
"Jane Foobar <jfoobar@example.com>\n"
|
|
|
|
"Language-Team: xx <xx@example.com>\n"
|
|
|
|
"MIME-Version: 1.0\n"
|
|
|
|
"Content-Type: text/plain; charset=iso-8859-15\n"
|
|
|
|
"Content-Transfer-Encoding: quoted-printable\n"
|
|
|
|
"Generated-By: pygettext.py 1.3\n"
|
|
|
|
'''
|
2015-04-13 11:38:56 -03:00
|
|
|
|
|
|
|
#
|
|
|
|
# messages.po, used for bug 17898
|
|
|
|
#
|
|
|
|
|
2017-06-20 11:13:29 -03:00
|
|
|
b'''
|
2015-04-13 11:38:56 -03:00
|
|
|
# test file for http://bugs.python.org/issue17898
|
|
|
|
msgid ""
|
|
|
|
msgstr ""
|
|
|
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
|
|
|
"#-#-#-#-# messages.po (EdX Studio) #-#-#-#-#\n"
|
|
|
|
"Content-Type: text/plain; charset=UTF-8\n"
|
|
|
|
'''
|