Written in AS2, class based and OOP architectured, lightweight, smart and feature packed! Buy it today for only $5!
Ever needed to internationalize or localize your flash appplication?
XPInternationl is just what you need to complete the localization of you application.
FlashMX2004 added several new features that greatly enhance the work flow for authoring multiple language Unicode-based applications but there was a piece missing, there was no way to localize dates or number. Until now!
XPInternational makes it easy to:
Format and parse dates in a simple and standard way for any languages or locale.
Format and parse numbers in a simple and standard way for any different language or locale.
Create new locales.
Now also includes support for the FMX2004 Professional DataBinding API. Installs as native formatters accessible from the Bindings tab of the ComponentInspector
Locale:
A Locale object represents a specific geographical, political, or cultural region.
An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user.
For example, displaying a number is a locale-sensitive operation--the number should be formatted according to the customs/conventions of the user's native country, region, or culture.
The Locale class contains localized information on dates and numbers.
You can set a default locale for you application and without any code changes all date and number format will display in the style and language for that locale
You can also use multiple locales within an application by creating DateFormat or NumberFormat objects for a particular locale
Worried about your application be bloated by including locale information for uneeded locales? Don't be XPInternationl ensures that Flash only includes those Locale you actually use.
XPInternationla comes with a set of Locale classes for common locales with more available on request or you can simply create your own locale class using our simple API.
First we add the locale classes we want in this application. This only needs to be done once per application.
var d = new Date();
var dfEn= DateFormat.getDateInstance(DateFormat.MEDIUM);
var dfFr= DateFormat.getDateInstance(DateFormat.MEDIUM,Locale.getInstance("fr"))
var dfZh= DateFormat.getDateInstance(DateFormat.MEDIUM,Locale.getInstance("zh"))
var dfEnGB= DateFormat.getDateInstance(DateFormat.MEDIUM,Locale.getInstance("en_GB"))
Next we obtain DateFormat objects, the first format objects doesnt specify a locale so it will use the current default locale.
Without recoding our application dates have been formatted in a locale specific manner.
var nfEn= NumberFormat.getCurrencyInstance();
var nfFr= NumberFormat.getCurrencyInstance(Locale.getInstance("fr"))
var nfZh= NumberFormat.getCurrencyInstance(Locale.getInstance("zh"))
var nfEnGB= NumberFormat.getCurrencyInstance(Locale.getInstance("en_GB"))
var n=19456.789
frNum.text=nfFr.format(n);
zhNum.text=nfZh.format(n);
enNum.text=nfEn.format(n);
enGBNum.text=nfEnGB.format(n);
Then we do the same for NumberFormat.
In this case we want to use a CurrenyFormat and once again for the first one as we dont specify a locale it will use the current default locale.
The currency format will automatically display the localized currency symbol and place it in the correct position all without our having to recode our application.
DateFormat:
DateFormat is a class for date/time formatting which formats and parses dates or time in a language-independent manner.
The date/time formatting allows for formatting (i.e., date -> text), parsing (text -> date).
The date is represented as a Date object or as the milliseconds since January 1, 1970, 00:00:00 GMT.
DateFormat provides many class methods for obtaining default date/time formatters based on the default or a given locale and a number of formatting styles.
The formatting styles include FULL, LONG, MEDIUM, and SHORT.
DateFormat helps you to format and parse dates for any locale.
Your code can be completely independent of the locale conventions for months, days of the week.
DateFormat allows you to start by choosing any user-defined patterns for date-time formatting.
However, you are encouraged to create a date-time formatter with either getTimeInstance, getDateInstance, or getDateTimeInstance in DateFormat.
Each of these class methods can return a date/time formatter initialized with a default format pattern.
You may modify the format pattern using the applyPattern methods as desired.
Detailed information on date formatting can be found here.
NumberFormat:
This class provides the interface for formatting and parsing numbers.
NumberFormat helps you to format and parse numbers for any locale.
Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or whether the number format is even decimal.
It has a variety of features designed to make it possible to parse and format numbers in any locale. It also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized.
Detailed information on number formatting can be found here.