I have some code that I can not get my head around. The more I look at it the more confused I become.
There are two date values and a language code that is passed into a js function. Then there is a django collection (I think!) that interacts with the django language tag to assign the correct values.
I thought I had set this up correctly, but the code is not working and I cannot see the reason for it as my experience is not good enough to see where I have gone wrong.
The error occurs when I try to call the names.month (as shown on the last line), so I think I have made an error in the name_map code or in the assignment of the variables of lc and LANGUAGE_CODES.
The passed in values are:
date1: 10/2000;
date2: 12/2004;
dynamic_language_code: de;
Any suggestions would be great.
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.
var a = date1;
var b = date2;
var lc = dynamic_language_code;
var LANGUAGE_CODES = 'ar, zh-CN, zh-TW, en-GB, en, fr, fr-CA, de, it, pl, pt, pt-BR, ru, es-419, es';
var name_map = {
{% for lc in LANGUAGE_CODES %}
{{ lc }}: {
month: "{% language lc %}{% trans 'month' %}{% endlanguage %}",
months: "{% language lc %}{% trans 'months' %}{% endlanguage %}",
year: "{% language lc %}{% trans 'year' %}{% endlanguage %}",
years: "{% language lc %}{% trans 'years' %}{% endlanguage %}"
} {% if not forloop.last %},{% endif %}
{% endfor %}
}
names = name_map[lc];
if(names === undefined) { names = name_map['en']; }
....
time_span = total_months + " " + names.month;
....