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='_')
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="-")
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="-")
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()]
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() ]
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
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
def get_identifier_from_locale_class(locale): return get_locale_identifier( (locale.language, locale.territory, locale.script, locale.variant))