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) -> 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 get_country_code(): try: if platform == 'linux': l = locale.getdefaultlocale()[0] if l is not None: return l.split(LOCALE_SPLITCHAR, 1)[1][:2].upper() elif platform == 'mac': from Foundation import NSAutoreleasePool, NSLocale, NSLocaleCountryCode pool = NSAutoreleasePool.alloc().init() try: return NSLocale.currentLocale().objectForKey_(NSLocaleCountryCode).upper() finally: del pool else: from dropbox.win32.version import WIN2K, WINDOWS_VERSION if WINDOWS_VERSION != WIN2K: GEO_ISO2 = 4 nation = ctypes.windll.kernel32.GetUserGeoID(16) buf = ctypes.create_string_buffer(20) if ctypes.windll.kernel32.GetGeoInfoA(nation, GEO_ISO2, ctypes.byref(buf), ctypes.sizeof(buf), 0): return buf.value.upper() except Exception: unhandled_exc_handler() return 'US'
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)