The jQuery International plugin allows you to easily process numbers, currencies, and date formats between different cultures in javascript code. For example, you can use this plug-in to correctly display the currency symbols of a country.
Today, we have released a new jQuery internationalization plug-in prototype. You can reference this plug-in your javascript program to add internationalization functions. The plug-in covers more than 350 types of international cultural information, from Scotland's Gael language, forissian language, Hungary language, Japanese to Canadian English. The plug-in will be released in open source form.
You can download the plug-in prototype from our Github code library:
Http://github.com/nje/jquery-glob
You can also download some examples here for simple usage.
Understand Internationalization
The jQuery International plugin allows you to easily process numbers, currencies, and date formats between different cultures in javascript code. For example, you can use this plug-in to correctly display the currency symbols of a country:
You can also use this plug-in to orchestrate the date format, so that the date and month are displayed in the correct order, and the date and month names can also be correctly translated:
Note that in the Arabic date format, the year is displayed as 1431. This is because the year has been converted in the calendar mode.
Some cultural differences are obvious, such as using different currencies or names of different months. However, some other differences are subtle and unexpected. For example, in some cultures, numbers are not grouped in a balanced manner. IN a culture marked as "te-IN" (Telugu IN eastern India), numbers are grouped by three digits and then grouped by two digits. Therefore, the number 1 million (1000000) is written as "10, 00, 000 ". Some cultures do not even group numbers. All these minor differences can be automatically handled by jQuery's International plug-in.
It may be tricky to get the correct date. Different cultures use different calendars, such as calendars and calendars. The same culture may also adopt multiple calendars. For example, Japan uses both the Gregorian calendar and the Historical calendar derived from the Emperor's year. The plug-in provides functions to convert dates in all these calendars.
Use language tags
JQuery internationalization plug-ins recognize culture based on the language tags defined in RFC 4646 and RFC 5646 standards (see http://tools.ietf.org/html/rfc5646). Language tags are typically made up of a combination of multiple secondary tags by a hyphen, for example:
Language markup language name (Chinese)
En-AU (Australia)
En-BZ English (Belize)
En-CA English (Canada)
Id Indonesian
Zh-CHS Chinese (simplified)-mark no longer used
Zu zuluwen
Note that a single language, for example, English, can have multiple language tags at the same time. In English-speaking countries, Canada adopts different numbers, currencies, and date formats from Australia or the United States. You can use the following language tag search tool to obtain the language tag of a culture:
Http://rishida.net/utils/subtags/
A folder named globinfo in the jQuery internationalization plug-in contains information about these 350 cultures. In fact, this folder contains more than 700 files because it includes the minimum and original versions of each file.
For example, in the globinfo folder, the file jQuery. glob. en-AU.js (Australia), jQuery. glob. id. js corresponds to Indonesian, while jQuery. glob. zh-CHS corresponds to simplified Chinese.
Example: specify a culture
Suppose you want to create a German website and want to use German in the client's javascript script to show all the date, currency symbols, and numbers. The source code of the page may be similar to the following HTML:
Note that the span labels above indicate all regions that need to be formatted using international plug-ins: product prices, shelving dates, and inventory.
To use jQuery International plug-in on a webpage, you need to add three javascript files: jQuery library, jQuery International plug-in, and specified cultural habits:
In the above example, I will include jQuery.glob.de-DE. javaScript files are statically added to webpages. "de-DE" is a language mark, indicating the German language used in Germany.
Now that necessary script files have been introduced, you can use the following client javascript code to call the plug-in to display the price, mounting date, and inventory equivalent:
The jQuery International plug-in adds some new functions to the jQuery function library, including preferCulture () and format. You can use the preferCulture () function to set the default culture used for calling other functions of the plug-in. The preferCulture () function accepts a language tag as a parameter, which uses the culture closest to the language tag.
The $. format () function is used to orchestrate currency, date, and number formats. The second parameter of the $. format () function is the format classifier. For example, "c" is input to indicate the parameter values in the style of the currency. In the ReadMe file of githum, the meaning of all format specifiers is described in detail: http://github.com/nje/jquery-glob
When we open this page in a browser, everything is correctly displayed according to the German habits. The currency symbol uses the euro symbol, the date uses the German Date and month name, And the number separator uses the dot (.) instead of the comma (,).