i18n.py 650 B

123456789101112131415161718192021222324
  1. from django.utils.translation import ugettext, ungettext
  2. from wtforms import form
  3. class DjangoTranslations(object):
  4. """
  5. A translations object for WTForms that gets its messages from django's
  6. translations providers.
  7. """
  8. def gettext(self, string):
  9. return ugettext(string)
  10. def ngettext(self, singular, plural, n):
  11. return ungettext(singular, plural, n)
  12. class Form(form.Form):
  13. """
  14. A Form derivative which uses the translations engine from django.
  15. """
  16. _django_translations = DjangoTranslations()
  17. def _get_translations(self):
  18. return self._django_translations