简体   繁体   English

如何检测语言iPhone网络应用程序?

[英]How to detect language iPhone web app?

Is there a way to detect the language of your users (on an iPhone web app), but not by using the ip or the gps location ? 有没有办法检测用户的语言(在iPhone网络应用程序上),而不是使用ip或gps位置? I know it's very annoying when you go for example to turkey, and you're apps are in turkish… So… How can i really detect the language of the system ?? 我知道当你去土耳其的时候非常烦人,你的应用程序是土耳其人......所以...我怎样才能真正检测到系统的语言?

Is it possible in javascript ? 在javascript中有可能吗?

I should want if it's english, the web app uses eng.js for dutch dut.js and further… 我应该想要,如果它是英文,网络应用程序使用eng.js为荷兰dut.js进一步...

Thanks 谢谢

I suppose you can do a window.navigator.language in Javascript. 我想你可以用Javascript做一个window.navigator.language

I suggest you name your files by using the ISO standard for languages; 我建议你使用ISO语言标准来命名你的文件; like 'en_US.js' for English (US) and 'nl_NL.js' for Dutch. 比如英语(美国)的'en_US.js'和荷兰的'nl_NL.js'。 That would make things easier when using window.navigator.language : 这将使使用window.navigator.language时更容易:

(function(){
    var s = document.getElementsByTagName('script')[0];
    var lang = document.createElement('script');

    lang.type = 'text/javascript';
    lang.async = true;
    lang.src = '/languages/' + window.navigator.language + '.js';

    s.parentNode.insertBefore(lang,s);
})();

You should however do a check if the 'window.navigator.language.js'-file exists or not. 但是,您应该检查'window.navigator.language.js'文件是否存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM