當前位置: 首頁>>代碼示例>>Python>>正文


Python locale.setlocale方法代碼示例

本文整理匯總了Python中locale.setlocale方法的典型用法代碼示例。如果您正苦於以下問題:Python locale.setlocale方法的具體用法?Python locale.setlocale怎麽用?Python locale.setlocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在locale的用法示例。


在下文中一共展示了locale.setlocale方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: activate_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def activate_locale(self):
        """
        Activates this user's locale
        """
        try:
            lc = self.locale.split('.')
            region = self.region.split('.')
            locale.setlocale(locale.LC_TIME, region)
            locale.setlocale(locale.LC_MESSAGES, lc)
            locale.setlocale(locale.LC_NUMERIC, region)
            locale.setlocale(locale.LC_MONETARY, region)
        except Exception as e:
            locale.setlocale(locale.LC_ALL, None)

        # Return the language code
        return self.locale.split('_', 1)[0] 
開發者ID:fpsw,項目名稱:Servo,代碼行數:18,代碼來源:account.py

示例2: main

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    # Configure our deprecation warnings to be sent through loggers
    deprecation.install_warning_logger()

    autocomplete()

    try:
        cmd_name, cmd_args = parseopts(args)
    except PipError as exc:
        sys.stderr.write("ERROR: %s" % exc)
        sys.stderr.write(os.linesep)
        sys.exit(1)

    # Needed for locale.getpreferredencoding(False) to work
    # in pip.utils.encoding.auto_decode
    locale.setlocale(locale.LC_ALL, '')
    command = commands_dict[cmd_name](isolated=check_isolated(cmd_args))
    return command.main(cmd_args)


# ###########################################################
# # Writing freeze files 
開發者ID:jpush,項目名稱:jbox,代碼行數:27,代碼來源:__init__.py

示例3: testConvertTo

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def testConvertTo(self):
        size = Size("1.5 KiB")
        conv = size.convert_to("KiB")
        self.assertEqual(conv, Decimal("1.5"))

        locale.setlocale(locale.LC_ALL,'cs_CZ.UTF-8')
        size = Size("1.5 KiB")
        conv = size.convert_to("KiB")
        self.assertEqual(conv, Decimal("1.5"))

        # this persian locale uses a two-byte unicode character for the radix
        locale.setlocale(locale.LC_ALL, 'ps_AF.UTF-8')
        size = Size("1.5 KiB")
        conv = size.convert_to("KiB")
        self.assertEqual(conv, Decimal("1.5"))

        locale.setlocale(locale.LC_ALL,'en_US.UTF-8') 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:19,代碼來源:lbs_py_override_unittest.py

