开发者

Detecting the language used by mobile device and auto-switch website to that corresponding language

开发者 https://www.devze.com 2023-04-12 05:12 出处:网络
Is it possible to detect the language which is used by the mobile phone to auto switch my mobile site to that corresponding language?

Is it possible to detect the language which is used by the mobile phone to auto switch my mobile site to that corresponding language?

Say for example, My website should display in english to peoples who have english as their language in mobile, similarly开发者_StackOverflow社区 for user who have french they should view the site in french.

I have developed the mobile site with jQueryMobile. Its just a static site with HTML & some Js calculations that's all.


You can detect the users language like this:

  var l_lang;
  if (navigator.userLanguage) // Explorer
    l_lang = navigator.userLanguage;
  else if (navigator.language) // FF
    l_lang = navigator.language;
  else
    l_lang = "en";

Then go to the language specific page:

  location.href = 'www.yourpage.com/' + l_lang + '.html';


I believe you can not do this with JS.

One of the option is to parse request's "Accept-Laguage", but do this with caution, cause there is could be several with different priority set. This can be done as with some server-side script as well as with apache's config.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号