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

时间:2023-01-30 00:08:32

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 ? 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 ??

有没有办法检测用户的语言(在iPhone网络应用程序上),而不是使用ip或gps位置?我知道当你去火鸡的时候非常烦人,而你的应用程序是土耳其的...所以...我怎样才能真正检测到系统的语言?

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

谢谢

1 个解决方案

#1


4  

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; like 'en_US.js' for English (US) and 'nl_NL.js' for Dutch. That would make things easier when using window.navigator.language:

我建议您使用ISO语言标准来命名您的文件;比如英语(美国)的'en_US.js'和荷兰的'nl_NL.js'。这将使使用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'文件是否存在。

#1


4  

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; like 'en_US.js' for English (US) and 'nl_NL.js' for Dutch. That would make things easier when using window.navigator.language:

我建议您使用ISO语言标准来命名您的文件;比如英语(美国)的'en_US.js'和荷兰的'nl_NL.js'。这将使使用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'文件是否存在。