Skip to content

Commit

Permalink
Merge branch 'k-nut-3060-set-formencode-default-lang'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jun 3, 2016
2 parents 0856d55 + 0b7aa77 commit ae9e163
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ckan/config/environment.py
Expand Up @@ -9,6 +9,7 @@

import sqlalchemy
from pylons import config
import formencode

import ckan.config.routing as routing
import ckan.model as model
Expand Down Expand Up @@ -200,6 +201,12 @@ def update_config():
template_paths = extra_template_paths.split(',') + template_paths
config['pylons.app_globals'].template_paths = template_paths

# Set the default language for validation messages from formencode
# to what is set as the default locale in the config
default_lang = config.get('ckan.locale_default', 'en')
formencode.api.set_stdtranslation(domain="FormEncode",
languages=[default_lang])

# Markdown ignores the logger config, so to get rid of excessive
# markdown debug messages in the log, set it to the level of the
# root logger.
Expand Down
1 change: 1 addition & 0 deletions ckan/lib/navl/dictization_functions.py
Expand Up @@ -8,6 +8,7 @@

from ckan.common import _


class Missing(object):
def __unicode__(self):
raise Invalid(_('Missing value'))
Expand Down
30 changes: 30 additions & 0 deletions ckan/tests/lib/test_navl.py
@@ -0,0 +1,30 @@
import nose
import pylons

from ckan.tests import helpers
from ckan.config import environment

eq_ = nose.tools.eq_


class TestFormencdoeLanguage(object):
@helpers.change_config('ckan.locale_default', 'de')
def test_formencode_uses_locale_default(self):
environment.update_config()
from ckan.lib.navl.dictization_functions import validate
from ckan.lib.navl.validators import not_empty
from formencode import validators
schema = {
"name": [not_empty, unicode],
"email": [validators.Email],
"email2": [validators.Email],
}

data = {
"name": "fred",
"email": "32",
"email2": "david@david.com",
}

converted_data, errors = validate(data, schema)
eq_({'email': [u'Eine E-Mail-Adresse muss genau ein @-Zeichen enthalten']}, errors)

0 comments on commit ae9e163

Please sign in to comment.