user535617
user535617

Reputation: 644

Javascript Localization in Windows

I'm looking for a way to localize a Windows Sidebar Gadget. It is written primarily in Javascript. What I specifically want is a way to get the user's "language code" (eg. en-us) because the language code will be used to get a localized XML file from a server.

If anyone has any ideas for how to get this language code or, even better, some code that accomplishes this task that would be great. Thanks in advance.

Edit: It looks like whoever asked for code deleted his comment, so I deleted the sample code as it was just clutter that didn't contribute.

Upvotes: 3

Views: 560

Answers (2)

Martin Jespersen
Martin Jespersen

Reputation: 26183

There are several ways of accomplishing this, which method you wish to use depends on your needs and what your setup allows you.

  1. navigator.language will tell you what language the installed browser has - not what the user has chosen as language from the preferences tho. So this will only give you a hint, but it might be enough for you.

  2. Geolocation. There are several APIs you can use for this, but again, they will not tell you the browsers language preference set by the user, but where they are in the world. again, this might be what you need and might not.

  3. On the server look at the request headers for the js-file/html-page/etc. Specifically, look at the Accept-Language header which reflects the users desired language preference as set in the browser. From your server, seed your js with this in a variable. Alas, this value cannot be read from javascript itself, so you need the server for it.

Upvotes: 1

Rafael S.
Rafael S.

Reputation: 21

It's not possible. You can't get that setting from the Browser, so it's not available to Javascript. Define a standard language and let the user to choose another.

Upvotes: 1

Related Questions