Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the current language in Django?

How can I get the current language in the current thread in a model or in the admin?

like image 493
diegueus9 Avatar asked Jul 28 '10 20:07

diegueus9


People also ask

How do I change the default language in Django?

If you use {% url web-language 'nl-nl' %} like this 'nl-nl' is in your args ( args[0] ), not in your kwargs . For kwargs you should use syntax like {% url web-language language='nl-nl' %} . Then your view should work.

What is Django language code?

language code. Represents the name of a language. Browsers send the names of the languages they accept in the Accept-Language HTTP header using this format. Examples: it , de-at , es , pt-br .

What is Gettext_lazy in Django?

gettext_lazy() In definitions like forms or models you should use gettext_lazy because the code of this definitions is only executed once (mostly on django's startup); gettext_lazy translates the strings in a lazy fashion, which means, eg.

What does {% %} mean in Django?

{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.


2 Answers

Functions of particular interest are django.utils.translation.get_language() which returns the language used in the current thread. See documentation.

like image 165
micha480 Avatar answered Sep 26 '22 12:09

micha480


Or you can also get this in your views

request.LANGUAGE_CODE
like image 34
Ignas Butėnas Avatar answered Sep 23 '22 12:09

Ignas Butėnas