Locale: Fix shadowed variables.

This commit is contained in:
John Ralls 2023-07-11 15:25:36 -07:00 committed by Nick Hall
parent 4bd5523e1b
commit e3a2797a33
2 changed files with 41 additions and 41 deletions

View File

@ -126,29 +126,29 @@ _RTL_LOCALES = ('ar', 'he')
# locales with less than 70% currently translated # locales with less than 70% currently translated
INCOMPLETE_TRANSLATIONS = ('ar', 'bg', 'sq', 'ta', 'tr', 'zh_HK', 'zh_TW') INCOMPLETE_TRANSLATIONS = ('ar', 'bg', 'sq', 'ta', 'tr', 'zh_HK', 'zh_TW')
def _check_mswin_locale(locale): def _check_mswin_locale(loc):
msloc = None msloc = None
try: try:
msloc = _LOCALE_NAMES[locale[:5]][:2] msloc = _LOCALE_NAMES[loc[:5]][:2]
locale = locale[:5] loc = loc[:5]
except KeyError: except KeyError:
try: try:
msloc = _LOCALE_NAMES[locale[:2]][:2] msloc = _LOCALE_NAMES[loc[:2]][:2]
locale = locale[:2] loc = loc[:2]
except KeyError: except KeyError:
#US English is the outlier, all other English locales want #US English is the outlier, all other English locales want
#real English: #real English:
if locale[:2] == ('en') and locale[:5] != 'en_US': if loc[:2] == ('en') and loc[:5] != 'en_US':
return ('en_GB', '1252') return ('en_GB', '1252')
return (None, None) return (None, None)
return (locale, msloc) return (loc, msloc)
def _check_mswin_locale_reverse(locale): def _check_mswin_locale_reverse(loc):
for (loc, msloc) in _LOCALE_NAMES.items(): for (loc, msloc) in _LOCALE_NAMES.items():
if msloc and locale == msloc[0]: if msloc and loc == msloc[0]:
return (loc, msloc[1]) return (loc, msloc[1])
#US English is the outlier, all other English locales want real English: #US English is the outlier, all other English locales want real English:
if locale.startswith('English') and locale != 'English_United States': if loc.startswith('English') and loc != 'English_United States':
return ('en_GB', '1252') return ('en_GB', '1252')
return (None, None) return (None, None)
@ -338,17 +338,17 @@ class GrampsLocale:
def _init_from_environment(self): def _init_from_environment(self):
def _check_locale(locale): def _check_locale(loc):
if not locale[0]: if not loc[0]:
return False return False
lang = self.check_available_translations(locale[0]) lang = self.check_available_translations(loc[0])
if not lang and locale[0].startswith('en'): if not lang and loc[0].startswith('en'):
locale = ('en_GB', 'UTF-8') loc = ('en_GB', 'UTF-8')
lang = 'en_GB' lang = 'en_GB'
if not lang: if not lang:
return False return False
self.lang = locale[0] self.lang = loc[0]
self.encoding = locale[1] self.encoding = loc[1]
self.language = [lang] self.language = [lang]
return True return True
@ -365,9 +365,9 @@ class GrampsLocale:
self.language = ['en'] self.language = ['en']
_failure = True _failure = True
except locale.Error as err: except locale.Error as loc_err:
LOG.debug("Locale error %s, localization settings ignored.", LOG.debug("Locale error %s, localization settings ignored.",
err) loc_err)
self.lang = 'C' self.lang = 'C'
self.encoding = 'ascii' self.encoding = 'ascii'
self.language = ['en'] self.language = ['en']
@ -626,8 +626,8 @@ class GrampsLocale:
try: try:
collation = self.icu_locales["collation"] collation = self.icu_locales["collation"]
self.collator = Collator.createInstance(collation) self.collator = Collator.createInstance(collation)
except ICUError as err: except ICUError as icu_err:
LOG.warning("Unable to create collator: %s", str(err)) LOG.warning("Unable to create collator: %s", str(icu_err))
self.collator = None self.collator = None
try: try:
@ -860,7 +860,7 @@ class GrampsLocale:
return languages return languages
def check_available_translations(self, locale): def check_available_translations(self, loc):
""" """
Test a locale for having a translation available Test a locale for having a translation available
locale -- string with standard language code, locale code, or name locale -- string with standard language code, locale code, or name
@ -873,16 +873,16 @@ class GrampsLocale:
if not hasattr(self, 'languages'): if not hasattr(self, 'languages'):
self.languages = self.get_available_translations() self.languages = self.get_available_translations()
if not locale: if not loc:
return None return None
if locale[:5] in self.languages: if loc[:5] in self.languages:
return locale[:5] return loc[:5]
#US English is the outlier, all other English locales want real English: #US English is the outlier, all other English locales want real English:
if locale[:2] == 'en' and locale[:5] != 'en_US': if loc[:2] == 'en' and loc[:5] != 'en_US':
return 'en_GB' return 'en_GB'
if locale[:2] in self.languages: if loc[:2] in self.languages:
return locale[:2] return loc[:2]
return None return None
def get_language_dict(self): def get_language_dict(self):
@ -939,9 +939,9 @@ class GrampsLocale:
string = string.decode("utf-8", "replace") string = string.decode("utf-8", "replace")
try: try:
key = locale.strxfrm(string) key = locale.strxfrm(string)
except Exception as err: except Exception as icu_err:
LOG.warning("Failed to obtain key for %s because %s", LOG.warning("Failed to obtain key for %s because %s",
self.collation, str(err)) self.collation, str(icu_err))
return string return string
return key return key

