Bugfix: use the provider's default language as default string
authorIvan Alejandro <ivanalejandro0@yahoo.com.ar>
Thu, 27 Jun 2013 18:33:57 +0000 (15:33 -0300)
committerIvan Alejandro <ivanalejandro0@yahoo.com.ar>
Thu, 27 Jun 2013 19:08:33 +0000 (16:08 -0300)
Also take care (and note) a possible case with a problematic provider
misconfiguration.

changes/bug-3029_default-localization-language [new file with mode: 0644]
src/leap/common/config/baseconfig.py

diff --git a/changes/bug-3029_default-localization-language b/changes/bug-3029_default-localization-language
new file mode 100644 (file)
index 0000000..1fbb464
--- /dev/null
@@ -0,0 +1,2 @@
+  o Bugfix: use the provider's default language as default string. Also take care (and note) a possible case with a problematic provider
+misconfiguration. Closes #3029.
index e6bd9c4..699d734 100644 (file)
@@ -155,26 +155,39 @@ class LocalizedKey(object):
     def __init__(self, func, **kwargs):
         self._func = func
 
-    def __call__(self, instance, lang="en"):
+    def __call__(self, instance, lang=None):
         """
         Tries to return the string for the specified language, otherwise
-        informs the problem and returns an empty string.
+        returns the default language string.
 
         :param lang: language code
         :type lang: str
 
         :return: localized value from the possible values returned by
                  self._func
+                 It returns None in case that the provider does not provides
+                 a matching pair of default_language and string for
+                 that language.
+                 e.g.:
+                     'default_language': 'es',
+                     'description': {'en': 'test description'}
+                Note that the json schema can't check that.
         """
         descriptions = self._func(instance)
-        description_lang = ""
-        config_lang = "en"
+        config_lang = instance.get_default_language()
+        if lang is None:
+            lang = config_lang
+
         for key in descriptions.keys():
             if lang.startswith(key):
                 config_lang = key
                 break
 
-        description_lang = descriptions[config_lang]
+        description_lang = descriptions.get(config_lang)
+        if description_lang is None:
+            logger.error("There is a misconfiguration in the "
+                         "provider's language strings.")
+
         return description_lang
 
     def __get__(self, instance, instancetype):