diff --git a/apprise/AppriseLocale.py b/apprise/AppriseLocale.py index 345c2067ee..b3b0fab2fa 100644 --- a/apprise/AppriseLocale.py +++ b/apprise/AppriseLocale.py @@ -203,6 +203,17 @@ def detect_language(lang=None, detect_fallback=True): # no detection enabled; we're done return None + # Posix lookup + lookup = os.environ.get + localename = None + for variable in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'): + localename = lookup(variable, None) + if localename: + result = AppriseLocale._local_re.match(localename) + if result and result.group('lang'): + return result.group('lang').lower() + + # Windows handling if hasattr(ctypes, 'windll'): windll = ctypes.windll.kernel32 try: @@ -216,16 +227,7 @@ def detect_language(lang=None, detect_fallback=True): # Fallback to posix detection pass - # Posix lookup - lookup = os.environ.get - localename = None - for variable in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'): - localename = lookup(variable, None) - if localename: - result = AppriseLocale._local_re.match(localename) - if result and result.group('lang'): - return result.group('lang').lower() - + # Linux Handling try: # Acquire our locale lang = locale.getlocale()[0] diff --git a/test/test_locale.py b/test/test_locale.py index f2436620a4..a16f178505 100644 --- a/test/test_locale.py +++ b/test/test_locale.py @@ -144,6 +144,7 @@ def test_detect_language_windows_users(): if hasattr(ctypes, 'windll'): from ctypes import windll + else: windll = mock.Mock() # 4105 = en_CA @@ -166,8 +167,7 @@ def test_detect_language_windows_users(): def test_detect_language_using_env(): """ - When enabling CI testing on Windows, those tests did not produce the - correct results. They may want to be reviewed. + Test the reading of information from an environment variable """ # The below accesses the windows fallback code and fail @@ -203,7 +203,12 @@ def test_detect_language_locale(mock_getlocale): """ # Handle case where getlocale() can't be detected mock_getlocale.return_value = None - assert AppriseLocale.AppriseLocale.detect_language() is None + with environ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'): + assert AppriseLocale.AppriseLocale.detect_language() is None + + mock_getlocale.return_value = (None, None) + with environ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'): + assert AppriseLocale.AppriseLocale.detect_language() is None # if detect_language and windows env fail us, then we don't # set up a default language on first load