2👍
Probably you need to quote the strings you’re comparing to, for example:
language_code_value == ru
should be
language_code_value == "ru"
otherwise the comparison will be looking for a variable named ru
to compare to.
There are a few additional issues to address in making this conversion:
-
Having an
if
condition test for every language you’ll want to deal with is quickly going to become unwieldy and error prone. -
This mapping is taking a language code
ru
and mapping to a code representing and language and a countryru_RU
. This involves making an assumption that somebody speaking a certain language is in a certain country, which is not generally correct. Many languages are spoken in multiple countries with different conventions in each.
It might be worth your while to dig a little deeper to find a better way of doing this. This will likely result in less effort and a more correct solution.
I’m sorry, I don’t know Django so I can’t point you in the right direction, but you might want to explore whether it, or a third party package, can return you the correct IETF language tag directly.
Edit
You’re also going to have problems with:
var language_code_value = "{{ user.get_profile.language_preference }}";
language_code_value
is going to have the literal string value {{ user.get_profile.language_preference }}
which is never going to compare equal to the two digit language codes you want to compare it to.
- [Answered ]-How do I modify a model field and then send it using the Rest Framework in Python/Django?
- [Answered ]-Add delimiter to a url, to extract different values
- [Answered ]-Logout not working Django 1.9