本文整理汇总了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()