def current_locale(self) -> str: """ Detect the OS default language. """ # Guess the encoding if MAC: # Always UTF-8 on macOS encoding = "UTF-8" else: encoding = locale.getdefaultlocale()[1] or "" # Guess the current locale name if WINDOWS: import ctypes l10n_code = ( ctypes.windll.kernel32.GetUserDefaultUILanguage( ) # type: ignore ) l10n = locale.windows_locale[l10n_code] elif MAC: from Foundation import NSLocale l10n_code = NSLocale.currentLocale() l10n = NSLocale.localeIdentifier(l10n_code) else: l10n = locale.getdefaultlocale()[0] or "" return ".".join([l10n, encoding])
def selectLanguage(macOSVersion): if macOSVersion > 10.11: locale = NSLocale.currentLocale() languageCode = NSLocale.languageCode(locale) id = languageCode countryCode = NSLocale.countryCode(locale) localeIdentifier = NSLocale.localeIdentifier(locale) else: cmd = ["defaults", 'read', '.GlobalPreferences', 'AppleLocale'] proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, err = proc.communicate() if proc.returncode: id = "en" localeIdentifier = "en_US" languageCode = id else: localeIdentifier = output id = languageCode = output.split('_')[0] # # Special cases for Apple's SU. # if languageCode == "pt" and localeIdentifier == "pt_PT": id = localeIdentifier elif languageCode == "es" and localeIdentifier == "es_419": id = localeIdentifier elif languageCode == "zh": if localeIdentifier == "zh_TW": id = localeIdentifier else: id = "zh_CN" return getICUName(id)
def current_locale(self): """ Detect the OS default language. """ encoding = locale.getdefaultlocale()[1] if AbstractOSIntegration.is_windows(): l10n_code = ctypes.windll.kernel32.GetUserDefaultUILanguage() l10n = locale.windows_locale[l10n_code] elif AbstractOSIntegration.is_mac(): l10n_code = NSLocale.currentLocale() l10n = NSLocale.localeIdentifier(l10n_code) encoding = 'UTF-8' else: l10n = locale.getdefaultlocale()[0] return '.'.join([l10n, encoding])
def current_locale(self) -> str: """ Detect the OS default language. """ encoding = locale.getdefaultlocale()[1] if WINDOWS: l10n_code = ctypes.windll.kernel32.GetUserDefaultUILanguage() l10n = locale.windows_locale[l10n_code] elif MAC: l10n_code = NSLocale.currentLocale() l10n = NSLocale.localeIdentifier(l10n_code) encoding = "UTF-8" else: l10n = locale.getdefaultlocale()[0] return ".".join([l10n, encoding])
def current_locale(self) -> str: """ Detect the OS default language. """ encoding = locale.getdefaultlocale()[1] or "" if WINDOWS: l10n_code = ( ctypes.windll.kernel32.GetUserDefaultUILanguage() # type: ignore ) l10n = locale.windows_locale[l10n_code] elif MAC: l10n_code = NSLocale.currentLocale() l10n = NSLocale.localeIdentifier(l10n_code) encoding = "UTF-8" else: l10n = locale.getdefaultlocale()[0] or "" return ".".join([l10n, encoding])
def selectLanguage(): locale = NSLocale.currentLocale() languageCode = NSLocale.languageCode(locale) id = languageCode countryCode = NSLocale.countryCode(locale) localeIdentifier = NSLocale.localeIdentifier(locale) # # Special cases for Apple SU. # if languageCode == "pt" and localeIdentifier == "pt_PT": id = localeIdentifier elif languageCode == "es" and localeIdentifier == "es_419": id = localeIdentifier elif languageCode == "zh": if localeIdentifier == "zh_TW": id = localeIdentifier else: id = "zh_CN" return getICUName(id)