示例4: test_option_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [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: test_getsetlocale_issue1813

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def test_getsetlocale_issue1813(self):
        # Issue #1813: setting and getting the locale under a Turkish locale
        oldlocale = locale.getlocale()
        self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
        for loc in ('tr_TR', 'tr_TR.UTF-8', 'tr_TR.ISO8859-9'):
            try:
                locale.setlocale(locale.LC_CTYPE, loc)
                break
            except locale.Error:
                continue
        else:
            # Unsupported locale on this system
            self.skipTest('test needs Turkish locale')
        loc = locale.getlocale()
        try:
            locale.setlocale(locale.LC_CTYPE, loc)
        except Exception as e:
            self.fail("Failed to set locale %r (default locale is %r): %r" %
                      (loc, oldlocale, e))
        self.assertEqual(loc, locale.getlocale()) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_locale.py

示例6: test_locale_caching

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def test_locale_caching(self):
        # Issue #22410
        oldlocale = locale.setlocale(locale.LC_CTYPE)
        self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
        for loc in 'en_US.iso88591', 'en_US.utf8':
            try:
                locale.setlocale(locale.LC_CTYPE, loc)
            except locale.Error:
                # Unsupported locale on this system
                self.skipTest('test needs %s locale' % loc)

        re.purge()
        self.check_en_US_iso88591()
        self.check_en_US_utf8()
        re.purge()
        self.check_en_US_utf8()
        self.check_en_US_iso88591() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_re.py

示例7: tick

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def tick(self):
        with setlocale(ui_locale):
            if time_format == 12:
                time2 = time.strftime('%I:%M %p') #hour in 12h format
            else:
                time2 = time.strftime('%H:%M') #hour in 24h format

            day_of_week2 = time.strftime('%A')
            date2 = time.strftime(date_format)
            # if time string has changed, update it
            if time2 != self.time1:
                self.time1 = time2
                self.timeLbl.config(text=time2)
            if day_of_week2 != self.day_of_week1:
                self.day_of_week1 = day_of_week2
                self.dayOWLbl.config(text=day_of_week2)
            if date2 != self.date1:
                self.date1 = date2
                self.dateLbl.config(text=date2)
            # calls itself every 200 milliseconds
            # to update the time display as needed
            # could use >200 ms, but display gets jerky
            self.timeLbl.after(200, self.tick) 
開發者ID:HackerShackOfficial,項目名稱:Smart-Mirror,代碼行數:25,代碼來源:smartmirror.py

示例8: _currency_symbols

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def _currency_symbols():
    """Compile a list of valid currency symbols."""
    current = locale.getlocale()
    locales = list(locale.locale_alias.values())
    symbols = set()

    for loc in locales:
        try:
            locale.setlocale(locale.LC_MONETARY, locale.normalize(loc))
            currency = "{int_curr_symbol}".format(**locale.localeconv())
            if currency != "":
                symbols.add(currency.strip())
        except (locale.Error, UnicodeDecodeError):
            continue

    locale.setlocale(locale.LC_MONETARY, current)
    return list(symbols) 
開發者ID:project-koku,項目名稱:koku,代碼行數:19,代碼來源:serializers.py

示例9: save_preferences

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def save_preferences(self):
        language = self.ui.get_language()
        if language == None:
            language = ''
        self.check_permissions_dialog = self.ui.get_check_permissions()
        check_permissions = '1' if self.check_permissions_dialog else '0'
        config = configparser.ConfigParser()
        if language != '':
            try:
                locale.setlocale(locale.LC_ALL, (language, 'UTF-8'))
            except locale.Error:
                self.ui.info_dialog(_("Failed to change language."),
                _("Make sure locale '" + str(language) + ".UTF8' is generated on your system" ))
                self.ui.set_language(self.locale)
                language = self.ui.get_language()
        config['DEFAULT'] = {
            'locale': language,
            'check_permissions': check_permissions,
            'button_config': ','.join(map(str, self.button_config)),
        }
        config_file = os.path.join(self.config_path, 'config.ini')
        with open(config_file, 'w') as file:
            config.write(file) 
開發者ID:berarma,項目名稱:oversteer,代碼行數:25,代碼來源:gui.py

示例10: main

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    # Configure our deprecation warnings to be sent through loggers
    deprecation.install_warning_logger()

    autocomplete()

    try:
        cmd_name, cmd_args = parseopts(args)
    except PipError as exc:
        sys.stderr.write("ERROR: %s" % exc)
        sys.stderr.write(os.linesep)
        sys.exit(1)

    # Needed for locale.getpreferredencoding(False) to work
    # in pip._internal.utils.encoding.auto_decode
    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error as e:
        # setlocale can apparently crash if locale are uninitialized
        logger.debug("Ignoring error %s when setting locale", e)
    command = commands_dict[cmd_name](isolated=check_isolated(cmd_args))
    return command.main(cmd_args) 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:27,代碼來源:__init__.py

示例11: initLocale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def initLocale():
    # Only initialize locale once
    if initLocale.is_done:
        return getTerminalCharset()
    initLocale.is_done = True

    # Setup locales
    try:
        locale.setlocale(locale.LC_ALL, "")
    except (locale.Error, IOError):
        pass

    # Get the terminal charset
    charset = getTerminalCharset()

    # UnicodeStdout conflicts with the readline module
    if config.unicode_stdout and ('readline' not in sys.modules):
        # Replace stdout and stderr by unicode objet supporting unicode string
        sys.stdout = UnicodeStdout(sys.stdout, charset)
        sys.stderr = UnicodeStdout(sys.stderr, charset)
    return charset 
開發者ID:Yukinoshita47,項目名稱:Yuki-Chan-The-Auto-Pentest,代碼行數:23,代碼來源:i18n.py

示例12: start

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def start(self, no_delay):
        self.window = curses.initscr()
        curses.start_color()
        curses.use_default_colors()
        curses.noecho()
        curses.cbreak()
        curses.curs_set(0)
        self.window.nodelay(no_delay)
        self.init_colors()
        self.window.bkgd(curses.color_pair(self.WHITE))
        locale.setlocale(locale.LC_ALL, '')    # set your locale
        self.code = locale.getpreferredencoding() 
開發者ID:Battelle,項目名稱:sandsifter,代碼行數:14,代碼來源:gui.py

示例13: init_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def init_locale(request):
    """Initialize locale for the check-in interface."""
    lc = settings.INSTALL_LOCALE.split('.')
    locale.setlocale(locale.LC_TIME, lc)
    locale.setlocale(locale.LC_NUMERIC, lc)
    locale.setlocale(locale.LC_MESSAGES, lc)
    locale.setlocale(locale.LC_MONETARY, lc)

    translation.activate(settings.INSTALL_LANGUAGE)
    request.session[translation.LANGUAGE_SESSION_KEY] = settings.INSTALL_LANGUAGE 
開發者ID:fpsw,項目名稱:Servo,代碼行數:12,代碼來源:checkin.py

示例14: get_unit_received

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def get_unit_received(self):
        """
        Returns (as a tuple) the GSX-compatible date and time of
        when this unit was received
        """
        import locale
        langs = gsxws.get_format('en_XXX')
        ts = self.unit_received_at
        loc = locale.getlocale()
        # reset locale to get correct AM/PM value
        locale.setlocale(locale.LC_TIME, None)
        result = ts.strftime(langs['df']), ts.strftime(langs['tf'])
        locale.setlocale(locale.LC_TIME, loc)
        return result 
開發者ID:fpsw,項目名稱:Servo,代碼行數:16,代碼來源:repair.py

示例15: run_with_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import setlocale [as 別名]
def run_with_locale(catstr, *locales):
    def decorator(func):
        def inner(*args, **kwds):
            try:
                import locale
                category = getattr(locale, catstr)
                orig_locale = locale.setlocale(category)
            except AttributeError:
                # if the test author gives us an invalid category string
                raise
            except:
                # cannot retrieve original locale, so do nothing
                locale = orig_locale = None
            else:
                for loc in locales:
                    try:
                        locale.setlocale(category, loc)
                        break
                    except:
                        pass

            # now run the function, resetting the locale on exceptions
            try:
                return func(*args, **kwds)
            finally:
                if locale and orig_locale:
                    locale.setlocale(category, orig_locale)
        inner.__name__ = func.__name__
        inner.__doc__ = func.__doc__
        return inner
    return decorator

#=======================================================================
# Decorator for running a function in a specific timezone, correctly
# resetting it afterwards. 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:37,代碼來源:support.py


注:本文中的locale.setlocale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。