Python locale.windows_locale() Examples
The following are 5
code examples of locale.windows_locale().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
locale
, or try the search function
.
Example #1
Source File: __init__.py From mlconjug with MIT License | 6 votes |
def _get_user_locale(): """ | Gets the user locale to set the user interface language language. | The default is set to english if the user's system locale is not one of the translated languages. :return: string. The user locale. """ if 'Windows' in platform.system(): import ctypes windll = ctypes.windll.kernel32 default_locale = windows_locale[windll.GetUserDefaultUILanguage()] else: default_locale = getdefaultlocale() if default_locale: if isinstance(default_locale, tuple): user_locale = [0][:2] else: user_locale = default_locale[:2] else: user_locale = 'en' return user_locale
Example #2
Source File: loki.py From Loki with GNU General Public License v3.0 | 6 votes |
def check_svchost_owner(self, owner): ## Locale setting import ctypes import locale windll = ctypes.windll.kernel32 locale = locale.windows_locale[ windll.GetUserDefaultUILanguage() ] if locale == 'fr_FR': return (owner.upper().startswith("SERVICE LOCAL") or owner.upper().startswith(u"SERVICE RÉSEAU") or re.match(r"SERVICE R.SEAU", owner) or owner == u"Système" or owner.upper().startswith(u"AUTORITE NT\Système") or re.match(r"AUTORITE NT\\Syst.me", owner)) elif locale == 'ru_RU': return (owner.upper().startswith("NET") or owner == u"система" or owner.upper().startswith("LO")) else: return ( owner.upper().startswith("NT ") or owner.upper().startswith("NET") or owner.upper().startswith("LO") or owner.upper().startswith("SYSTEM"))
Example #3
Source File: Utils.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def GetClosestLanguage(): """ Returns the language file closest to system locale. """ langDir = join(dirname(abspath(sys.executable)), "languages") if exists(langDir): uiLang = windows_locale[windll.kernel32.GetUserDefaultUILanguage()] langFiles = tuple( f[:-3] for f in os.listdir(langDir) if f.endswith(".py") and ( f.startswith(uiLang) or f.startswith(uiLang[:3]) ) ) if uiLang in langFiles: return uiLang if langFiles: return langFiles[0] return "en_US"
Example #4
Source File: AppriseLocale.py From apprise with MIT License | 4 votes |
def detect_language(lang=None, detect_fallback=True): """ returns the language (if it's retrievable) """ # We want to only use the 2 character version of this language # hence en_CA becomes en, en_US becomes en. if not isinstance(lang, six.string_types): if detect_fallback is False: # no detection enabled; we're done return None if hasattr(ctypes, 'windll'): windll = ctypes.windll.kernel32 try: lang = locale.windows_locale[ windll.GetUserDefaultUILanguage()] # Our detected windows language return lang[0:2].lower() except (TypeError, KeyError): # Fallback to posix detection pass try: # Detect language lang = locale.getdefaultlocale()[0] except ValueError as e: # This occurs when an invalid locale was parsed from the # environment variable. While we still return None in this # case, we want to better notify the end user of this. Users # receiving this error should check their environment # variables. logger.warning( 'Language detection failure / {}'.format(str(e))) return None except TypeError: # None is returned if the default can't be determined # we're done in this case return None return None if not lang else lang[0:2].lower()
Example #5
Source File: AppriseLocale.py From bazarr with GNU General Public License v3.0 | 4 votes |
def detect_language(lang=None, detect_fallback=True): """ returns the language (if it's retrievable) """ # We want to only use the 2 character version of this language # hence en_CA becomes en, en_US becomes en. if not isinstance(lang, six.string_types): if detect_fallback is False: # no detection enabled; we're done return None if hasattr(ctypes, 'windll'): windll = ctypes.windll.kernel32 try: lang = locale.windows_locale[ windll.GetUserDefaultUILanguage()] # Our detected windows language return lang[0:2].lower() except (TypeError, KeyError): # Fallback to posix detection pass try: # Detect language lang = locale.getdefaultlocale()[0] except ValueError as e: # This occurs when an invalid locale was parsed from the # environment variable. While we still return None in this # case, we want to better notify the end user of this. Users # receiving this error should check their environment # variables. logger.warning( 'Language detection failure / {}'.format(str(e))) return None except TypeError: # None is returned if the default can't be determined # we're done in this case return None return None if not lang else lang[0:2].lower()