I have some javascript that displays the timespan between two dates according to a language code. For example in en / English: (3 years, 2 months) , in ru / Russian (3 лет, 2 месяцев) in de / German: (3 Jahre, 2 Monate) , etc.
The code is working ok but will be difficult to maintain, so I have tried to pass in a dynamic variable to change the language display but it does not work, and I am not sure why and I am unsure how to get it working, despite trying for several days now. Here is the relevant section of the working code, that will be difficult to maintain if more language codes are added to the site: function dateCalculation(date1, date2, dynamic_language_code) { //this function will accept two dates (format: mm/yyyy) and calculate the difference between the 2 dates //and display the difference as x months or x years, x months. //arabic if (dynamic_language_code == 'ar'){ var_month = "{% language 'ar' %}{% trans 'month' %}{% endlanguage %}"; var_months = "{% language 'ar' %}{% trans 'months' %}{% endlanguage %}"; var_year = "{% language 'ar' %}{% trans 'year' %}{% endlanguage %}"; var_years = "{% language 'ar' %}{% trans 'years' %}{% endlanguage %}"; } else if (dynamic_language_code == 'bg'){ //bulgaian var_month = "{% language 'bg' %}{% trans 'month' %}{% endlanguage %}"; var_months = "{% language 'bg' %}{% trans 'months' %}{% endlanguage %}"; var_year = "{% language 'bg' %}{% trans 'year' %}{% endlanguage %}"; var_years = "{% language 'bg' %}{% trans 'years' %}{% endlanguage %}"; } else if (dynamic_language_code == 'zh-CN'){ //chinese (simplified) var_month = "{% language 'zh' %}{% trans 'month' %}{% endlanguage %}"; var_months = "{% language 'zh' %}{% trans 'months' %}{% endlanguage %}"; var_year = "{% language 'zh' %}{% trans 'year' %}{% endlanguage %}"; var_years = "{% language 'zh' %}{% trans 'years' %}{% endlanguage %}"; } ...... more conditions & remainder of code not important for this question. ...... The above variables take the form of: *date1: 01/2009* *date2: 03/2012* *dynamic_language_code: tr (a two letter language code)* Here is the code with the passed in variables that I cannot get to work: var_month = "{% language dynamic_language_code %}{% trans 'month' %}{% endlanguage %}"; var_months = "{% language dynamic_language_code %}{% trans 'months' %}{% endlanguage %}"; var_year = "{% language dynamic_language_code %}{% trans 'year' %}{% endlanguage %}"; var_years = "{% language dynamic_language_code %}{% trans 'years' %}{% endlanguage %}"; *How would I get the django language tag to work if I am passing in the dynamic_language_code variable as show immediately above?* I think the error is to do with the django language tag not recognising the dynamic_langauge_code when it is not in quotes (''), but I could be wrong. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2bf13bdc-6934-4b5c-80b9-a16a40dc82d1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.