Aplicações localizadas (L10N applications)

Hello folks,

Let’s show how flex-mojos can be used to generate resource-bundles.

To start, I strongly recommend you read this.

This is a good start to understand how Runtime Localization work. And, with this in mind we can show how to use flex-mojos to create Runtime Localized applications.

  • Compiled Localization

Here you can get the source for FlightReservationSamples 1 and 2.

So, lets start from begging. Download FlightReservation1 Sample and import it to FlexBuilder.

In other to compile this Sample1 with flex-mojos, we need to add this pom:

<?xml version="1.0" encoding="UTF-8"?>
<project>

<parent>
<groupId>info.rvin.mojo</groupId>
<artifactId>flex-super-pom</artifactId>
<version>1.0-beta2</version>
</parent>

<groupId>com.adobe.flex.samples</groupId>
<artifactId>FlightReservation1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>swf</packaging>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>info.rvin.mojo</groupId>
<artifactId>flex-compiler-mojo</artifactId>
<configuration>
<sourceFile>FlightReservation1.mxml</sourceFile>
<mergeResourceBundle>true</mergeResourceBundle>
<resourceBundlePath>${basedir}/locale/{locale}</resourceBundlePath>
</configuration>
</plugin>
</plugins>
</build>

</project>

During this post I figure out flex-mojos will not be able to compile FlightReservation1.
Found a bug, issue on adobe, and post stop on the middle.
https://bugs.adobe.com/jira/browse/SDK-15453

I strongly believe is a bug because when I define locales en_US,ja_JP all appears in English. When I define ja_JP,en_US all appears in Japanese. Lets wait Adobe’s feedback.

  • Runtime Localization

Well, lets do to the second sample. Download it from here. Again, import it on FlexBuilder.

Another pom is required for this project:

<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>info.rvin.mojo</groupId>
<artifactId>flex-super-pom</artifactId>
<version>1.0-beta2</version>
</parent>

<groupId>com.adobe.flex.samples</groupId>
<artifactId>FlightReservation2</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>swf</packaging>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>info.rvin.mojo</groupId>
<artifactId>flex-compiler-mojo</artifactId>
<configuration>
<debug>true</debug>
<sourceFile>FlightReservation2.mxml</sourceFile>
<mergeResourceBundle>false</mergeResourceBundle>
<resourceBundlePath>${basedir}/locale/{locale}</resourceBundlePath>
<locales>
<param>en_US</param>
<param>ja_JP</param>
</locales>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>framework</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>resource-bundle</type>
<classifier>ja_JP</classifier>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>rpc</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>resource-bundle</type>
<classifier>ja_JP</classifier>
</dependency>
</dependencies>

</project>

So, lets explain this pom.

    sourceDirectory: define sources located at src directory.
    mergeResourceBundle: when is false resource-bundle files are not merged into SWF, so, we got runtime resource-bundle.
    resourceBundlePath: folder when .properties files are located. {locale} is replaced at runtime by locale
    locales: define what locales should be generated.

So, running mvn clean install you will got 3 artifacts:

[INFO] [install:install]
[INFO] Installing D:\FlightReservation2\target\FlightReservation2-1.0-SNAPSHOT.swf to c:\repository\com\adobe\flex\samples\FlightReservation2\1.0-SNAPSHOT\FlightReservation2-1.0-SNAPSHOT.swf
[INFO] Installing D:\FlightReservation2\target\FlightReservation2-1.0-SNAPSHOT-en_US.swf to c:\repository\com\adobe\flex\samples\FlightReservation2\1.0-SNAPSHOT\FlightReservation2-1.0-SNAPSHOT-en_US.swf
[INFO] Installing D:\FlightReservation2\target\FlightReservation2-1.0-SNAPSHOT-ja_JP.swf to c:\repository\com\adobe\flex\samples\FlightReservation2\1.0-SNAPSHOT\FlightReservation2-1.0-SNAPSHOT-ja_JP.swf

One unlocalized swf and two resources swfs (one per locale).

In order to run that, all files must be copied into any HTTP server with html wrappers. I don’t know why, but runtime localization only run with html wrapper.

So, while flex-mojos doesn’t generate html wrapper, it can be download from here.

I just copy and rename swf files.

Both projects are available on SVN under it folder.

VELO

14 Responses to “Aplicações localizadas (L10N applications)”

  1. Hello VELO,
    Great work, I am new to Flex and your work actually give me a lot of hope that I can quickly get into Flex :) Congratulations for all your team, I am moving to Flex due to MyGWT “trick” moving licence from LGPL to GPL, never do this:) I would like to ask you actually how FlightReservation2Package works with what maven command ? Actually this is server side for ought I see or ? Can you give me short example ?

    Kind Regards,
    Pavel Tonev

  2. Hi Velo,

    I think the mxmlc.jar dependency on the plugin for creating resources is also required.

    I just added the following as a plugin dependency and only after that I was able to generate the resource bundle swfs.

    com.adobe.flex
    mxmlc
    3.0.0.477

    regards
    sriraman.

  3. Hi Sriraman,

    That shouldn’t be required.

    I imagine something happen when maven download flex-compiler-oem.
    Try to delete {repo}/com/adobe/* and try again.

    VELO

  4. https://bugs.adobe.com/jira/browse/SDK-15453 <= In the comments you state that this bug has been resolved, but when I try your code, I can only use the first locale.

    Is it possible that this fix hasn’t been submitted to the Maven repository yet?

    This is my code:

    info.rvin.mojo
    flex-compiler-mojo
    1.0-beta7

    main.mxml
    true
    ${basedir}/src/main/flex/locale/{locale}

  5. @Bjorn
    You’re using a very old version of flex-mojos (1.0-beta7). Try upgrading to at least 1.0. We’re using locales just fine in 2.0M8.

  6. Repository? Because we are using http://flex-mojos.googlecode.com/svn/trunk/repository/info/rvin/mojo/, but that doesn’t contain that version.

  7. Flex-mojos switched to a new repository a while ago. You need to update to this:
    http://svn.sonatype.org/flexmojos/repository/
    The groupId has changed as well to info.flex-mojos (from info.rvin.mojo)

  8. Downloading: http://repo1.maven.org/maven2/info/flex-mojos/flex-compiler-mojo/2.
    0M8/flex-compiler-mojo-2.0M8.jar
    [INFO] ————————————————————————
    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] Plugin could not be found - check that the goal name is correct: Unable t
    o download the artifact from any repository

    Try downloading the file manually from the project website.

    Then, install it using the command:
    mvn install:install-file -DgroupId=info.flex-mojos -DartifactId=flex-compile
    r-mojo -Dversion=2.0M8 -Dpackaging=maven-plugin -Dfile=/path/to/file

  9. You can ignore that last comment :). Now I get this:

    Loading configuration file C:\Users\BjDe\workspace\exocura-flex-maven\exocura-ri
    a\target\classes\config.xml
    Error: Unable to resolve resource bundle “containers” for locale “en_US”.

    Error: Unable to resolve resource bundle “validators” for locale “en_US”.

    Error: Unable to resolve resource bundle “states” for locale “en_US”.

    Error: Unable to resolve resource bundle “styles” for locale “en_US”.

  10. Sounds like your Flex SDK dependencies are not correct. If you are using the Flex-mojos super poms, then make sure your parent pom is set to version 2.0M8 as well.
    If you are not using them, then you need to update your dependencies to use the flex-framework dependency like here:
    http://svn.sonatype.org/flexmojos/repository/info/flex-mojos/flex-super-pom/2.0M8/flex-super-pom-2.0M8.pom

    		 
    		
    			com.adobe.flex.framework
    			flex-framework
    			3.1.0.2710
    			pom
    		
    
  11. I already did that, but it’s still the same problem. When I run the install command, I get the following trace:

    [INFO] Loading configuration file C:\workspace\flex-project\flex-ria\target\classes\config.xml
    [ERROR] Unable to resolve resource bundle “core” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “core” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “skins” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “core” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “effects” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “core” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “containers” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “styles” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “validators” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “controls” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “rpc” for locale “en_US”.
    [ERROR] Unable to resolve resource bundle “controls” for locale “en_US”.

    and son.

    When I open that config.xml, that file only contains a start en endtag.

    Configuration:

    info.flex-mojos
    flex-compiler-mojo
    2.0M10
    true

    flex-web

    Is there a way to make this work? Why is it looking for all those resource bundles, since I don’t need those from the start.

  12. (You can delete my previous comment)

    I’ve altered my pom a bit and came up with this configuration:

    info.flex-mojos
    flex-compiler-mojo
    2.0M10
    true

    true
    main.mxml
    false
    ${basedir}/src/main/flex/locale/{locale}

    en_US

    exocura-web

    When I run the install command, I get the following stacktrace:

    [INFO] Compiling resources bundles!
    [INFO] Installing resource bundle beacon: …\AppData\Local\Temp\exocu
    ra-ria-1.0-SNAPSHOT64865.rb.swc
    [INFO] Generating resource-bundle for en_US
    Loading configuration file …\workspace\flex-flex-maven\flex-ri
    a\target\classes\config.xml
    Error: Unable to resolve resource bundle “containers” for locale “en_US”.
    [INFO] Already trust on …\workspace\flex-flex-maven\flex-ria\t
    arget\flex-ria-1.0-SNAPSHOT.swf
    [INFO] [resources:testResources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [flex-compiler-mojo:test-compile]
    [INFO] Flex-mojos 2.0M10 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
    [WARNING] Test folder not found…\workspace\flex-flex-maven\exocur
    a-ria\src\test\java
    [INFO] [flex-compiler-mojo:test-run]
    [INFO] Flex-mojos 2.0M10 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
    [WARNING] Skipping test run. Runner not found: …\workspace\flex-f
    lex-maven\flex-ria\target\test-classes\TestRunner.swf
    [INFO] [install:install]
    [INFO] Installing …\workspace\flex-flex-maven\flex-ria\target\
    flex-ria-1.0-SNAPSHOT.swf to …\.m2\repository\be\ordina\flex-r
    ia\1.0-SNAPSHOT\flex-ria-1.0-SNAPSHOT.swf
    [INFO] Installing …\AppData\Local\Temp\flex-ria-1.0-SNAPSHOT64865
    .rb.swc to …\.m2\repository\be\ordina\flex-ria\1.0-SNAPSHOT\exocu
    ra-ria-1.0-SNAPSHOT.swc
    [INFO] Installing …\workspace\flex-flex-maven\flex-ria\target\
    flex-ria-1.0-SNAPSHOT-en_US.swf to …\.m2\repository\be\ordina\exo
    cura-ria\1.0-SNAPSHOT\flex-ria-1.0-SNAPSHOT-en_US.swf
    [INFO] ————————————————————————
    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] Error installing artifact: File …\workspace\flex-flex-mave
    n\flex-ria\target\flex-ria-1.0-SNAPSHOT-en_US.swf does not exist

    It’s true, that swf file doesn’t exist. The problem is that I don’t understand why it says “Installing …en_US” and then starts complaining that it doesn’t exist … That’s the whole point of installing that thing is my first thought :).

  13. And to complete the trilogy of questions. In the previous repository (http://flex-mojos.googlecode.com/svn/trunk/repository) there were several more dependencies for localization. Why aren’t these added in the new repository? And is it also possible to explain the purpose of those .swc dependencies? Because I really have no idea why to add these and I don’t think this is explained in this article (or any other articles on this site).

  14. You can see updated localized applications at:
    http://svn.sonatype.org/flexmojos/trunk/rvin-mojo/test-harness/projects/concept/l10n-swf/
    http://svn.sonatype.org/flexmojos/trunk/rvin-mojo/test-harness/projects/concept/l10n-swc-swf/

    VELO

Discussion Area - Leave a Comment