diff options
-rw-r--r-- | docs/api.rst | 6 | ||||
-rw-r--r-- | src/zope/i18n/config.py | 34 | ||||
-rw-r--r-- | src/zope/i18n/tests/test.py | 10 |
3 files changed, 44 insertions, 6 deletions
diff --git a/docs/api.rst b/docs/api.rst index 706976e..b185cae 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -12,6 +12,12 @@ zope.i18n .. automodule:: zope.i18n +zope.i18n.config +================ + +.. automodule:: zope.i18n.config + + zope.i18n.compile ================= diff --git a/src/zope/i18n/config.py b/src/zope/i18n/config.py index 41e5ab1..cd38e64 100644 --- a/src/zope/i18n/config.py +++ b/src/zope/i18n/config.py @@ -1,11 +1,37 @@ import os +#: The environment variable that is consulted when this module +#: 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' +#: 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) +#: The environment variable that is consulted when this module +#: is imported to determine the value of `ALLOWED_LANGUAGES`. +#: If set, this should be a comma-separated list of language names. ALLOWED_LANGUAGES_KEY = 'zope_i18n_allowed_languages' -ALLOWED_LANGUAGES = os.environ.get(ALLOWED_LANGUAGES_KEY, None) -if ALLOWED_LANGUAGES is not None: - ALLOWED_LANGUAGES = ALLOWED_LANGUAGES.strip().replace(',', ' ') - ALLOWED_LANGUAGES = frozenset(ALLOWED_LANGUAGES.split()) + +def _parse_languages(value): + """ + Utility function to parse languages. + + >>> _parse_languages(None) is None + True + >>> _parse_languages("en") == frozenset(('en',)) + True + >>> _parse_languages("en,es") == frozenset(('en', 'es')) + True + """ + if value: + value = value.strip().replace(",", " ") + value = frozenset(value.split()) + return value + + +#: A set of languages that `zope.i18n.negotiate` will pass to the +#: `zope.i18n.interfaces.INegotiator` utility. If this is None, +#: no utility will be used. +ALLOWED_LANGUAGES = _parse_languages(os.environ.get(ALLOWED_LANGUAGES_KEY, None)) diff --git a/src/zope/i18n/tests/test.py b/src/zope/i18n/tests/test.py index 998bd6e..2e84b55 100644 --- a/src/zope/i18n/tests/test.py +++ b/src/zope/i18n/tests/test.py @@ -21,8 +21,14 @@ from zope.i18n.testing import unicode_checker def test_suite(): - return doctest.DocTestSuite("zope.i18n", setUp=setUp, tearDown=tearDown, - checker=unicode_checker) + return unittest.TestSuite([ + doctest.DocTestSuite( + "zope.i18n", setUp=setUp, tearDown=tearDown, + checker=unicode_checker), + doctest.DocTestSuite( + "zope.i18n.config", setUp=setUp, tearDown=tearDown, + checker=unicode_checker), + ]) if __name__ == '__main__': |