Commit 488af54f authored by Paul Brown's avatar Paul Brown

Fix translations for validation errors

parent 520d2506
......@@ -11,6 +11,13 @@ except ImportError:
def lazy_gettext(string, **variables):
return gettext(string, **variables)
class Translations(object):
''' dummy Translations class for WTForms, no translation support '''
def gettext(self, string):
return gettext(string)
def ngettext(self, singular, plural, n):
return ngettext(singular, plural, n)
else:
from flask_admin import translations
......@@ -34,5 +41,21 @@ else:
ngettext = domain.ngettext
lazy_gettext = domain.lazy_gettext
try:
from wtforms.i18n import messages_path
except ImportError:
from wtforms.ext.i18n.utils import messages_path
wtforms_domain = Domain(messages_path(), domain='wtforms')
class Translations(object):
''' Fixes WTForms translation support and uses wtforms translations '''
def gettext(self, string):
return wtforms_domain.gettext(string)
def ngettext(self, singular, plural, n):
return wtforms_domain.ngettext(singular, plural, n)
# lazy imports
from .helpers import get_current_view
from wtforms import form, __version__ as wtforms_version
from wtforms.fields.core import UnboundField
from flask_admin.babel import Translations
from .fields import *
from .widgets import *
......@@ -7,11 +8,16 @@ from .upload import *
class BaseForm(form.Form):
_translations = Translations()
def __init__(self, formdata=None, obj=None, prefix=u'', **kwargs):
self._obj = obj
super(BaseForm, self).__init__(formdata=formdata, obj=obj, prefix=prefix, **kwargs)
def _get_translations(self):
return self._translations
class FormOpts(object):
__slots__ = ['widget_args', 'form_rules']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment