当前位置: 首页>>代码示例>>Python>>正文


Python locale.getdefaultlocale方法代码示例

本文整理汇总了Python中locale.getdefaultlocale方法的典型用法代码示例。如果您正苦于以下问题:Python locale.getdefaultlocale方法的具体用法?Python locale.getdefaultlocale怎么用?Python locale.getdefaultlocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在locale的用法示例。


在下文中一共展示了locale.getdefaultlocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: launch

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def launch(name, *args):
    """Executes a script designed specifically for this launcher.

       The parameter "name" is the name of the function to be tested
       which is passed as an argument to the script.
    """

    filename = os.path.join(os.path.dirname(__file__), '_launch_widget.py')
    command = ['python', filename, name]
    if args:
        command.extend(args)
    output = subprocess.check_output(command)

    try:
        output = output.decode(encoding='UTF-8')
    except:
        try:
            output = output.decode(encoding=locale.getdefaultlocale()[1])
        except:
            print("could not decode")
    return output 
开发者ID:aroberge,项目名称:easygui_qt,代码行数:23,代码来源:launcher.py

示例2: user_set_encoding_and_is_utf8

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def user_set_encoding_and_is_utf8():
    # Check user's encoding settings
    try:
        (lang, enc) = getdefaultlocale()
    except ValueError:
        print("Didn't detect your LC_ALL environment variable.")
        print("Please export LC_ALL with some UTF-8 encoding.")
        print("For example: `export LC_ALL=en_US.UTF-8`")
        return False
    else:
        if enc != "UTF-8":
            print("zdict only works with encoding=UTF-8, ")
            print("but your encoding is: {} {}".format(lang, enc))
            print("Please export LC_ALL with some UTF-8 encoding.")
            print("For example: `export LC_ALL=en_US.UTF-8`")
            return False
    return True 
开发者ID:zdict,项目名称:zdict,代码行数:19,代码来源:zdict.py

示例3: setencoding

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def setencoding():
    """Set the string encoding used by the Unicode implementation.  The
    default is 'ascii', but if you're willing to experiment, you can
    change this."""
    encoding = "ascii" # Default value set by _PyUnicode_Init()
    if 0:
        # Enable to support locale aware default string encodings.
        import locale
        loc = locale.getdefaultlocale()
        if loc[1]:
            encoding = loc[1]
    if 0:
        # Enable to switch off string to Unicode coercion and implicit
        # Unicode to string conversion.
        encoding = "undefined"
    if encoding != "ascii":
        # On Non-Unicode builds this will raise an AttributeError...
        sys.setdefaultencoding(encoding) # Needs Python Unicode build ! 
开发者ID:glmcdona,项目名称:meddle,代码行数:20,代码来源:site.py

示例4: test_option_locale

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def test_option_locale(self):
        self.assertFailure('-L')
        self.assertFailure('--locale')
        self.assertFailure('-L', 'en')
        lang, enc = locale.getdefaultlocale()
        lang = lang or 'C'
        enc = enc or 'UTF-8'
        try:
            oldlocale = locale.getlocale(locale.LC_TIME)
            try:
                locale.setlocale(locale.LC_TIME, (lang, enc))
            finally:
                locale.setlocale(locale.LC_TIME, oldlocale)
        except (locale.Error, ValueError):
            self.skipTest('cannot set the system default locale')
        stdout = self.run_ok('--locale', lang, '--encoding', enc, '2004')
        self.assertIn('2004'.encode(enc), stdout) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_calendar.py

