我有一些我无法理解的代码。我越看越困惑。
有两个日期值和一个语言代码传递到 js 函数中。然后有一个 django 集合(我认为!),它与 django 语言标签交互以分配正确的值。
我以为我已经正确设置了它,但是代码不起作用,我看不出它的原因,因为我的经验不足以看出我哪里出错了。
当我尝试调用names.month时出现错误(如最后一行所示),所以我认为我在name_map代码或lc和LANGUAGE_CODES的变量分配中出错。
传入的值是:
日期1:10/2000;
日期2:12/2004;
动态语言代码:de;
任何建议都会很棒。
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;
....