Le 28/03/2012 19:56, John Anderson a écrit :
>
>
> On Wed, Mar 28, 2012 at 12:15 PM, tonthon <[email protected]
> <mailto:[email protected]>> wrote:
>
>     Hi,
>
>     I'm trying to get translated messages while using deform (I'm
>     working on
>     a french-only application).
>
>     I've added :
>     """
>     pyramid.default_locale_name = fr
>     """
>     to my application inifile.
>
>     I've added :
>     """
>     config.add_translation_dirs('deform:locale')
>     """
>     to my application __init__.py.
>
>     But it doesn't seem to be sufficient.
>
>     I've tried launching the following one from within one of my views :
>     """
>     from pyramid.i18n import
>     TranslationStringFactory
>     from pyramid.i18n import
>     get_localizer
>
>
>     translater =
>     TranslationStringFactory('deform')
>
>     def _(request, string,
>     mapping=None):
>         ts = translater(string,
>     mapping)
>         localizer =
>     get_localizer(request)
>         return localizer.translate(ts)
>
>     def myview(request):
>         print _(Required)
>         ...
>     """
>     and it prints "Requis" as expected. I can consider my setup is
>     fine, but
>     I can't understand why deform messages are still in english.
>
>     How should I do to make deform render translated strings ?
>
>     Regards,
>     Gaston
>
>
> deform has nothing to do with pyramid or its translation hooks.  You
> need to pass deform a renderer with a translator as well with:
>
>  deform.Form.set_default_renderer(renderer)
>
>
Ok, I thought it could magically handle it :).

I've now passed a renderer and some of my strings are translated, but
the one coming from the chameleon templates are still in english.
Did I miss something ?

A sample of my code :
"""
def
get_deform_renderer():                                                     
     deform_template_dir = resource_filename('deform',
'templates/')            
     def
translator(term):                                                      
         return
get_localizer(get_current_request()).translate(term)            
     renderer =
deform.ZPTRendererFactory(                                      
                                         
[deform_template_dir],                 
                                          
translator=translator)                
     return
renderer                                                            

  def
set_deform_renderer():                                                     
       renderer =
get_deform_renderer()                                           
       deform.Form.set_default_renderer(renderer)         
"""

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to