Pages

Friday, December 3, 2010

Localization of Flex applications using ExcelAntTasks

ExcelAntTasks is a small tool which allows you to define all locales in an Excel file and to convert them automatically to *.properties files using Ant.

The following image shows locales defined in an Excel file:



The first column contains the keys and the second row contains the identifiers for the locales (en_US, de_DE and so on). Empty fields (see de_DE) mean that the value of a fallback locale (en_US) should be used. All blank fields won't show up in the *.properties files.

Now let's take a look at the build script to convert the locales:

<project default="buildLocales" name="ExcelAntTask Test">
  <taskdef classname="excelanttasks.ConvertExcel" classpath="build/excelAntTasks.jar" name="convert"/>
  <target name="buildLocales">
    <convert excelpath="Locale.xls" localepath="locale/"/>
  </target>
</project>

The ExcelAntTasks are made available using the taskdef tag. After that you can convert Excel files using the convert tag, which provides the following attributes:

- excelpath: The path to the excel file. Default is "Locale.xls".
- localepath: The path where to store the created property files. Default is "locale/".
- resourcename: The name of the created property file. Default is "Locale.properties".
- headerrownumber: The number of the header row. The header row contains the identifiers for the locales (en_US, de_DE and so on). Default is 2.
- keycolumnnumber: The number of the key column. The key column contains the keys used in Flex. Default is 1.
- keyLabel: The identifier of the key column. Default is "labelkey".

Running the build script creates a folder and a *.properties file for each locale identifier defined in the Excel file:



As you can see, there's one additional locales file called debug which maps the keys to the keys and which can be used to identify not yet localized string in the user interface.

Right now it is not possible to convert XML-based Excel files (XLSX, Excel 2007+), but this feature is definitely planned.

2 comments:

  1. Great stuff!

    Thanks for opening the code Norbert!

    ReplyDelete
  2. Hi! For localization projects, I recommend trying a software localization management platform like https://poeditor.com/ that can simplify the workflow.

    ReplyDelete