Ejemplo n.º 1
0
 def _determine_locale(my_locale: Locale = None, author_info: dict = None) -> Locale:
     if my_locale:
         if not isinstance(my_locale, Locale):
             raise TypeError("my_locale must be a babel Locale object")
     else:
         if author_info:
             try:
                 my_locale = Locale.parse(author_info["locale"], sep="-")
             except UnknownLocaleError:
                 logger.warning("Could not use locale info from Slack")
                 my_locale = Locale.default()
         else:
             my_locale = Locale.default()
     if not my_locale:
         my_locale = Locale.parse(settings.FALLBACK_LOCALE)
     return my_locale
Ejemplo n.º 2
0
def defaultLocale():
    try:
        lang, _ = locale.getdefaultlocale()
    except Exception:
        lang = None

    if lang is not None:
        return Locale.parse(lang)
    else:
        return Locale.default()
Ejemplo n.º 3
0
    def __babel_default(self):
        logger.debug('Babel is using default locale')

        # Locale.default will raise an UnknownLocaleError if
        # the environment variables are not set or set wrong
        # This generally happens on Windows only
        # See: http://babel.edgewall.org/ticket/98
        try:
            locale = Locale.default()
        except ValueError:
            logger.debug('Babel did not understand default locale')
            locale = Locale(self.fallback_language)
        except UnknownLocaleError:
            logger.debug('Babel does not support default locale')
            locale = Locale(self.fallback_language)
        else:
            if locale is None:
                logger.debug('Babel returned a default locale of None')
                locale = Locale(self.fallback_language)
            cbpos.locale = locale
Ejemplo n.º 4
0
 def __babel_default(self):
     logger.debug('Babel is using default locale')
     
     # Locale.default will raise an UnknownLocaleError if
     # the environment variables are not set or set wrong
     # This generally happens on Windows only
     # See: http://babel.edgewall.org/ticket/98 
     try:
         locale = Locale.default()
     except ValueError:
         logger.debug('Babel did not understand default locale')
         locale = Locale(self.fallback_language)
     except UnknownLocaleError:
         logger.debug('Babel does not support default locale')
         locale = Locale(self.fallback_language)
     else:
         if locale is None:
             logger.debug('Babel returned a default locale of None')
             locale = Locale(self.fallback_language)
         cbpos.locale = locale
Ejemplo n.º 5
0
 def test_default(self, os_environ):
     for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LC_MESSAGES']:
         os_environ[name] = ''
     os_environ['LANG'] = 'fr_FR.UTF-8'
     default = Locale.default('LC_MESSAGES')
     assert (default.language, default.territory) == ('fr', 'FR')
Ejemplo n.º 6
0
def test_can_return_default_locale(os_environ):
    os_environ['LC_MESSAGES'] = 'fr_FR.UTF-8'
    assert Locale('fr', 'FR') == Locale.default('LC_MESSAGES')
Ejemplo n.º 7
0
 def test_default(self, os_environ):
     for name in ["LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_MESSAGES"]:
         os_environ[name] = ""
     os_environ["LANG"] = "fr_FR.UTF-8"
     default = Locale.default("LC_MESSAGES")
     assert (default.language, default.territory) == ("fr", "FR")
Ejemplo n.º 8
0
def test_can_return_default_locale(os_environ):
    os_environ["LC_MESSAGES"] = "fr_FR.UTF-8"
    assert Locale("fr", "FR") == Locale.default("LC_MESSAGES")
Ejemplo n.º 9
0
def get_user_locale():
    return LocaleInfo.from_babel_locale(Locale.default())