Search code examples
pythoninternationalizationpyramidchameleondeform

How to work on internationalization of Pyramid forms?


I have been looking online for localization of error messages and labels of pyramid forms but so far without any luck. I have worked on both pyramid_simpleform and pyramid_deform. Has anyone worked on something similiar. The docs are not much of help.

The example given on this page does not work for me.

I also tried the docs of pyramid_deform and pyramid_simpleform.

I do not care which form library I use. I want something that has straightforward support for localization.


Solution

  • This is what has worked for me.

       from pyramid.i18n import get_locale_name
       from pyramid_simpleform import Form,State
       from formencode import api as formencode_api
       def includeme(config):
         config.scan(__name__)
         config.add_route('login', '/login')
    
       @view_config(route_name='login',renderer='website/login.mak')
       def login(request):
    
         formencode_api.set_stdtranslation(languages=[get_locale_name(request)])
    
         form = Form(request,
                defaults=dict(request.params),
                schema=MySchema,
                state=State()                
                )
         form.state._ = ''