Monday, July 23, 2007

Creating a localized application

This section begins with a simple sample localized application. It describes the key aspects in creating a localized application.

To build a simple localized application:
1)Create a locale/en_US/RegistrationForm.properties file that contains the following text:registration_title=Registration
submit=Submit Form
personname=Name
street_address=Street Address
city=City
state=State!
zip=ZIP Code
thanks=Thank you for registering!
subtext=[0] alphabetically comes before [1]


The location of the locale directory is not important, but you must be able to add that location to the compiler's source path.

2) Create a locale/es_ES/RegistrationForm.properties file that contains the following text. Ensure that you save this file with UTF-8 encoding.registration_title=Registro
submit=Someta La Forma
personname=Nombre
street_address=Dirección De la Calle
city=Ciudad
state=Estado
zip=Código postal
thanks=¡Gracias por colocarse!
subtext=[0] viene alfabéticamente antes [1]


3) Create a LocalizedForm.mxml application that contains the following code:
<?xml version="1.0"?>

<!--
l10n/LocalizedForm.mxml -->
<
mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<
mx:Script><![CDATA[

import
mx.resources.ResourceBundle;
import
mx.controls.Alert;

[
ResourceBundle("RegistrationForm")]

private static var
rb:ResourceBundle;

private function
registrationComplete():void {

Alert.show(rb.getString('thanks'));
}

]]></
mx:Script>

<
mx:Form>
<
mx:FormItem label="@Resource(key='personname', bundle='RegistrationForm')">
<
mx:TextInput/>

</
mx:FormItem>
<
mx:FormItem label="@Resource(key='street_address', bundle='RegistrationForm')">
<
mx:TextInput/>

</
mx:FormItem>
<
mx:FormItem label="@Resource(key='city', bundle='RegistrationForm')">
<
mx:TextInput/>

</
mx:FormItem>
<
mx:FormItem label="@Resource(key='state', bundle='RegistrationForm')">
<
mx:TextInput/>

</
mx:FormItem>
<
mx:FormItem label="@Resource(key='zip', bundle='RegistrationForm')">
<
mx:TextInput/>

</
mx:FormItem>
</
mx:Form>
<
mx:Button id="b1" label="@Resource(key='submit', bundle='RegistrationForm')" click="registrationComplete()"/>

</
mx:Application>


4)Use the following mxmlc command line to compile the application with the en_US resource bundle:mxmlc -locale en_US source-path+=path_to_locale_dir/{locale} -o Form-us.swf LocalizedForm.mxml

5)Use the following mxmlc command line to compile the application with the es_ES resource bundle:mxmlc -locale es_US source-path+=path_to_locale_dir/{locale} -o Form-es.swf LocalizedForm.mxml

6)Run the two SWF files to see the different form labels and alerts in the applications.

1 comment:

summ3r said...

Hello, Mr Feng Hua! If you're involved in localization projects and are interested in management tools that can help automate the translation process of software strings, I believe you may want to have a look at https://poeditor.com/
It's got great potential, being equipped with API, translation memory and other useful features.