www.webdeveloper.com
Results 1 to 8 of 8

Thread: Select language based on OS

  1. #1
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    5

    Select language based on OS

    Hello,

    here's the situation..
    I'm trying to find a way to read the OS language so that I can set the language on my webpage. I've searched the web for such method but haven't been able to find one. Is there anyone who can tell how to do this.

    Thanks in advance!

  2. #2
    Join Date
    Aug 2009
    Posts
    2
    The following code can be used to detect OS

    var OSName="Unknown OS";
    if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
    if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
    if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
    if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

    document.write('Your OS: '+OSName);

  3. #3
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    5
    Hello kmatheeswar,

    thanks for your reply on my post. You don't happen to know how to retrieve the language used on the OS...? Because that's what I need to find out.

  4. #4
    Join Date
    Oct 2007
    Location
    Sweden
    Posts
    225
    You can get the browser language through this:
    Code:
    <script type="text/javascript">
        var lang = navigator.browserLanguage;
        alert("Browser language: "+lang)
    </script>
    I don't know how to get it from the OS though, sorry.

  5. #5
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    5
    Hey,

    thanks you very much!
    I'll try it and let you guys know when it works. Probably not within a few minutes, but a.s.a.p.

  6. #6
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    in FF3, navigator.language == "en-US" for me, but navigator.browserLanguage is empty...

  7. #7
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    5
    Quote Originally Posted by rnd me View Post
    in FF3, navigator.language == "en-US" for me, but navigator.browserLanguage is empty...
    Hi rnd me,

    interesting fact you've got there. I've tried both options and this is my result.
    In case of FF3 I'd have to use your option
    Code:
    navigator.language
    .

    In case of IE I'd have to use Quidam's version
    Code:
    navigator.browserLanguage
    So all I have to do is combine those two options with kmatheeswar's input. Modify it so that it gets the browser type and voila.
    Retrieve the browser type en based on that result retrieve the language


    Thanks.
    Last edited by Menno; 08-20-2009 at 03:19 AM.

  8. #8
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    5
    Quote Originally Posted by Quidam View Post
    You can get the browser language through this:
    Code:
    <script type="text/javascript">
        var lang = navigator.browserLanguage;
        alert("Browser language: "+lang)
    </script>
    I don't know how to get it from the OS though, sorry.

    Hi guys,

    I've found a way to retrieve the OS language.
    Code:
    navigator.systemLanguage
    Returns the default language of the operating system (ie: en-us). IE only.
    I've chosen to go for the browser lang option but for those who read this thread...

    Thanks all!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles