How can I get the current language in the current thread in a model or in the admin?
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.
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 .
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.
{% %} 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.
Functions of particular interest are django.utils.translation.get_language()
which returns the language used in the current thread. See documentation.
Or you can also get this in your views
request.LANGUAGE_CODE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With