diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2021-12-15 17:48:51 +0000 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2021-12-15 18:35:50 +0000 |
commit | 58cc278145eec62e55a8a9430ed3664586cf2da2 (patch) | |
tree | 4056feec30a021baadf308b44a5e131b9dcdd972 | |
parent | a03e649da6b243986d7ca4ae467be6f17558d97a (diff) | |
download | deluge-58cc278145eec62e55a8a9430ed3664586cf2da2.tar.gz deluge-58cc278145eec62e55a8a9430ed3664586cf2da2.tar.bz2 deluge-58cc278145eec62e55a8a9430ed3664586cf2da2.zip |
[i18n] Fix set_language error with empty lang string
The Web server config for language was set to an empty string which
resulted in an warning logged by i18n set_language.
* Changed set_language to ignore empty language string and do nothing.
We don't want to override the user's system language unless actually
specified by the user.
* Improved the translation warning message.
-rw-r--r-- | deluge/i18n/util.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/deluge/i18n/util.py b/deluge/i18n/util.py index 81530c2ee..6ed4b97da 100644 --- a/deluge/i18n/util.py +++ b/deluge/i18n/util.py @@ -69,18 +69,21 @@ def set_language(lang): :param lang: the language, e.g. "en", "de" or "en_GB" :type lang: str """ + if not lang: + return + # Necessary to set these environment variables for GtkBuilder deluge.common.set_env_variable('LANGUAGE', lang) # Windows/Linux deluge.common.set_env_variable('LANG', lang) # For OSX - translations_path = get_translations_path() try: - ro = gettext.translation( - 'deluge', localedir=translations_path, languages=[lang] + translation = gettext.translation( + 'deluge', localedir=get_translations_path(), languages=[lang] ) - ro.install() - except IOError as ex: - log.warning('IOError when loading translations: %s', ex) + except IOError: + log.warning('Unable to find translation (.mo) to set language: %s', lang) + else: + translation.install() def setup_mock_translation(warn_msg=None): |