Re: Translation outside the broswer
You can pass the latest language_code in the url and set that to the session >>>Is there a way to retrieve the latest language used in the user session? cheers *Laxmikant* On Wed, Oct 10, 2012 at 9:14 PM, Bastian wrote: > Ok this is all very clear now, and the docs are quite helpful too ( > https://docs.djangoproject.com/en/dev/topics/i18n/translation/#using-translations-outside-views-and-templates > ). > But now I wonder what is the best way to implement that? > I mean in my case I use Django to automatically discover the user's > preferred language according to the browser preferences and if it fails > there is also a button to choose the language. I can link that button to a > field in the user profile model to remember what language they set for > later use with translation.activate. But in case Django displays the right > language for the user automatically that field will remain empty and that > would be pretty counter intuitive for the user to set their preferred > language with a button when it is already displayed correctly. What would > be the right thing to do in that case? Is there a way to retrieve the > latest language used in the user session? Or something similar? Thanks! > > > > On Friday, October 5, 2012 12:19:38 PM UTC+2, Tom Evans wrote: > >> On Fri, Oct 5, 2012 at 10:12 AM, Bastian wrote: >> > Hi, >> > >> > I understand quite well how translations and i18n work inside a browser >> for >> > Django but I'm not sure about the correct way to do it outside a >> browser. I >> > mean when sending a mail or a tweet. What should I use to get the >> language >> > of the user that is going to receive the mail or in case of a tweet the >> > language of the user that I will send it on behalf of. And then how do >> I ask >> > Django to translate that? >> > I could not find it in the docs, if it exists please point me to it. >> > >> > Cheers >> > >> >> You will need to have a mechanism for storing what the user's chosen >> language is. Once you have that, simply do this: >> >> from django.utils import translation >> >> cur_language = translation.get_language() >> translation.activate(get_lang_**for_user(user)) >> # send email, tweet, etc >> translation.activate(cur_**language) >> >> You would need to define the 'get_lang_for_user' function. >> >> Cheers >> >> Tom >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/0MvHhF60bBIJ. > > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- * GlxGuru * -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Translation outside the broswer
Ok this is all very clear now, and the docs are quite helpful too (https://docs.djangoproject.com/en/dev/topics/i18n/translation/#using-translations-outside-views-and-templates). But now I wonder what is the best way to implement that? I mean in my case I use Django to automatically discover the user's preferred language according to the browser preferences and if it fails there is also a button to choose the language. I can link that button to a field in the user profile model to remember what language they set for later use with translation.activate. But in case Django displays the right language for the user automatically that field will remain empty and that would be pretty counter intuitive for the user to set their preferred language with a button when it is already displayed correctly. What would be the right thing to do in that case? Is there a way to retrieve the latest language used in the user session? Or something similar? Thanks! On Friday, October 5, 2012 12:19:38 PM UTC+2, Tom Evans wrote: > > On Fri, Oct 5, 2012 at 10:12 AM, Bastian > > wrote: > > Hi, > > > > I understand quite well how translations and i18n work inside a browser > for > > Django but I'm not sure about the correct way to do it outside a > browser. I > > mean when sending a mail or a tweet. What should I use to get the > language > > of the user that is going to receive the mail or in case of a tweet the > > language of the user that I will send it on behalf of. And then how do I > ask > > Django to translate that? > > I could not find it in the docs, if it exists please point me to it. > > > > Cheers > > > > You will need to have a mechanism for storing what the user's chosen > language is. Once you have that, simply do this: > > from django.utils import translation > > cur_language = translation.get_language() > translation.activate(get_lang_for_user(user)) > # send email, tweet, etc > translation.activate(cur_language) > > You would need to define the 'get_lang_for_user' function. > > Cheers > > Tom > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/0MvHhF60bBIJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Translation outside the broswer
Yeah, i18n works anywhere just put _(message) to send a mail. * * *cheers * On Fri, Oct 5, 2012 at 10:16 PM, Bastian wrote: > Thanks Tom, the logic seems pretty clear. I just didn't know about > translation.activate. What does it do exactly? Change the current language? > Anyway I will do my homework and google it and read the code... > > Cheers. > > > On Friday, October 5, 2012 12:19:38 PM UTC+2, Tom Evans wrote: > >> On Fri, Oct 5, 2012 at 10:12 AM, Bastian wrote: >> > Hi, >> > >> > I understand quite well how translations and i18n work inside a browser >> for >> > Django but I'm not sure about the correct way to do it outside a >> browser. I >> > mean when sending a mail or a tweet. What should I use to get the >> language >> > of the user that is going to receive the mail or in case of a tweet the >> > language of the user that I will send it on behalf of. And then how do >> I ask >> > Django to translate that? >> > I could not find it in the docs, if it exists please point me to it. >> > >> > Cheers >> > >> >> You will need to have a mechanism for storing what the user's chosen >> language is. Once you have that, simply do this: >> >> from django.utils import translation >> >> cur_language = translation.get_language() >> translation.activate(get_lang_**for_user(user)) >> # send email, tweet, etc >> translation.activate(cur_**language) >> >> You would need to define the 'get_lang_for_user' function. >> >> Cheers >> >> Tom >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/UWQFiq5SddQJ. > > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- * GlxGuru * -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Translation outside the broswer
Thanks Tom, the logic seems pretty clear. I just didn't know about translation.activate. What does it do exactly? Change the current language? Anyway I will do my homework and google it and read the code... Cheers. On Friday, October 5, 2012 12:19:38 PM UTC+2, Tom Evans wrote: > > On Fri, Oct 5, 2012 at 10:12 AM, Bastian > > wrote: > > Hi, > > > > I understand quite well how translations and i18n work inside a browser > for > > Django but I'm not sure about the correct way to do it outside a > browser. I > > mean when sending a mail or a tweet. What should I use to get the > language > > of the user that is going to receive the mail or in case of a tweet the > > language of the user that I will send it on behalf of. And then how do I > ask > > Django to translate that? > > I could not find it in the docs, if it exists please point me to it. > > > > Cheers > > > > You will need to have a mechanism for storing what the user's chosen > language is. Once you have that, simply do this: > > from django.utils import translation > > cur_language = translation.get_language() > translation.activate(get_lang_for_user(user)) > # send email, tweet, etc > translation.activate(cur_language) > > You would need to define the 'get_lang_for_user' function. > > Cheers > > Tom > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/UWQFiq5SddQJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Translation outside the broswer
On Fri, Oct 5, 2012 at 10:12 AM, Bastian wrote: > Hi, > > I understand quite well how translations and i18n work inside a browser for > Django but I'm not sure about the correct way to do it outside a browser. I > mean when sending a mail or a tweet. What should I use to get the language > of the user that is going to receive the mail or in case of a tweet the > language of the user that I will send it on behalf of. And then how do I ask > Django to translate that? > I could not find it in the docs, if it exists please point me to it. > > Cheers > You will need to have a mechanism for storing what the user's chosen language is. Once you have that, simply do this: from django.utils import translation cur_language = translation.get_language() translation.activate(get_lang_for_user(user)) # send email, tweet, etc translation.activate(cur_language) You would need to define the 'get_lang_for_user' function. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Translation outside the broswer
I believe that when you detect the language you could store in the user profile the selected language (either it was automatic or manual), when sending your email just check that On Fri, Oct 5, 2012 at 11:12 AM, Bastian wrote: > Hi, > > I understand quite well how translations and i18n work inside a browser > for Django but I'm not sure about the correct way to do it outside a > browser. I mean when sending a mail or a tweet. What should I use to get > the language of the user that is going to receive the mail or in case of a > tweet the language of the user that I will send it on behalf of. And then > how do I ask Django to translate that? > I could not find it in the docs, if it exists please point me to it. > > Cheers > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/ikoUTSyxuykJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Translation outside the broswer
Hi, I understand quite well how translations and i18n work inside a browser for Django but I'm not sure about the correct way to do it outside a browser. I mean when sending a mail or a tweet. What should I use to get the language of the user that is going to receive the mail or in case of a tweet the language of the user that I will send it on behalf of. And then how do I ask Django to translate that? I could not find it in the docs, if it exists please point me to it. Cheers -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/ikoUTSyxuykJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.