Exemplo n.º 1
0
 def locale_tuple(self):
     """
     Testing locale identifier parsing attributes
     """
     l = Locale.parse('en-AU')
     print "language:", l.language
     print "territory:", l.territory
     print "script:", l.script
     print "variant:", l.variant
     
     print get_locale_identifier((l.language, l.territory, l.script, l.variant), sep='_')
Exemplo n.º 2
0
def language_tag(locale: str) -> str:
    """
    Returns a BCP47/RFC5646 language tag for the locale.

    For example, it will convert "fr_FR" to "fr-FR".
    """
    return get_locale_identifier(parse_locale(locale), sep="-")
Exemplo n.º 3
0
    def language_tag(self) -> str:
        """
        Returns a BCP47/RFC5646 language tag for the locale.

        Language tags are used in HTTP headers and the HTML lang
        attribute.
        """
        return get_locale_identifier(parse_locale(str(self.locale)), sep="-")
Exemplo n.º 4
0
def get_available_languages():
    """Returns a list that contains all available languages. The items in the
    list are tuples where the first item of the tuple is the locale
    identifier (i.e. de_AT) and the second one the display name of the locale.
    For example::

        [('de_AT', 'Deutsch (Österreich)')]
    """
    return [(get_locale_identifier((l.language, l.territory)), l.display_name)
            for l in babel.list_translations()]
Exemplo n.º 5
0
def get_available_languages():
    """Returns a list that contains all available languages. The items in the
    list are tuples where the first item of the tuple is the locale
    identifier (i.e. de_AT) and the second one the display name of the locale.
    For example::

        [('de_AT', 'Deutsch (Österreich)')]
    """
    return [
        (get_locale_identifier((l.language, l.territory)), l.display_name)
        for l in babel.list_translations()
    ]
Exemplo n.º 6
0
 def clean_locale(self):
     data = self.cleaned_data['locale']
     if data:
         # only accept "_" as separator, all "-" are replaced to "_"
         data = "_".join(data.split("-"))
         try:
             self.locale_trans = Locale.parse(data)
         except UnknownLocaleError:
             raise forms.ValidationError("Invalid locale")
         except ValueError:
             raise forms.ValidationError("Invalid locale")
         else:
             data = get_locale_identifier((self.locale_trans.language, self.locale_trans.territory, self.locale_trans.script, self.locale_trans.variant), sep='_')
     return data
Exemplo n.º 7
0
 def clean_locale(self):
     data = self.cleaned_data['locale']
     if data:
         # only accept "_" as separator, all "-" are replaced to "_"
         data = "_".join(data.split("-"))
         try:
             self.locale_trans = Locale.parse(data)
         except UnknownLocaleError:
             raise forms.ValidationError("Invalid locale")
         except ValueError:
             raise forms.ValidationError("Invalid locale")
         else:
             data = get_locale_identifier(
                 (self.locale_trans.language, self.locale_trans.territory,
                  self.locale_trans.script, self.locale_trans.variant),
                 sep='_')
     return data
Exemplo n.º 8
0
def get_identifier_from_locale_class(locale):
    return get_locale_identifier(
        (locale.language, locale.territory, locale.script, locale.variant))
Exemplo n.º 9
0
def get_identifier_from_locale_class(locale):
    return get_locale_identifier(
        (locale.language,
         locale.territory,
         locale.script,
         locale.variant))