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

Joel
  • 19,175
  • 2
  • 63
  • 83
SilverLight
  • 19,668
  • 65
  • 192
  • 300

1 Answers1

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.

Community
  • 1
  • 1
Zuul
  • 16,217
  • 6
  • 61
  • 88