You were introduced to the navigator object and its properties earlier. One of the properties that has not been discussed in detail is the language property, which returns the language and country code in which the browser is currently operating (for example,“en-us” for United States English):var sLang =navigator.language;//won’t work in IE
Mozilla, Opera,and Safari/Konqueror all support this property, but Internet Explorer does not. Instead, Internet Explorer provides three properties: browserLanguage (indicates the language being used by the browser), userLanguage (essentially identical to browserLanguage), and systemLanguage (indicating the language of the operating system). The userLanguage property is essentially the same as language, so you can make a simple addition to the previous code to detect the language for all browsers:var sLang =navigator.language||navigator.browserLanguage;
Using this code, you can determine if someone is viewing your page from a browser with an unsupported language setting and take appropriate action, such as redirecting the visitor to a more appropriate page:
This code checks to see if the language is French (represented as “fr”), and if so, it redirects to another page.
In this example, the string “The date you entered is incorrect.” is hard-coded.
When a value is hard-coded, its value cannot be changed without directly editing the line that uses it. Compare this with the following example:
This example places the message string into a variable called sIncorrectDateMessage. All other internationalized strings should be stored alongside this variable so you can change any and all values in only one place.
Then, using a little server-side logic, you can ensure that the correct one is included. In PHP, you could do this:
The first edition of ECMAScript introduced support for Unicode characters (which number upwards of 65,000 as compared to 128 ASCII characters), effectively assuring that ECMAScript can handle strings of any kind,including typically problematic double-byte characters.
What exactly is Unicode?
According to the official Unicode home page, “Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language.”
Unicode was developed to provide a common encoding to handle all the characters that exist in the world. Prior to Unicode, each language had its own encoding, meaning that characters in different languages could be represented by the same code,so the letter A in English could use the same code as a different letter in a different language (obviously, not optimal).
Unicode represents characters as a 16-bit number, allowing for over 65,000 possible characters, making it an ideal solution to internationalization concerns.Additionally,the first 128 Unicode characters are,in fact, the 128 ASCII characters, making compatibility with older English-language applications much easier.
All Unicode characters, including ASCII, are represented in Unicode as a four-digit hexadecimal value prefixed with a u to indicate a Unicode character. For example,u0045 is the Unicode form of the E (which can also be represented using ASCII syntax as x45).
Not sure what this line does? It presents an alert with the text “HELLO WORLD” to the user. Using the Unicode character set, you can create messages in any number of languages. Even though the plain text form of such messages isn’t human readable, it’s still the only way to deal with multibyte characters from other languages.
Browser versus operating system support
Any time you use alert(),confirm(), or prompt(),you are using an operating system dialog box. Unless the client operating system has foreign language support installed, you end up with a dialog full of gibberish. Most of the time, the browser reflects the language of the operating system, however you never can tell what individuals with do with their browsers.
When using operating system dialogs with internationalization, be aware that these problems can occur. When dealing with a distributed Web application, it may be enough to inform the customer of this limitation; on public Web sites, however, it may be best to avoid using these dialogs altogether.
This example converts all quotation marks to a backslash followed by a quotation mark using the Java replaceAll() method. The first argument is a string representation of a regular expression(you’ll remember that regular expression strings must be double-escaped, so ” becomes ”); the second argument is identical,although this one is a string and not a regular expression. This effectively changes this string:
Use double quotes
Java Script Related Tutorials
|Adv Java Tutorial||Core Java Tutorial|
|Java-Springs Tutorial||Java Servlets Tutorial|
|EJB(Enterprise JavaBeans) Tutorial||JavaServer Faces (JSF) Tutorial|
|Java Swing Tutorial||Java Tutorial|
|JavaMail API Tutorial||Java 8 Tutorial|
|Java XML Tutorial||Java Bean Utils Tutorial|
|The Java Debugger (JDB) Tutorial||Java.math Package Tutorial|
Java Script Related Interview Questions
|Java Script Interview Questions||Adv Java Interview Questions|
|Core Java Interview Questions||Java-Springs Interview Questions|
|Java Servlets Interview Questions||EJB(Enterprise JavaBeans) Interview Questions|
|JavaServer Faces (JSF) Interview Questions||Java Swing Interview Questions|
|Java 8 Interview Questions||Java XML Interview Questions|
|JavaFX Interview Questions||The Java Debugger (JDB) Interview Questions|
Java Script Related Practice Tests
|Java Script Practice Tests||Adv Java Practice Tests|
|Core Java Practice Tests||Java-Springs Practice Tests|
|Java Servlets Practice Tests||EJB(Enterprise JavaBeans) Practice Tests|
|JavaServer Faces (JSF) Practice Tests||Java 8 Practice Tests|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.