用荷兰语显示明天和第二天的明天?

时间:2017-06-28 11:28:53

标签: javascript

我目前正在使用simpleWeather.js在我的个人网站上显示简单的天气预报。它工作得很好,但我遇到了一个简单的问题。

目前,它以英语输出预测,例如:

  • THU:22°C
  • FRI:26°C
  • SAT:23°C

然而,不是显示“THU:”而是希望它显示“Donderdag:”。 一周剩下的几天显然是相同的结果。

我知道有一个工作代码示例,所以我在这里创建了一个:

https://codepen.io/anon/pen/Moreab

$(document).ready(function() {
  $.simpleWeather({
  location: 'Austin, TX',
  woeid: '',
  unit: 'c',
  success: function(weather) {

  html = '<p>'+weather.forecast[1].day+': <i class="weerklein icon-'+weather.forecast[1].code+'"></i> min. '+weather.forecast[1].low+' max. '+weather.forecast[1].high+'</p>';
  html += '<p>'+weather.forecast[2].day+': <i class="weerklein icon-'+weather.forecast[2].code+'"></i> min. '+weather.forecast[2].low+' max. '+weather.forecast[2].high+'</p>';
  html += '<p>'+weather.forecast[3].day+': <i class="weerklein icon-'+weather.forecast[3].code+'"></i> min. '+weather.forecast[3].low+' max. '+weather.forecast[3].high+'</p>';
  html += '<p>'+weather.forecast[4].day+': <i class="weerklein icon-'+weather.forecast[4].code+'"></i> min. '+weather.forecast[4].low+' max. '+weather.forecast[4].high+'</p>';

  $("#weather").html(html);
},
error: function(error) {
  $("#weather").html('<p>'+error+'</p>');
}
});
});

它看起来很难看,但它显示了我的意思。如你所见,它显示了THU:FRI:SAT:等等......

我希望将这些改为荷兰亲戚。 有人能告诉我如何实现这一目标吗? TY。

1 个答案:

答案 0 :(得分:2)

您可以使用对象将英文名称翻译为荷兰语:

var day_to_dutch = {
    Mon: 'Maandag',
    Tue: 'Dinsdag',
    Wed: 'Woensdag',
    Thu: 'Donderdag',
    Fri: 'Vrijdag',
    Sat: 'Zaterdag',
    Sun: 'Zondag'
};

翻译可按如下方式进行:

day_to_dutch[weather.forecast[1].day]