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 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.
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 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.
Share Improve this question edited Mar 15, 2013 at 18:03 ThinkingStiff 65.4k30 gold badges147 silver badges241 bronze badges asked Oct 12, 2011 at 7:45 Logesh PaulLogesh Paul 7,7003 gold badges28 silver badges23 bronze badges 3-
possible duplicate of JavaScript for detecting browser language preference - seems a rather plex problem. Once you have the language code, redirecting is trivial using
location.href
– Pekka Commented Oct 12, 2011 at 7:47 - @pekka thanks for your reply. I'm not targeting desktop browsers because its a mobile only site. I'm trying to detect the language of mobile browser is there any useful information you can help with? – Logesh Paul Commented Oct 12, 2011 at 9:43
- 2 What does detecting the language have to do with mobile vs. desktop? The solutions presented in the duplicate should work in both worlds. Do they not? – Pekka Commented Oct 12, 2011 at 12:18
2 Answers
Reset to default 5You 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./' + 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.