![]() In this example I moved the Finnish language on top:Ĭomment out the language setting code and clear the cookie: class HomePageView ( TemplateView ): In Chrome you can change the preferred language in here: chrome://settings/?search=language. The Accept-Language header is sent by the browser. Response = render (request, 'pages/home.html' )Īdd it to pages app URLs: from django. You can do this with function-based views: def home (request): Our custom code overrides all other behaviours. Now the language for the home page will always be Finnish. t_cookie() makes the preference persistent.translation.activate() changes the language for the current thread.render_to_response (context, ** response_kwargs) generic import TemplateViewĭef render_to_response (self, context, ** response_kwargs): Edit the pages app views.py file and add a render_to_response method to it: from django. Here is an example on how to set up the cookie manually. The get_current_language tag returns the current language.QuickstartĪdd LOCALE_PATHS setting to the project settings file and change the default language: LOCALE_PATHS = Įdit a template file, load the i18n tag and use the trans tag to translate a string: We explore several ways to determine user's language preference, translate URLs and add a language switcher. This tutorial shows how to translate texts in templates, code and database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |