diff options
author | Tomás Touceda <chiiph@leap.se> | 2013-06-27 16:59:12 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2013-06-27 16:59:12 -0300 |
commit | 8f54afe3ce4ff98bdf52982c75e7691fc0203090 (patch) | |
tree | 25f0fbc3742384f046e90969392e1dba05a66d26 /src/leap/common | |
parent | fbd0a8d86232e0e6d717d8c3fc5ace88e167eb74 (diff) | |
parent | 3a4906638909729236b693fb21a4b1b7194344b5 (diff) |
Merge remote-tracking branch 'ivan/bug/fix_default_language_localization' into develop
Diffstat (limited to 'src/leap/common')
-rw-r--r-- | src/leap/common/config/baseconfig.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/leap/common/config/baseconfig.py b/src/leap/common/config/baseconfig.py index e6bd9c4..699d734 100644 --- a/src/leap/common/config/baseconfig.py +++ b/src/leap/common/config/baseconfig.py @@ -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): |