如何在sencha touch 2中根据浏览器语言选择文件?我的项目下有 3 个文件 app_de.js、app_en-US.js 和 app_es.js。我正在查找浏览器语言并像这样加载文件:
<script type="text/javascript" id="extlocale">
var browserLang = window.navigator.language; // get the browsers language
alert(browserLang);
var locale = 'en'; // default locale
if(browserLang == 'de' || browserLang == 'de-de') //called when the language is german
{
locale = 'de';
}
else if(browserLang == 'en-US' || browserLang == 'en-us' || browserLang == 'en')
{
locale = 'en-US'; //called when the language is english
}
else if(browserLang == 'es' || browserLang == 'es-es' )
{
locale = 'es'; //called when the language is spanish
}
else
{
console.log("Invalid language");
locale = 'en-US';
}
if(locale) {
Ext.fly('extlocale').set({src:'app_'+locale+'.js'});
}
</script>
如果我以这种方式包含文件,这些文件将单独工作:
<script type="text/javascript" src="app_en-US.js"></script>
请让我知道如何根据浏览器的语言加载文件?