[google-appengine] Re: Sample code of i18n on GAE+Django
On Nov 19 2008, 7:20 am, niklasr nikla...@gmail.com wrote: from django.conf import settings if os.environ.get('HTTP_HOST'): url = os.environ['HTTP_HOST'] else: url = os.environ['SERVER_NAME'] if url.endswith('domain1.com'): settings.LANGUAGE_CODE = 'en' elif url.endswith('domain2.com.br'): settings.LANGUAGE_CODE = 'pt_BR' An even cleaner solution would be to use the Accept-Language header value which you can get by calling the following command: self.request.headers.get('Accept-Language') It retrieves the users preferred language specified in the browser settings. The returned value can be also a prioritized list of languages like: en_US,en,de,ru --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
Altering settings.LANGUAGE_CODE at runtime switches languages dynamically (while the django manual says not to i.e. You shouldn’t alter settings in your applications at runtime) e.g. english for .com and pt_BR for .com.br: from django.conf import settings if os.environ.get('HTTP_HOST'): url = os.environ['HTTP_HOST'] else: url = os.environ['SERVER_NAME'] if url.endswith('domain1.com'): settings.LANGUAGE_CODE = 'en' elif url.endswith('domain2.com.br'): settings.LANGUAGE_CODE = 'pt_BR' Manual pages say don't do this. The app does however dynamically choose between english and portuguese depending on the URL this way. I don't know why the manual advises against. Maybe performance reasons. best regards Niklas On 31 Okt, 01:57, Ary Manzana [EMAIL PROTECTED] wrote: Hi, Thanks all for the big effort you are putting in getting i18n into GAE. Did anyone find a way to choose a language dynamically? All the best, Ary On 23 oct, 22:03, Alexander Orlov [EMAIL PROTECTED] wrote: On Oct 20, 10:00 am, A.TNG [EMAIL PROTECTED] wrote: Do you have any idea? I meet some similar problems in my project too. I have investigated this issue and put a lot of time (too much!) tinkering to get it working but without success (found a really dirty hack to get it working with dev_appserver.py *locally*). However I have killed this task in my project to be able to go on with other tasks. I will post a corresponding solution here if I find a way for setting LANGUAGE_CODE *dynamically*. Maybe this issue is also unsolvable without a hack in GAE API version v.1... Looking forward for GAE API v. 2 :) Best Regards Alex --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
Hi, Thanks all for the big effort you are putting in getting i18n into GAE. Did anyone find a way to choose a language dynamically? All the best, Ary On 23 oct, 22:03, Alexander Orlov [EMAIL PROTECTED] wrote: On Oct 20, 10:00 am, A.TNG [EMAIL PROTECTED] wrote: Do you have any idea? I meet some similar problems in my project too. I have investigated this issue and put a lot of time (too much!) tinkering to get it working but without success (found a really dirty hack to get it working with dev_appserver.py *locally*). However I have killed this task in my project to be able to go on with other tasks. I will post a corresponding solution here if I find a way for setting LANGUAGE_CODE *dynamically*. Maybe this issue is also unsolvable without a hack in GAE API version v.1... Looking forward for GAE API v. 2 :) Best Regards Alex --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
On Oct 20, 10:00 am, A.TNG [EMAIL PROTECTED] wrote: Do you have any idea? I meet some similar problems in my project too. I have investigated this issue and put a lot of time (too much!) tinkering to get it working but without success (found a really dirty hack to get it working with dev_appserver.py *locally*). However I have killed this task in my project to be able to go on with other tasks. I will post a corresponding solution here if I find a way for setting LANGUAGE_CODE *dynamically*. Maybe this issue is also unsolvable without a hack in GAE API version v.1... Looking forward for GAE API v. 2 :) Best Regards Alex --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
On Sep 22, 4:00 pm, A.TNG [EMAIL PROTECTED] wrote: Originally in Django, locale could be set via session. But GAE cannot work with session in Django. So I tried to set settings.LANGUAGE_CODE='zh-cn' directly to make i18n works dynamically. It works. I have found some interesting information regarding the settings object: *Altering settings at runtime* You shouldn’t alter settings in your applications at runtime. [...] The only place you should assign to settings is in a settings file. See http://www.djangoproject.com/documentation/0.96/settings/ for more information! Btw Tang, as I have already told you in a mail, I could not set the LANGUAGE_CODE *dynamically*. E.g. settings.LANGUAGE_CODE = self.request.query_string does not work and after I have read the information above, the settings should not be set this way. Best Regards Alex --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
On Sep 22, 4:00 pm, A.TNG [EMAIL PROTECTED] wrote: Originally in Django, locale could be set via session. But GAE cannot work with session in Django. So I tried to set settings.LANGUAGE_CODE='zh-cn' directly to make i18n works dynamically. It works. I have extended the example webappi18n with settings.LANGUAGE_CODE='zh-cn' inserting it after self.response.out.write(_('hello')) and got this error: AttributeError: 'NoneType' object has no attribute 'LANGUAGE_CODE'. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
On Mon, Sep 15, 2008 at 11:53 AM, Mathieu [EMAIL PROTECTED] wrote: Hi TNG, I used your sample code and I have been able to create localization files for my application and make them work properly. The only problem I have now is that I dont know how to switch between each languages without hard-coding it in the settings file. I want users to be able to choose the locale they want to use. The only way I have read about involves the django middleware, but I dont believe I could succceed in making it work. I have failed over and over at moving my app to django 1.0 Originally in Django, locale could be set via session. But GAE cannot work with session in Django. So I tried to set settings.LANGUAGE_CODE='zh-cn' directly to make i18n works dynamically. It works. Maybe there are some other ways. I never tried Django 1.0. All above is based on GAE built-in Django 0.96.1. Thanks On Sep 9, 12:41 am, A.TNG [EMAIL PROTECTED] wrote: Hi, I find another way to use django's i18n middleware. The story is that you already have a app based on webapp framework and you want to make it support i18n. 1. you still need to create your .po and .mo files and put them under appproj/locale/{locale, eg: zh_CN}/LC_MESSAGES/ 2. add settings.py to appproj/ 3. modify your main.py and import several django modules. 4. Now, you could use _() in .py and {% trans %} in template. You could follow your webapp way, no need to change to django way. For detail information, you could check attached code sample. Enjoy :-) -- Best Regards, TANG Jiyu webappi18n.zip 7KViewDownload -- Best Regards, TANG Jiyu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
Hi Jiyu, This definitively works !! and Rocks !! ;-) Just tried in real world : - extract - run appcfg.py update webappi18n - browse -- Hello is transformed to Bonjour and that's pretty good ! Voilà ! Thank to you. Pierre On Sep 9, 6:41 am, A.TNG [EMAIL PROTECTED] wrote: Hi, I find another way to use django's i18n middleware. The story is that you already have a app based on webapp framework and you want to make it support i18n. 1. you still need to create your .po and .mo files and put them under appproj/locale/{locale, eg: zh_CN}/LC_MESSAGES/ 2. add settings.py to appproj/ 3. modify your main.py and import several django modules. 4. Now, you could use _() in .py and {% trans %} in template. You could follow your webapp way, no need to change to django way. For detail information, you could check attached code sample. Enjoy :-) -- Best Regards, TANG Jiyu webappi18n.zip 7KViewDownload --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
Hi, I must be a fool. I decompresses your zip then run ./dev_appserver i18nsample and it worked 'translated 'Hello' to 'Bonjour' ;-) So, : - I take your setting.py and put it in my application's directory. (Note I already have django.po in 'myapp/locale/fr/LC_MESSAGES/ django.po' and ran compile-messages) - run ./dev_appserver Nothing ... ???/.§?§ No translation. Any hint ? Pierre On 7 sep, 04:12, A.TNG [EMAIL PROTECTED] wrote: On Sun, Sep 7, 2008 at 5:29 AM, Davide Rognoni [EMAIL PROTECTED] wrote: Yes you can :-) but I don't know where is the [button] to add files. I'm posting from web... I use Gmail to check this group. So I could send a email to this group with attachments. On Sep 6, 5:01 pm, A.TNG [EMAIL PROTECTED] wrote: On 9/6/08, Davide Rognoni [EMAIL PROTECTED] wrote: How can you add i18sample.zip to the post? I just want to share the sample code. Anything wrong? File size is only 9k. On Sep 6, 4:21 pm, A.TNG [EMAIL PROTECTED] wrote: Hi All, Finally, I could make i18n work on GAE now (with built-in Django 0.96.1). Please check attached ZIP file. Set LANGUAGE_CODE in settings.py to get different locale. Enjoy. :-) -- Best Regards, TANG Jiyu i18nsample.zip 9KViewDownload -- Best Regards, TANG Jiyu -- Best Regards, TANG Jiyu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
On Sun, Sep 7, 2008 at 3:07 PM, Pierre [EMAIL PROTECTED] wrote: Hi, I must be a fool. I decompresses your zip then run ./dev_appserver i18nsample and it worked 'translated 'Hello' to 'Bonjour' ;-) So, : - I take your setting.py and put it in my application's directory. (Note I already have django.po in 'myapp/locale/fr/LC_MESSAGES/ django.po' and ran compile-messages) - run ./dev_appserver Nothing ... ???/.§?§ No translation. Any hint ? I have no idea. Could you send me your project? Maybe I will find any clue. Pierre On 7 sep, 04:12, A.TNG [EMAIL PROTECTED] wrote: On Sun, Sep 7, 2008 at 5:29 AM, Davide Rognoni [EMAIL PROTECTED] wrote: Yes you can :-) but I don't know where is the [button] to add files. I'm posting from web... I use Gmail to check this group. So I could send a email to this group with attachments. On Sep 6, 5:01 pm, A.TNG [EMAIL PROTECTED] wrote: On 9/6/08, Davide Rognoni [EMAIL PROTECTED] wrote: How can you add i18sample.zip to the post? I just want to share the sample code. Anything wrong? File size is only 9k. On Sep 6, 4:21 pm, A.TNG [EMAIL PROTECTED] wrote: Hi All, Finally, I could make i18n work on GAE now (with built-in Django 0.96.1). Please check attached ZIP file. Set LANGUAGE_CODE in settings.py to get different locale. Enjoy. :-) -- Best Regards, TANG Jiyu i18nsample.zip 9KViewDownload -- Best Regards, TANG Jiyu -- Best Regards, TANG Jiyu -- Best Regards, TANG Jiyu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
How can you add i18sample.zip to the post? On Sep 6, 4:21 pm, A.TNG [EMAIL PROTECTED] wrote: Hi All, Finally, I could make i18n work on GAE now (with built-in Django 0.96.1). Please check attached ZIP file. Set LANGUAGE_CODE in settings.py to get different locale. Enjoy. :-) -- Best Regards, TANG Jiyu i18nsample.zip 9KViewDownload --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
On 9/6/08, Davide Rognoni [EMAIL PROTECTED] wrote: How can you add i18sample.zip to the post? I just want to share the sample code. Anything wrong? File size is only 9k. On Sep 6, 4:21 pm, A.TNG [EMAIL PROTECTED] wrote: Hi All, Finally, I could make i18n work on GAE now (with built-in Django 0.96.1). Please check attached ZIP file. Set LANGUAGE_CODE in settings.py to get different locale. Enjoy. :-) -- Best Regards, TANG Jiyu i18nsample.zip 9KViewDownload -- Best Regards, TANG Jiyu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: Sample code of i18n on GAE+Django
On Sun, Sep 7, 2008 at 5:29 AM, Davide Rognoni [EMAIL PROTECTED] wrote: Yes you can :-) but I don't know where is the [button] to add files. I'm posting from web... I use Gmail to check this group. So I could send a email to this group with attachments. On Sep 6, 5:01 pm, A.TNG [EMAIL PROTECTED] wrote: On 9/6/08, Davide Rognoni [EMAIL PROTECTED] wrote: How can you add i18sample.zip to the post? I just want to share the sample code. Anything wrong? File size is only 9k. On Sep 6, 4:21 pm, A.TNG [EMAIL PROTECTED] wrote: Hi All, Finally, I could make i18n work on GAE now (with built-in Django 0.96.1). Please check attached ZIP file. Set LANGUAGE_CODE in settings.py to get different locale. Enjoy. :-) -- Best Regards, TANG Jiyu i18nsample.zip 9KViewDownload -- Best Regards, TANG Jiyu -- Best Regards, TANG Jiyu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---