pylons has an ugly hack to make form encode translations work - by using the PylonsFormEncodeState which has a translation method as attribute, as the default state object. So in effect if you try to use a different state object, then translations won't work.
On Jan 17, 10:25 am, mickolka <[email protected]> wrote: > I got the problem here is a bug report to the formencode > trackerhttps://sourceforge.net/tracker/?func=detail&atid=596416&aid=2515640&... > The cause of such a strange behaviour was.... > from xml import xpath > after you do it - set_stdtranslation stop work and always return > English > > On Jan 13, 7:21 pm, mickolka <[email protected]> wrote: > > > > > Hi, > > I have a different problem with pylons andformencodei18n > > when I run the following code in console > > importformencode > > ne > > =formencode.validators.NotEmpty()formencode.api.set_stdtranslation(language > > s=["de"]) > > try: > > ne.to_python("") > > exceptformencode.api.Invalid, e: > > print str(e) > > > I get printed > > > Bitte einen Wert eingeben > > > when I do in inside a controller I get printed > > > Please enter a value > > > What can be the problem with it? > > my easy_install.pth file is > > import sys; sys.__plen = len(sys.path) > > ./Mako-0.1.8-py2.5.egg > > ./nose-0.10.1-py2.5.egg > > ./decorator-2.2.0-py2.5.egg > > ./PasteScript-1.3.6-py2.5.egg > > ./PasteDeploy-1.3.1-py2.5.egg > > ./AuthKit-0.4.0-py2.5.egg > > ./elementtree-1.2.7_20070827_preview-py2.5.egg > > ./python_urljr-1.0.1-py2.5.egg > > ./python_yadis-1.1.0-py2.5.egg > > ./python_openid-1.2.0-py2.5.egg > > ./Babel-0.9.2-py2.5.egg > > ./paginate-0.3.2-py2.5.egg > > ./sqlalchemy_migrate-0.4.3-py2.5.egg > > ./Elixir-0.5.2-py2.5.egg > > ./Beaker-0.9.3-py2.5.egg > > ./Routes-1.8-py2.5.egg > > ./SQLAlchemy-0.4.5-py2.5.egg > > ./pytils-0.2.2-py2.5.egg > > ./logging-0.4.9.6-py2.5.egg > > ./xlrd-0.6.1-py2.5.egg > > ./dateutil-1.1-py2.5.egg > > ./pytz-2008b-py2.5.egg > > ./pygooglechart-0.2.0-py2.5.egg > > ./PyYAML-3.05-py2.5.egg > > ./setuptools-0.6c8-py2.5.egg > > ./Paste-1.7.1-py2.5.egg > > ./geopy-0.93-py2.5.egg > > ./WebOb-0.9.2-py2.5.egg > > ./flup-1.0.1-py2.5.egg > > ./bsddb3-4.7.2-py2.5-macosx-10.5-i386.egg > > ./simplejson-2.0.4-py2.5-macosx-10.5-i386.egg > > ./WebHelpers-0.6.4-py2.5.egg > > ./clonedigger-1.0.9_beta-py2.5.egg > > ./FormBuild-0.1.6b-py2.5.egg > > ./FormEncode-1.0.1-py2.5.egg > > ./Pylons-0.9.6.1-py2.5.egg > > import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; > > p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p > > +len(new) > > > Also some time ago there were no problems with it, probably it is > > somehow related to our switch to newer webhelpers > > > Thanks in advance for any help. > > > Mykola > > > On Nov 20 2008, 9:28 am, "Dalius Dobravolskas" > > > <[email protected]> wrote: > > > Hi, > > > > > I'm having some troubles withFormEncodeand internationalization. > > > > What I'm trying to do is to make FE to display properly translated > > > > messages for those form fields that are not valid. After a lot of > > > > trials and errors I found that (using paster shell): > > > > >>>>formencode.api.set_stdtranslation(domain='FormEncode', > > > >>>>languages=['it']) > > > >>>>formencode.api._stdtrans('Please enter a value') > > > > > works as expected and I get the translated message. However: > > > > >>>> pylons.decorators.formencode_gettext('Please enter a value') > > > > > gives me the original message (i.e. in english). What I don't > > > > understand here is that in pylons/decorators/__init__.py there is the > > > > following import statament: > > > > > fromformencode.api import _stdtrans as formencode_gettext > > > > > so calling pylons.decorators.formencode_gettext() should give the same > > > > result as callingformencode.api._stdtrans(). But it doesn't! > > > > > It's like the former set_stdtranslation() call has no effect when I > > > > call _stdtrans() from within pylons. But I really don't understand > > > > what's going on here. Any help? > > > > While it looks the same it is not:>>>formencode.api._stdtrans > > > > <bound method GNUTranslations.ugettext of <gettext.GNUTranslations > > > instance at 0x00C63288>>>>> pylons.decorators.formencode_gettext > > > > <bound method NullTranslations.ugettext of <gettext.NullTranslations > > > instance at 0x00D405D0>> > > > > In my opinion you shouldn't use this function directly. decorators > > > module exports only jsonify and validate functions. Use them. > > > That's how I solved validate problem: > > > > from pylons.i18n import set_lang > > > > class PeklaStateFactory(object): > > > > def __call__(self): > > > set_lang('it') > > > formencode.api.set_stdtranslation(domain="FormEncode", > > > languages=['it']) > > > return None > > > > state_factory = PeklaStateFactory() > > > > That's how you can use state_factory with tosca widgets validate: > > > @validate(form=banner_form, error_handler='edit', > > > state_factory=state_factory) > > > > Pylons validate should use state (not state_factory) but I have not > > > tested that. > > > > -- > > > Daliushttp://blog.sandbox.lt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
