Esempio n. 1
0
 def validate_locale(form, field):
     """Validate whether the user provided locale is a valid locale."""
     try:
         Locale(field.data)
     except UnknownLocaleError:
         raise ValidationError(
             _("Please select a valid locale from above."))
Esempio n. 2
0
def list_locales():
    """Get a list of available :class:`babel.core.Locale` objects.

    Whatever translations the system provides, "en" should always
    appear in the list.  The returned list should be sorted in the order
    of display names, which may be vary in different languages.

    :return: :class:`list` of :class:`babel.core.Locale` objects.
    """
    ret = [Locale('en')] + babel.list_translations()
    return sorted(ret, cmp=lambda a, b: cmp(a.display_name, b.display_name))