Prototype of the new jquery internationalization plug-in

Source: Internet
Author: User
Tags glob month name rfc jquery library

The jquery internationalization plug-in allows you to easily handle digital, currency, and date formats between different cultures in JavaScript code. For example, you can use this plugin to correctly display a country's currency symbol

Today, we have released a prototype of a new jquery internationalization plug-in that you can use to add internationalization functionality to your JavaScript program. Plug-ins cover more than 350 cultures of international information, from Scottish Gaelic, Friesland, Hungarian, Japanese to Canadian English and so on. The plugin will be published in open source form.

You can download the prototype version of the plugin from our GitHub code base:

Http://github.com/nje/jquery-glob

You can also download some examples here to understand the simple usage.

Understanding Internationalization

The jquery internationalization plug-in allows you to easily handle digital, currency, and date formats between different cultures in JavaScript code. For example, you can use this plugin to correctly display a country's currency symbol:

You can also use this plugin to format dates so that dates and months are displayed in the correct order, and the names of dates and months can be translated correctly:

Note that in the date format of the figure Arabic above, the year is shown as 1431. This is because the year has been converted in the form of the Hijri calendar.

Some cultural differences are obvious, such as using different currencies or different month names. But other differences are subtle and unexpected. For example, in some cultures, numbers are not grouped in a balanced way. In a culture marked as "te-in" (Telugu in eastern India), numbers are grouped by 3 digits and then grouped by 2 digits. So like the number 1 million (1000000) it will be written "10,00,000". And some cultures do not group numbers at all. All of these nuances can be handled automatically by the jquery internationalization plug-in.

It may be very tricky to get the right date. Different cultures use different calendars, such as the Gregorian calendar and the Hijri calendar. The same culture may also adopt multiple calendars, such as the Gregorian calendar and the annals of the Emperor's reign, which are used in Japan. Plug-ins provide functions to convert dates into each of these calendars.

Using language tags

The jquery internationalization plug-in recognizes culture according to the language tags defined in the RFC 4646 and RFC 5646 standards (see http://tools.ietf.org/html/rfc5646), and language tags are usually composed of multiple auxiliary tags by hyphens, such as:

Language Markup Language name (Chinese)

En-au English (Australia)

EN-BZ English (Belize)

EN-CA English (Canada)

Id Indonesian text

Zh-chs Chinese (Simplified)-mark no longer used

Zu zu Lu Wen

Note that a single language, such as English, can have more than one language tag at a time. In the same English-speaking countries, the number, currency and date formats used in Canada are different from those of Australia or the United States. You can use the following language Tag Finder tool to get the language tags of a culture:

http://rishida.net/utils/subtags/

A folder called Globinfo in the jquery internationalization plug-in contains information about these 350 cultures. In fact, there are more than 700 files in this folder, because it includes the minimized (Minify) and original versions of each file.

For example, in the Globinfo folder, the file jquery.glob.en-au.js corresponds to English (Australia), jQuery.glob.id.js corresponds to Indonesian, and jquery.glob.zh-chs corresponds to Simplified Chinese.

Example: Specifying a Culture

If you want to create a German web site and want to use German in the client's JavaScript script, display all dates, currency symbols, and numbers. The source code for that page might resemble the following HTML:

Note the span labels above, which identify all areas that need to be formatted with internationalized Plug-ins: The price of the commodity, the date of the shelf, and the amount of inventory.

To use the jquery internationalization plugin on your Web page, you need to add three JavaScript files: the jquery library, the jquery internationalization plugin, and the specific cultural habits information:

In the previous example, I statically added a jquery.glob.de-de.js file containing German cultural habits to the Web page, "De-de" is a language tag that represents German used in Germany.

Now that you have introduced the necessary script files, you can use the following client-side JavaScript code to invoke the plug-in to display the price, the date of the shelf, and the amount of inventory equivalent:

The jquery internationalization plug-in adds new functions to the jquery function library-including preferculture () and new functions such as format (). You can use the Preferculture () function to set the default culture used when other functions are called by the plug-in. The Preferculture () function takes a language tag as an argument, and this function uses the culture closest to the language tag.

The $.format () function is really used to format money, dates, and numbers. The second parameter of the $.format () function is the format classifier. For example, passing in "C" means that the value of the parameter is formatted in currency style. In Githum's readme file, the meaning of all format classifier representations is described in detail: http://github.com/nje/jquery-glob

When we open this page in the browser, all things are displayed correctly according to the German custom. The currency symbol takes the euro symbol, the date is in German and the date and month name, and the number separator is a dot (.), not a comma (,).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.