Fix i18n: message catalogs were reset on each initialization

This commit is contained in:
Takeshi KOMIYA committed 2018-02-25 23:44:38 +09:00
1 parent b3e7609a80
commit bc31485b10
3 files changed
+5 -4

No files matched your search

+2
View File
@@ -47,6 +47,8 @@ Features added
Bugs fixed
----------
* i18n: message catalogs were reset on each initialization
Testing
--------
+1 -1
View File
@@ -214,7 +214,7 @@ def init(locale_dirs, language, catalog='sphinx', namespace='general'):
global translators
translator = translators.get((namespace, catalog))
# ignore previously failed attempts to find message catalogs
if isinstance(translator, NullTranslations):
if translator.__class__ is NullTranslations:
translator = None
# the None entry is the system's default locale path
has_translation = True
+2 -3
View File
@@ -41,9 +41,8 @@ def test_init(rootdir):
assert _('Hello sphinx') == 'Hello sphinx' # nothing changed here
assert _('Hello reST') == 'Hello reST'
# load both locale1 and locale2
locale.init([rootdir / 'test-locale' / 'locale1',
rootdir / 'test-locale' / 'locale2'], 'en', 'myext')
# load locale2 in addition
locale.init([rootdir / 'test-locale' / 'locale2'], 'en', 'myext')
_ = locale.get_translation('myext')
assert _('Hello world') == 'HELLO WORLD'
assert _('Hello sphinx') == 'HELLO SPHINX'