Handle unknown locale exception
authorThierry Florac <thierry.florac@onf.fr>
Fri, 22 Feb 2019 12:31:28 +0100
changeset 331 15b593eddfcb
parent 330 b20fc80aa6be
child 332 71606c1dff73
Handle unknown locale exception
src/pyams_utils/size.py
--- a/src/pyams_utils/size.py	Fri Feb 22 12:31:08 2019 +0100
+++ b/src/pyams_utils/size.py	Fri Feb 22 12:31:28 2019 +0100
@@ -12,14 +12,10 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
-
-# import packages
+from babel import UnknownLocaleError
 from babel.core import Locale
 from babel.numbers import format_decimal
+
 from pyams_utils.request import check_request
 
 from pyams_utils import _
@@ -56,7 +52,10 @@
     if request is None:
         request = check_request()
     translate = request.localizer.translate
-    locale = Locale(request.locale_name)
+    try:
+        locale = Locale(request.locale_name)
+    except UnknownLocaleError:
+        locale = Locale(request.registry.settings.get('pyramid.default_locale_name', 'en'))
     if value < 1024:
         return format_decimal(value, translate(_('0 bytes')), locale)
     value /= 1024