3

How can I determine Language Switching (pressing alt+shift on keyboard) using Jquery when typing in a text box?

I'd like to find the new language!

EDIT:

I can use javascript too for all browsers for all operating systems

3
  • I assume windows? I think it depends on the browser if they follow the Windows-langueage switch.. Commented Jun 14, 2012 at 16:07
  • @MoonLight: does it have to be jQuery, or will JavaScript do? Commented Jun 14, 2012 at 16:12
  • 2
    I may be wrong, but that's an operating system event, and I don't think the browser (or at least javascript) will know about it. Commented Jun 14, 2012 at 16:29

1 Answer 1

4

Short Answer: No, you can't determine it.

Long Answer:

There is no cross-browser way to detect the user language, even more detecting a changed to it.

Internet explorer has some methods to give you such information (Using Client Capabilities):


That I know of, these are not available for other browsers, thus relying on:


According with the Browser compatibility Table from the MDN, this should be available on all modern browser versions:

var lang = window.navigator.userLanguage || window.navigator.language;
alert(lang);

After reading a bit about this to find if new information had surface, I've found some saying that this above code would return the Regional Setting from the Microsoft Windows:

See this Stackoverflow answer and the question she refers to

and so I did a simple test performed under Windows XP Profissional versão 2002 Service Pack 3 by switching with alt + shift between pt-PT and en_gb:

See this working Fiddle Example!

1)

Open the browser with system regional settings set to pt-PT:

╭──────────────────────────────────╥──────────────────┬─────────────┬─────────╮
│ Browser                          ║ Browser UI Lang  │ System Lang │ Alerted │
╞══════════════════════════════════╬══════════════════╪═════════════╪═════════╡
│ Internet Explorer 8.0.6001.18702 ║        PT        │    pt-PT    │  en-gb  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Opera 11.62                      ║        PT        │    pt-PT    │   pt    │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Firefox 3.6.16                   ║        PT        │    pt-PT    │  pt-PT  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Safari 5.1.2                     ║        PT        │    pt-PT    │  pt-PT  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Google Chrome 18.0.1025.168 m    ║        PT        │    pt-PT    │  pt-PT  │
╰──────────────────────────────────╨──────────────────┴─────────────┴─────────╯

2)

Open the browser with system regional settings set to en-gb:

╭──────────────────────────────────╥──────────────────┬─────────────┬─────────╮
│ Browser                          ║ Browser UI Lang  │ System Lang │ Alerted │
╞══════════════════════════════════╬══════════════════╪═════════════╪═════════╡
│ Internet Explorer 8.0.6001.18702 ║        PT        │    pt-PT    │  en-gb  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Opera 11.62                      ║        PT        │    pt-PT    │   pt    │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Firefox 3.6.16                   ║        PT        │    pt-PT    │  pt-PT  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Safari 5.1.2                     ║        PT        │    pt-PT    │  pt-PT  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Google Chrome 18.0.1025.168 m    ║        PT        │    pt-PT    │  pt-PT  │
╰──────────────────────────────────╨──────────────────┴─────────────┴─────────╯

3)

switching with alt + shift between pt-PT and en_gb with the browser already open:

╭──────────────────────────────────╥──────────────────┬─────────────┬─────────╮
│ Browser                          ║ Browser UI Lang  │ System Lang │ Alerted │
╞══════════════════════════════════╬══════════════════╪═════════════╪═════════╡
│ Internet Explorer 8.0.6001.18702 ║        PT        │    pt-PT    │  en-gb  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Opera 11.62                      ║        PT        │    pt-PT    │   pt    │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Firefox 3.6.16                   ║        PT        │    pt-PT    │  pt-PT  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Safari 5.1.2                     ║        PT        │    pt-PT    │  pt-PT  │
├──────────────────────────────────╫──────────────────┼─────────────┼─────────┤
│ Google Chrome 18.0.1025.168 m    ║        PT        │    pt-PT    │  pt-PT  │
╰──────────────────────────────────╨──────────────────┴─────────────┴─────────╯

The result was always the same, even tried this under windows 7 Home Premium SP1 Native EN with regional to PT, performing the above exercise, but the result was the same.

As far as my knowledge goes, and proven by the tests performed you can't get past the user agent language into the system language or even detect a change to it by using JavaScript or any dependent library.

As a side Note:

The already referred question of stackoverflow covering a similar issue as a hack workaround that I've also used to perform some tests with, but the end result was the same, the returned language didn't match the one applied by the alt + shift combination.

Other question here on stackoverflow and after a deep Google search turn out empty as well.

Sign up to request clarification or add additional context in comments.

1 Comment

@MoonLight, I've got my moments ;) Sorry if it is kind of disappointing!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.