本文整理匯總了Python中locale.windows_locale方法的典型用法代碼示例。如果您正苦於以下問題:Python locale.windows_locale方法的具體用法?Python locale.windows_locale怎麽用?Python locale.windows_locale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類locale
的用法示例。
在下文中一共展示了locale.windows_locale方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_user_locale
# 需要導入模塊: import locale [as 別名]
# 或者: from locale import windows_locale [as 別名]
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
示例2: check_svchost_owner
# 需要導入模塊: import locale [as 別名]
# 或者: from locale import windows_locale [as 別名]
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"))
示例3: GetClosestLanguage
# 需要導入模塊: import locale [as 別名]
# 或者: from locale import windows_locale [as 別名]
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"
示例4: detect_language
# 需要導入模塊: import locale [as 別名]
# 或者: from locale import windows_locale [as 別名]
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()