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 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)