View File

@ -149,11 +149,11 @@ def mac_setup_localization(glocale):
return None return None
def _mac_check_locale(locale_string): def _mac_check_locale(locale_string):
locale = None loc = None
calendar = None calendar = None
div = locale_string.strip().split("@") div = locale_string.strip().split("@")
LOG.debug("Checking Locale %s", ' '.join(div)) LOG.debug("Checking Locale %s", ' '.join(div))
locale = glocale.check_available_translations(div[0]) loc = glocale.check_available_translations(div[0])
if len(div) > 1: if len(div) > 1:
div = div[1].split(";") div = div[1].split(";")
for phrase in div: for phrase in div:
@ -161,7 +161,7 @@ def mac_setup_localization(glocale):
if name == "calendar": if name == "calendar":
calendar = glocale.check_available_translations(value) calendar = glocale.check_available_translations(value)
return (locale, calendar) return (loc, calendar)
def _mac_get_locale(): def _mac_get_locale():
""" """
@ -171,19 +171,19 @@ def mac_setup_localization(glocale):
#with [0] being the decimal separator and [1] the thousands #with [0] being the decimal separator and [1] the thousands
#separator. This obviously won't translate into a locale without #separator. This obviously won't translate into a locale without
#searching the locales database for a match. #searching the locales database for a match.
locale = _mac_get_gramps_defaults("Gramps", "AppleLocale") loc = _mac_get_gramps_defaults("Gramps", "AppleLocale")
if locale: if loc:
locale_values = _mac_check_locale(locale) locale_values = _mac_check_locale(loc)
if locale_values[0]: if locale_values[0]:
return locale_values return locale_values
LOG.debug("Gramps defaults locale %s isn't supported", locale) LOG.debug("Gramps defaults locale %s isn't supported", loc)
locale = _mac_get_gramps_defaults("Global", "AppleLocale") loc = _mac_get_gramps_defaults("Global", "AppleLocale")
if locale: if loc:
locale_values = _mac_check_locale(locale) locale_values = _mac_check_locale(loc)
if locale_values[0]: if locale_values[0]:
return locale_values return locale_values
LOG.debug("Global defaults locale %s isn't supported", locale) LOG.debug("Global defaults locale %s isn't supported", loc)
return (None, None, None) return (None, None, None)