示例5: _get_user_locale

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [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 
开发者ID:SekouD,项目名称:mlconjug,代码行数:25,代码来源:__init__.py

示例6: language_code

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def language_code(self, language_code):
        is_system_locale = language_code is None
        if language_code is None:
            try:
                language_code, _ = locale.getdefaultlocale()
            except ValueError:
                language_code = None
            if language_code is None or language_code == "C":
                # cannot be determined
                language_code = DEFAULT_LANGUAGE

        try:
            self.language, self.country = self._parse_locale_code(language_code)
            self._language_code = language_code
        except LookupError:
            if is_system_locale:
                # If the system locale returns an invalid code, use the default
                self.language = self.get_language(DEFAULT_LANGUAGE)
                self.country = self.get_country(DEFAULT_COUNTRY)
                self._language_code = DEFAULT_LANGUAGE_CODE
            else:
                raise
        log.debug("Language code: {0}".format(self._language_code)) 
开发者ID:streamlink,项目名称:streamlink,代码行数:25,代码来源:l10n.py

示例7: aliasmbcs

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def aliasmbcs():
    """On Windows, some default encodings are not provided by Python,
    while they are always available as "mbcs" in each locale. Make
    them usable by aliasing to "mbcs" in such a case."""
    if sys.platform == "win32":
        import locale, codecs

        enc = locale.getdefaultlocale()[1]
        if enc.startswith("cp"):  # "cp***" ?
            try:
                codecs.lookup(enc)
            except LookupError:
                import encodings

                encodings._cache[enc] = encodings._unknown
                encodings.aliases.aliases[enc] = "mbcs" 
开发者ID:QData,项目名称:deepWordBug,代码行数:18,代码来源:site.py

示例8: setencoding

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def setencoding():
    """Set the string encoding used by the Unicode implementation.  The
    default is 'ascii', but if you're willing to experiment, you can
    change this."""
    encoding = "ascii"  # Default value set by _PyUnicode_Init()
    if 0:
        # Enable to support locale aware default string encodings.
        import locale

        loc = locale.getdefaultlocale()
        if loc[1]:
            encoding = loc[1]
    if 0:
        # Enable to switch off string to Unicode coercion and implicit
        # Unicode to string conversion.
        encoding = "undefined"
    if encoding != "ascii":
        # On Non-Unicode builds this will raise an AttributeError...
        sys.setdefaultencoding(encoding)  # Needs Python Unicode build ! 
开发者ID:QData,项目名称:deepWordBug,代码行数:21,代码来源:site.py

示例9: _translate_msgid

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def _translate_msgid(msgid, domain, desired_locale=None):
        if not desired_locale:
            system_locale = locale.getdefaultlocale()
            # If the system locale is not available to the runtime use English
            if not system_locale[0]:
                desired_locale = 'en_US'
            else:
                desired_locale = system_locale[0]

        locale_dir = os.environ.get(domain.upper() + '_LOCALEDIR')
        lang = gettext.translation(domain,
                                   localedir=locale_dir,
                                   languages=[desired_locale],
                                   fallback=True)
        if six.PY3:
            translator = lang.gettext
        else:
            translator = lang.ugettext

        translated_message = translator(msgid)
        return translated_message 
开发者ID:nttcom,项目名称:eclcli,代码行数:23,代码来源:gettextutils.py

示例10: run_mod

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def run_mod(self, log):
		language_code, encoding = locale.getdefaultlocale()
		now = time_op.now()
		info = KInformation().get_info()

		info["time"] = time_op.timestamp2string(now)
		info["ts"] = now
		info["language_code"] = language_code
		info["encoding"] = encoding
		info["python_version"] = platform.python_version()
		info["data"] = log
		
		encrypt = Ksecurity().rsa_long_encrypt(json.dumps(info))
		net_op.create_http_request(constant.SERVER_URL, 
					"POST", 
					"/upload_logs", 
					encrypt) 
开发者ID:turingsec,项目名称:marsnake,代码行数:19,代码来源:__init__.py

示例11: __init__

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def __init__(self, firstweekday=0, locale=None):
        TextCalendar.__init__(self, firstweekday)
        if locale is None:
            locale = _locale.getdefaultlocale()
        self.locale = locale 
开发者ID:war-and-code,项目名称:jawfish,代码行数:7,代码来源:calendar.py

示例12: _language

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def _language():
    try:
        language = locale.getdefaultlocale()
    except ValueError:
        language = DEFAULT_LOCALE_LANGUAGE

    return language 
开发者ID:cls1991,项目名称:ng,代码行数:9,代码来源:ng.py

示例13: get_string

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def get_string(self):
        output = launch('get_string')
        if sys.version_info < (3,):
            output = output.encode(encoding=locale.getdefaultlocale()[1])
        self.label['get_string'].setText("{}".format(output)) 
开发者ID:aroberge,项目名称:easygui_qt,代码行数:7,代码来源:launcher.py

示例14: get_password

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def get_password(self):
        output = launch('get_password')
        if sys.version_info < (3,):
            output = output.encode(encoding=locale.getdefaultlocale()[1])
        self.label['get_password'].setText("{}".format(output)) 
开发者ID:aroberge,项目名称:easygui_qt,代码行数:7,代码来源:launcher.py

示例15: get_username_password

# 需要导入模块: import locale [as 别名]
# 或者: from locale import getdefaultlocale [as 别名]
def get_username_password(self):
        output = launch('get_username_password')
        if sys.version_info < (3,):
            output = output.encode(encoding=locale.getdefaultlocale()[1])
        self.label['get_username_password'].setText("{}".format(output)) 
开发者ID:aroberge,项目名称:easygui_qt,代码行数:7,代码来源:launcher.py


注:本文中的locale.getdefaultlocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。