I18n doesn't work outside Pylons Controller
Hi, I have a i18n string defined outside the Pylons Controller, it could be collected by python setup.py extract_messages, I can translate the string and compile it. But in the output page, don't know why it always displays non-translated string. For example: # myapp/controller/hello.py global_string = _(Global String) # Display non-translated string always, why? class HelloController(BaseController): def index(self): c.global_string = global_string c.local_string = _('Local String') # Display translated string correctly return render('/index.mako') Any idea? Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: I18n doesn't work outside Pylons Controller
Olli Wang wrote: Hi, I have a i18n string defined outside the Pylons Controller, it could be collected by python setup.py extract_messages, I can translate the string and compile it. But in the output page, don't know why it always displays non-translated string. For example: # myapp/controller/hello.py global_string = _(Global String) # Display non-translated string always, why? class HelloController(BaseController): def index(self): c.global_string = global_string c.local_string = _('Local String') # Display translated string correctly return render('/index.mako') Any idea? Thanks. Use lazy_gettext as defined in http://wiki.pylonshq.com/display/pylonsdocs/Internationalization+and+Localization#lazy-translations. There is explanation of your problem BTW. Regards, Dalius --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: I18n doesn't work outside Pylons Controller
Hi, Dalius. I had tried lazy_gettext, but don't know why the lazy_gettext strings won't be collected after I run python setup.py extract_messages, therefore, I couldn't translate the string. :( On Mar 31, 2:46 pm, Dalius Dobravolskas [EMAIL PROTECTED] wrote: Use lazy_gettext as defined inhttp://wiki.pylonshq.com/display/pylonsdocs/Internationalization+and+ There is explanation of your problem BTW. Regards, Dalius --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: I18n doesn't work outside Pylons Controller
Olli Wang wrote: Hi, Dalius. I had tried lazy_gettext, but don't know why the lazy_gettext strings won't be collected after I run python setup.py extract_messages, therefore, I couldn't translate the string. :( If you are lazier than lazy_gettext do following: lazy_gettext(_('your string')) I have not checked that but I guess extract_messages should collect your string now and it will not hit your performance. Regards, Dalius --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: I18n doesn't work outside Pylons Controller
Thanks, Dalius. It works. But I happened into another encoding issue: global_test = lazy_gettext(_('Global Test')) class HelloController(BaseController): def test(self): return str(global_test) # Works fine, returns the translated string def test2(self): return unicode(global_test) # It renders the following traceback Module ollix.controllers.accounts:26 in signin g = str(global_test) print type(g), g return unicode(global_test) c.global_test = 'g' return render('/accounts/signin.mako') return unicode(global_test) Module pylons.i18n.translation:37 in __unicode__ def __unicode__(self): return unicode(self.eval()) def __str__(self): return unicode(self.eval()) type 'exceptions.UnicodeDecodeError': 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128) I've tried many ways to encode the string to unicode but failed. This also causes my mako template down. Any suggestion? Thanks. On Mar 31, 3:02 pm, Dalius Dobravolskas [EMAIL PROTECTED] wrote: Olli Wang wrote: Hi, Dalius. I had tried lazy_gettext, but don't know why the lazy_gettext strings won't be collected after I run python setup.py extract_messages, therefore, I couldn't translate the string. :( If you are lazier than lazy_gettext do following: lazy_gettext(_('your string')) I have not checked that but I guess extract_messages should collect your string now and it will not hit your performance. Regards, Dalius --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: I18n doesn't work outside Pylons Controller
Olli Wang wrote: Thanks, Dalius. It works. But I happened into another encoding issue: global_test = lazy_gettext(_('Global Test')) class HelloController(BaseController): def test(self): return str(global_test) # Works fine, returns the translated string def test2(self): return unicode(global_test) # It renders the following Try following: return unicode(global_test.decode('utf-8')) Again, plain guess. I guess there are more possibilities but I'm not aware about them. You should consult pylons code here. Regards, Dalius --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: I18n doesn't work outside Pylons Controller
Oh, thanks a lot. Everything works fine now. :) On Mar 31, 4:51 pm, Dalius Dobravolskas [EMAIL PROTECTED] wrote: Olli Wang wrote: Thanks, Dalius. It works. But I happened into another encoding issue: global_test = lazy_gettext(_('Global Test')) class HelloController(BaseController): def test(self): return str(global_test) # Works fine, returns the translated string def test2(self): return unicode(global_test) # It renders the following Try following: return unicode(global_test.decode('utf-8')) Again, plain guess. I guess there are more possibilities but I'm not aware about them. You should consult pylons code here. Regards, Dalius --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: I18n doesn't work outside Pylons Controller
On Mar 31, 2008, at 12:48 AM, Olli Wang wrote: Thanks, Dalius. It works. But I happened into another encoding issue: global_test = lazy_gettext(_('Global Test')) class HelloController(BaseController): def test(self): return str(global_test) # Works fine, returns the translated string def test2(self): return unicode(global_test) # It renders the following traceback I've tried many ways to encode the string to unicode but failed. This also causes my mako template down. Any suggestion? Thanks. You want lazy_ugettext -- Philip Jenvey --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---