Monday, February 17, 2014

Build Flex Apps for Unsupported Locale

This is a bit off mobile topic but I think it's a very important issue that can be hard to solve for everyone that is building flex apps for other locale different from the common ones.

Since version 3.2 of ArcGIS for Flex, Portuguese (pt_PT) locale is supported, but if you change your Flex project to Portuguese you will get compilation errors. This article will guide you on how to overcome this problem with any language.
When you want to change the locale of your flex app, the first step is going to the project properties (right mouse click on your project's root). In Flex Compiler you will find in the arguments box:
-locale=en_US -source-path=locale/{locale} -keep-all-type-selectors=true
Change en_US for the target localization (in my case pt_PT ). Close Properties and compile. You will get the following error:
unable to open 'C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\frameworks\locale\pt_PT'
Now this is strange because ArcGIS for Flex supports pt_PT localization.
Checking ArcGIS Flex's Help, in the Localization section is stated:
"Adobe 4.6.0 supports 16 locales out of the box (see your Flash Builder install, for example, C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\frameworks\locale), while Apache Flex 4.10.0 supports 23 different locales. This still leaves seven locales supported by Esri that are not supported by the underlying Flex SDKs."
This Esri’s document also helps out on how to copy an existing locale, giving it a new name, but if you want to create a whole new localization files, let’s say, Portuguese,  you will have to translate the copied files.
But first things first! Let’s start by copying existing locale files.
1. Open the windows command line with administration privileges.

2. Type the path of your Flash builder installation directory, for example cd "C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\bin".

3. In my case I will copy the existing pt_BR to a new pt_PT because the language is quite similar. This way I won’t have much work on translating the files.
Type copylocale pt_BR pt_PT. This will create localization files for pt_PT but with the same words as pt_BR.
If you want to copy, for example, from English to Hungarian you should type copylocale en_US hu_HU.

4. In the file explorer go to C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\frameworks\locale and you will find the new created folder pt_PT. If you don’t find it this could mean that you are not running command line with administration privileges.

5. Back to Flash Builder, in the project’s properties argument box, set the locale to pt_PT, like this
-locale=pt_PT -source-path=locale/{locale} -keep-all-type-selectors=true

6. Clean and compile the project. The error will go away and the localization strings will be set to the copied locale. Check, for instance, map tool tips and month names in calendar controls.
The next step is to translate the localization files with the correct words.

1. Go back to file explorer. In C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\frameworks\locale\pt_PT  you will find ten .swc files. These files are where you will find localization strings.

2. In order to access and change this files you will have to extract, or unzip, every file with a normal packaging software like WinZip or 7Zip. You will probably get a “Access denied” error when unzipping the files, so copy every file to another location like your desktop.

3. Inside each extracted .swc you will find the folder \locale\pt_PT. Inside of this folder there are the localization strings.

4. With a lite text editor like Notepad++ edit each file to translate its string without changing the file format



5. After translating all the files you need to package the files again. Many posts on the web and even Adobe’s documentation point out to running a flex command line torecreate the .swc files but I couldn’t put it to work. I always got errors. So what I did was opening the original package files, one by one, with the packaging software and dragged and dropped the translated files back to its sources. Pay special attention to copy the files to the same location inside the package without changing the .swc original file structure.
6. The final step is to copy the translated .swc files back to C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\frameworks\ locale\pt_PT.
7. Compile and run the app.
Good Luck