Extract locale name from system registry if it can't be extracted from current request
authorThierry Florac <thierry.florac@onf.fr>
Thu, 28 Apr 2016 14:34:31 +0200
changeset 23 75ffaadf42a6
parent 22 2361ecac5731
child 24 a376782c4077
Extract locale name from system registry if it can't be extracted from current request
src/pyams_i18n/negotiator.py
--- a/src/pyams_i18n/negotiator.py	Mon Jan 18 17:58:56 2016 +0100
+++ b/src/pyams_i18n/negotiator.py	Thu Apr 28 14:34:31 2016 +0200
@@ -23,6 +23,7 @@
 from pyams_utils.i18n import get_browser_language
 from pyams_utils.registry import query_utility, utility_config
 from persistent import Persistent
+from zope.component.globalregistry import getGlobalSiteManager
 from zope.container.contained import Contained
 from zope.i18n.locales import locales
 from zope.interface import implementer
@@ -89,6 +90,9 @@
         locale_name = negotiator.get_language(request)
     else:
         locale_name = get_browser_language(request)
+    if not locale_name:
+        registry = getGlobalSiteManager()
+        locale_name = registry.settings.get('pyramid.default_locale_name', 'en')
     if '-' in locale_name:
         # remove 'sub-locale' to prevent Babel and Zope exceptions for unknown locales
         locale_name = locale_name.split('-')[0]