summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens W. Klein <jk@kleinundpartner.at>2021-12-08 09:49:32 +0100
committerGitHub <noreply@github.com>2021-12-08 09:49:32 +0100
commit73d9d8779797f4ec88468246f45853ae8227f453 (patch)
treea1001909285fab31d8d805a09771822829b91296
parent825fea4b8b315b794670f2fc1cb5d8c68b92cdb4 (diff)
parentdac792b2a1449c4377468d1acc1126e15f9dceec (diff)
downloadzope-i18n-73d9d8779797f4ec88468246f45853ae8227f453.tar.gz
Merge pull request #52 from zopefoundation/fix-Zope-994-2
Fix problems with zope_i18n_compile_mo_files early assignment
-rw-r--r--CHANGES.rst4
-rw-r--r--src/zope/i18n/config.py3
-rw-r--r--src/zope/i18n/zcml.py9
3 files changed, 13 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 006cc24..525c51c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,7 +5,9 @@
4.8.1 (unreleased)
==================
-- Nothing changed yet.
+- Fix problems with ``zope_i18n_compile_mo_files`` early assignment to
+ module variable in ``config.py`` in a non-breaking way.
+ See also `Zope issue #994 <https://github.com/zopefoundation/Zope/issues/994>`_
4.8.0 (2021-09-07)
diff --git a/src/zope/i18n/config.py b/src/zope/i18n/config.py
index b0068c5..ce94ded 100644
--- a/src/zope/i18n/config.py
+++ b/src/zope/i18n/config.py
@@ -4,9 +4,10 @@ import os
#: is imported to determine the value of `COMPILE_MO_FILES`.
#: Simply set this to a non-empty string to make it True.
COMPILE_MO_FILES_KEY = 'zope_i18n_compile_mo_files'
+COMPILE_MO_FILES_UNSET = "__unset__"
#: Whether or not the ZCML directives will attempt to compile
#: translation files. Defaults to False.
-COMPILE_MO_FILES = os.environ.get(COMPILE_MO_FILES_KEY, False)
+COMPILE_MO_FILES = COMPILE_MO_FILES_UNSET
#: The environment variable that is consulted when this module
#: is imported to determine the value of `ALLOWED_LANGUAGES`.
diff --git a/src/zope/i18n/zcml.py b/src/zope/i18n/zcml.py
index 6934485..caeff9b 100644
--- a/src/zope/i18n/zcml.py
+++ b/src/zope/i18n/zcml.py
@@ -89,7 +89,14 @@ def registerTranslations(_context, directory, domain='*'):
lc_messages_path = os.path.join(path, language, 'LC_MESSAGES')
if os.path.isdir(lc_messages_path):
# Preprocess files and update or compile the mo files
- if config.COMPILE_MO_FILES:
+ setting_unset = (
+ config.COMPILE_MO_FILES == config.COMPILE_MO_FILES_UNSET
+ )
+ if (
+ (setting_unset
+ and os.environ.get(config.COMPILE_MO_FILES_KEY, False))
+ or (not setting_unset and config.COMPILE_MO_FILES)
+ ):
for domain_path in glob(os.path.join(lc_messages_path,
'%s.po' % domain)):
domain_file = os.path.basename(domain_path)