コード例 #1
0
ファイル: forms.py プロジェクト: lzz12/railgun
 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."))
コード例 #2
0
ファイル: i18n.py プロジェクト: lzz12/railgun
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))