--- a/src/pyams_utils/i18n.py Thu Sep 27 14:37:47 2018 +0200
+++ b/src/pyams_utils/i18n.py Tue Oct 02 09:57:17 2018 +0200
@@ -12,12 +12,7 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
-
-# import interfaces
-
-# import packages
+import locale
def normalize_lang(lang):
@@ -74,3 +69,11 @@
accepts.reverse()
return [lang for qual, lang in accepts][0] if accepts else None
+
+
+def set_locales(config):
+ """Define locale environment variables"""
+ for attr in ('LC_CTYPE', 'LC_COLLATE', 'LC_TIME', 'LC_MONETARY', 'LC_NUMERIC', 'LC_ALL'):
+ value = config.get('pyams.{0}'.format(attr.lower()))
+ if value is not None:
+ locale.setlocale(getattr(locale, attr), value)
--- a/src/pyams_utils/include.py Thu Sep 27 14:37:47 2018 +0200
+++ b/src/pyams_utils/include.py Tue Oct 02 09:57:17 2018 +0200
@@ -12,25 +12,21 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
-
-# import interfaces
+from chameleon import PageTemplateFile
from persistent.interfaces import IPersistent
-from zope.annotation.interfaces import IAttributeAnnotatable, IAnnotations
+from z3c.pt.pagetemplate import PageTemplateFile as Z3cPageTemplateFile
+from zope.annotation.attribute import AttributeAnnotations
+from zope.annotation.interfaces import IAnnotations, IAttributeAnnotatable
from zope.keyreference.interfaces import IKeyReference
+from zope.keyreference.persistent import KeyReferenceToPersistent
-# import packages
-from chameleon import PageTemplateFile
from pyams_utils.container import ParentSelector
from pyams_utils.context import ContextSelector
-from pyams_utils.request import get_annotations, get_debug, RequestSelector
+from pyams_utils.i18n import set_locales
+from pyams_utils.request import RequestSelector, get_annotations, get_debug
from pyams_utils.site import site_factory
from pyams_utils.tales import ExtensionExpr
from pyams_utils.traversing import NamespaceTraverser
-from z3c.pt.pagetemplate import PageTemplateFile as Z3cPageTemplateFile
-from zope.annotation.attribute import AttributeAnnotations
-from zope.keyreference.persistent import KeyReferenceToPersistent
def include_package(config):
@@ -39,6 +35,9 @@
# add translations
config.add_translation_dirs('pyams_utils:locales')
+ # define locale
+ set_locales(config.registry.settings)
+
# define root factory
config.set_root_factory(site_factory)