i18n Translation System

While working on a new project I developed a translation system. This does not do the translation on its own but more is more like a language file system. It is highly modeled after the one in the SilverStripe CMS the one that powers this website. It uses a pretty stright forward language file consisting of a parent (which is usually the classname), a key which is a unique identifyer atleast in that parent, and the value which is that languages replacement for that piece of text. LIke the translation system in SilverStripe you simply call i18n._t() which is a top level function passing in the path (ClassName.KEY) and the default value which by convention should start with an underscore this is to help identify problems with the language file. This class is pretty simple to implement, however at this time it only supports Adobe AIR 1.5 or greater. This does work with databinding in flex as well, so if you call i18n.init() again you can pass in a language to init() ie en_US and all areas that are bound to _t() will update with the new data automatically.

One caviot to make note of if your using _t() in your main mxml file on any elements for example a button that are created when the application is, then you must call i18n.init() in the preinitialize event.

To use this component you will find the Frame class located in the com.containers package. This component is available for download using the link to the left, just don't forget to give a nod to the developer me. As like every project that appears in this portfolio, it is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License. If you are a commecial entity looking to use this in one of your projects please use the contact me link above and we will discuss arrangements for use.

ASDocs are available here, see the bellow snippit on how to get it working.

Language file (app:/languages/en_US.airln)

{parent:[BaseClass],key:[GREATING],value:[Hello World]}

Example Class

package {
    public class BaseClass  {
        public function BaseClass():void {
            i18n.getInstance().init(); //Initialise the i18n library (Very important you must do this before any calls to i18n.getInstance()._t()
            trace(i18n.getInstance()._t('BaseClass.GREATING','_Hello World')); //Produces "Hello World", not just removing the _ it looks into the language file
        }
}

Example MXML Implementation

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" width="640" height="480">
    <mx:Label fontSize="20" horizontalCenter="0" verticalCenter="0" label="{i18n.getInstance()._t('BaseClass.GREATING','_Hello World')}"/>
</mx:WindowedApplication>