Re: Set language on per page basis
Thanks a lot, this seems to work like a charm. On Feb 25, 10:45 am, Ian Lewiswrote: > In process_request you have access to the request object which knows > the current path (request.path). You can use that to determine which > language to show the page in. > > Or if you are determining the language based on a url parameter you > can look at request.GET > > Ian > > > > On Thu, Feb 25, 2010 at 8:24 AM, Tor Nordam wrote: > > After doing some further research, I have found the following: > > > By writing a small piece of custom middleware, I can change the value > > of HTTP_ACCEPT_LANGUAGE. If I add this line to a process_request() > > > request.META['HTTP_ACCEPT_LANGUAGE'] = 'no' > > > then the webpage will be displayed with Norwegian translation. > > However, I want to set the language based on which page the user is > > trying to view, and process_request() doesn't know this. On the other > > hand, if I use process_view(), I am able to determine what the > > language should be, as process_view() gets passed for example the > > arguments from the url. However, when I add the same line as above to > > process_view(), nothing happens to the language. > > > Is there an easy way to do this? > > > On Feb 24, 9:59 pm, Tor Nordam wrote: > >> Thank you for your reply, > > >> Using the {% trans %} method is indeed what I intend to do. But the > >> problem is how to set the language on a page basis, rather than as an > >> installation-wide setting, or a user-selectable setting. > > >> On Feb 24, 6:55 pm, Timothy Kinney wrote: > > >> > I believe you want to use the {% *trans* %} template > >> > method.http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/ > > >> > -Tim > > >> > On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordam wrote: > >> > > I'm currently developing a project for making course webpages at my > >> > > university. Essentially, each course would be an instance of the model > >> > > Course, and each course would then get it's own webpage. However, as > >> > > some courses are taught in Norwegian, and some in English, I want to > >> > > use django's internationalisation framework, and I want to be able to > >> > > set the language for each course separately. So I want to use > >> > > different languages, but I don't want the person viewing the webpage > >> > > to be able to select the language himself. > > >> > > As far as I can tell, the standard ways to set the language is either > >> > > to use one setting for you entire project, or to select language based > >> > > on the end users preferences. Is there an easy way to do what I want? > > >> > > -- > >> > > You received this message because you are subscribed to the Google > >> > > Groups > >> > > "Django users" group. > >> > > To post to this group, send email to django-us...@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-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > === > 株式会社ビープラウド イアン・ルイス > 〒150-0012 > 東京都渋谷区広尾1-11-2アイオス広尾ビル604 > email: ianmle...@beproud.jp > TEL:03-5795-2707 > FAX:03-5795-2708http://www.beproud.jp/ > === -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Set language on per page basis
On Wed, Feb 24, 2010 at 8:59 PM, Tor Nordamwrote: > Thank you for your reply, > > Using the {% trans %} method is indeed what I intend to do. But the > problem is how to set the language on a page basis, rather than as an > installation-wide setting, or a user-selectable setting. > Just do what django.middleware.locale.LocaleMiddleware does (Use the source, Luke): Activate the required language (django.utils.translation.activate). Set request.LANGUAGE_CODE to the required language. Set the header 'Content-Language' on the response. If the page contents vary upon the requested language, set/update the 'Vary' header on the response to include 'Accept-Language', but sounds as though your pages are in one specific language. Deactivate the translation after you're done with it. 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-us...@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: Set language on per page basis
BTW: django-cms does something similar to what you are trying to do. You can check out it's implementation here: http://github.com/digi604/django-cms-2.0/blob/master/cms/middleware/multilingual.py 2010/2/25 Ian Lewis: > In process_request you have access to the request object which knows > the current path (request.path). You can use that to determine which > language to show the page in. > > Or if you are determining the language based on a url parameter you > can look at request.GET > > Ian > > On Thu, Feb 25, 2010 at 8:24 AM, Tor Nordam wrote: >> After doing some further research, I have found the following: >> >> By writing a small piece of custom middleware, I can change the value >> of HTTP_ACCEPT_LANGUAGE. If I add this line to a process_request() >> >> request.META['HTTP_ACCEPT_LANGUAGE'] = 'no' >> >> then the webpage will be displayed with Norwegian translation. >> However, I want to set the language based on which page the user is >> trying to view, and process_request() doesn't know this. On the other >> hand, if I use process_view(), I am able to determine what the >> language should be, as process_view() gets passed for example the >> arguments from the url. However, when I add the same line as above to >> process_view(), nothing happens to the language. >> >> Is there an easy way to do this? >> >> On Feb 24, 9:59 pm, Tor Nordam wrote: >>> Thank you for your reply, >>> >>> Using the {% trans %} method is indeed what I intend to do. But the >>> problem is how to set the language on a page basis, rather than as an >>> installation-wide setting, or a user-selectable setting. >>> >>> On Feb 24, 6:55 pm, Timothy Kinney wrote: >>> >>> > I believe you want to use the {% *trans* %} template >>> > method.http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/ >>> >>> > -Tim >>> >>> > On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordam wrote: >>> > > I'm currently developing a project for making course webpages at my >>> > > university. Essentially, each course would be an instance of the model >>> > > Course, and each course would then get it's own webpage. However, as >>> > > some courses are taught in Norwegian, and some in English, I want to >>> > > use django's internationalisation framework, and I want to be able to >>> > > set the language for each course separately. So I want to use >>> > > different languages, but I don't want the person viewing the webpage >>> > > to be able to select the language himself. >>> >>> > > As far as I can tell, the standard ways to set the language is either >>> > > to use one setting for you entire project, or to select language based >>> > > on the end users preferences. Is there an easy way to do what I want? >>> >>> > > -- >>> > > You received this message because you are subscribed to the Google >>> > > Groups >>> > > "Django users" group. >>> > > To post to this group, send email to django-us...@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-us...@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. >> >> > > > > -- > === > 株式会社ビープラウド イアン・ルイス > 〒150-0012 > 東京都渋谷区広尾1-11-2アイオス広尾ビル604 > email: ianmle...@beproud.jp > TEL:03-5795-2707 > FAX:03-5795-2708 > http://www.beproud.jp/ > === > -- === 株式会社ビープラウド イアン・ルイス 〒150-0012 東京都渋谷区広尾1-11-2アイオス広尾ビル604 email: ianmle...@beproud.jp TEL:03-5795-2707 FAX:03-5795-2708 http://www.beproud.jp/ === -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Set language on per page basis
In process_request you have access to the request object which knows the current path (request.path). You can use that to determine which language to show the page in. Or if you are determining the language based on a url parameter you can look at request.GET Ian On Thu, Feb 25, 2010 at 8:24 AM, Tor Nordamwrote: > After doing some further research, I have found the following: > > By writing a small piece of custom middleware, I can change the value > of HTTP_ACCEPT_LANGUAGE. If I add this line to a process_request() > > request.META['HTTP_ACCEPT_LANGUAGE'] = 'no' > > then the webpage will be displayed with Norwegian translation. > However, I want to set the language based on which page the user is > trying to view, and process_request() doesn't know this. On the other > hand, if I use process_view(), I am able to determine what the > language should be, as process_view() gets passed for example the > arguments from the url. However, when I add the same line as above to > process_view(), nothing happens to the language. > > Is there an easy way to do this? > > On Feb 24, 9:59 pm, Tor Nordam wrote: >> Thank you for your reply, >> >> Using the {% trans %} method is indeed what I intend to do. But the >> problem is how to set the language on a page basis, rather than as an >> installation-wide setting, or a user-selectable setting. >> >> On Feb 24, 6:55 pm, Timothy Kinney wrote: >> >> > I believe you want to use the {% *trans* %} template >> > method.http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/ >> >> > -Tim >> >> > On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordam wrote: >> > > I'm currently developing a project for making course webpages at my >> > > university. Essentially, each course would be an instance of the model >> > > Course, and each course would then get it's own webpage. However, as >> > > some courses are taught in Norwegian, and some in English, I want to >> > > use django's internationalisation framework, and I want to be able to >> > > set the language for each course separately. So I want to use >> > > different languages, but I don't want the person viewing the webpage >> > > to be able to select the language himself. >> >> > > As far as I can tell, the standard ways to set the language is either >> > > to use one setting for you entire project, or to select language based >> > > on the end users preferences. Is there an easy way to do what I want? >> >> > > -- >> > > You received this message because you are subscribed to the Google Groups >> > > "Django users" group. >> > > To post to this group, send email to django-us...@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-us...@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. > > -- === 株式会社ビープラウド イアン・ルイス 〒150-0012 東京都渋谷区広尾1-11-2アイオス広尾ビル604 email: ianmle...@beproud.jp TEL:03-5795-2707 FAX:03-5795-2708 http://www.beproud.jp/ === -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Set language on per page basis
After doing some further research, I have found the following: By writing a small piece of custom middleware, I can change the value of HTTP_ACCEPT_LANGUAGE. If I add this line to a process_request() request.META['HTTP_ACCEPT_LANGUAGE'] = 'no' then the webpage will be displayed with Norwegian translation. However, I want to set the language based on which page the user is trying to view, and process_request() doesn't know this. On the other hand, if I use process_view(), I am able to determine what the language should be, as process_view() gets passed for example the arguments from the url. However, when I add the same line as above to process_view(), nothing happens to the language. Is there an easy way to do this? On Feb 24, 9:59 pm, Tor Nordamwrote: > Thank you for your reply, > > Using the {% trans %} method is indeed what I intend to do. But the > problem is how to set the language on a page basis, rather than as an > installation-wide setting, or a user-selectable setting. > > On Feb 24, 6:55 pm, Timothy Kinney wrote: > > > I believe you want to use the {% *trans* %} template > > method.http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/ > > > -Tim > > > On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordam wrote: > > > I'm currently developing a project for making course webpages at my > > > university. Essentially, each course would be an instance of the model > > > Course, and each course would then get it's own webpage. However, as > > > some courses are taught in Norwegian, and some in English, I want to > > > use django's internationalisation framework, and I want to be able to > > > set the language for each course separately. So I want to use > > > different languages, but I don't want the person viewing the webpage > > > to be able to select the language himself. > > > > As far as I can tell, the standard ways to set the language is either > > > to use one setting for you entire project, or to select language based > > > on the end users preferences. Is there an easy way to do what I want? > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to django-us...@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-us...@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: Set language on per page basis
Thank you for your reply, Using the {% trans %} method is indeed what I intend to do. But the problem is how to set the language on a page basis, rather than as an installation-wide setting, or a user-selectable setting. On Feb 24, 6:55 pm, Timothy Kinneywrote: > I believe you want to use the {% *trans* %} template > method.http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/ > > -Tim > > On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordam wrote: > > I'm currently developing a project for making course webpages at my > > university. Essentially, each course would be an instance of the model > > Course, and each course would then get it's own webpage. However, as > > some courses are taught in Norwegian, and some in English, I want to > > use django's internationalisation framework, and I want to be able to > > set the language for each course separately. So I want to use > > different languages, but I don't want the person viewing the webpage > > to be able to select the language himself. > > > As far as I can tell, the standard ways to set the language is either > > to use one setting for you entire project, or to select language based > > on the end users preferences. Is there an easy way to do what I want? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@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-us...@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: Set language on per page basis
I believe you want to use the {% *trans* %} template method. http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/ -Tim On Wed, Feb 24, 2010 at 7:18 AM, Tor Nordamwrote: > I'm currently developing a project for making course webpages at my > university. Essentially, each course would be an instance of the model > Course, and each course would then get it's own webpage. However, as > some courses are taught in Norwegian, and some in English, I want to > use django's internationalisation framework, and I want to be able to > set the language for each course separately. So I want to use > different languages, but I don't want the person viewing the webpage > to be able to select the language himself. > > As far as I can tell, the standard ways to set the language is either > to use one setting for you entire project, or to select language based > on the end users preferences. Is there an easy way to do what I want? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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-us...@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.
Set language on per page basis
I'm currently developing a project for making course webpages at my university. Essentially, each course would be an instance of the model Course, and each course would then get it's own webpage. However, as some courses are taught in Norwegian, and some in English, I want to use django's internationalisation framework, and I want to be able to set the language for each course separately. So I want to use different languages, but I don't want the person viewing the webpage to be able to select the language himself. As far as I can tell, the standard ways to set the language is either to use one setting for you entire project, or to select language based on the end users preferences. Is there an easy way to do what I want? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.