Wednesday, January 26, 2011

Using FlexUnit with locales other than the ones provided by FlashBuilder 4

Today i took some time to find out, why the integrated FlexUnit support doesn't work, if your project has a locale other than the ones provided by FlashBuilder.

One of my last Flex projects was for the danish web market. Therefore it used the danish locale. Of course we wrote a lot of unit tests to verify our code. Unfortunately the integrated support for FlexUnit didn't work with the danish locale. It always gave me a error like "Unable to find resources for FlexUnitTestRunner".

One way to work around it, was to create a test project, which referenced the test folder of the main project but used en_US as the locale. Not ideal, but it worked without much hassle.

However, i wasn't satisfied with creating test projects for all my Flex projects. After digging a bit into the FlashBuilder plugin directory i found out, that there are two directories for the resources of FlexUnit. One contains the resources for en_US and the other directory contains the resources for the rest of us ;)

My first try was to simply copy the files from en_US to a new directory da_DK. However, the error didn't go away. By looking into the swc library files i found out, that internally they still had a package path en_US instead of the da_DK that i needed.

Next try was to see, if copylocale.exe supports source and target directories, which it doesn't unfortunately. Hm, at least this gave me the idea, that i need something like copylocale, but with configurable paths.

So the third try was to recreate copylocale.exe using ant. The ant script copies the en_US resources to the new da_DK folder. It unpacks the swc library files to a temporary folder. This gives me the original source files for the en_US locale. Next it renames the en_US package to da_DK. And last but not least it compiles the new swc from these source. That works like a charm now. I'm able to use the integrated FlexUnit with a danish locale finally :)

Like copylocale, the actual strings are still in english of course. If you want danish strings, you can do so by manually translating the content of FlexUnitTestRunner.properties and recompile the swc with the translated file.

Here you can find the ant script.

Happy testing,
Ralf.