diff options
author | Micah Lee <micah@micahflee.com> | 2018-12-18 18:53:40 -0800 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2018-12-18 18:53:40 -0800 |
commit | e6f26f65459489de6c59dda8bc8e4abc213ba762 (patch) | |
tree | f9ba7f553b67955982e81ff8253ff8a9850a9c7e | |
parent | ce2efec61091d714127b9d07a003beb819090545 (diff) | |
download | onionshare-e6f26f65459489de6c59dda8bc8e4abc213ba762.tar.gz onionshare-e6f26f65459489de6c59dda8bc8e4abc213ba762.zip |
When discovering default locale, default to english if locale.getdefaultlocale() returns None. Also, make locales that include country codes (pt_PT and pt_BR) actually work as default locales
-rw-r--r-- | onionshare/settings.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/onionshare/settings.py b/onionshare/settings.py index fc68ffc9..91844c8d 100644 --- a/onionshare/settings.py +++ b/onionshare/settings.py @@ -111,7 +111,19 @@ class Settings(object): # Choose the default locale based on the OS preference, and fall-back to English if self._settings['locale'] is None: - default_locale = locale.getdefaultlocale()[0][:2] + language_code, encoding = locale.getdefaultlocale() + + # Default to English + if not language_code: + language_code = 'en_US' + + if language_code == 'pt_PT' and language_code == 'pt_BR': + # Portuguese locales include country code + default_locale = language_code + else: + # All other locales cut off the country code + default_locale = language_code[:2] + if default_locale not in self.available_locales: default_locale = 'en' self._settings['locale'] = default_locale |