- Add language selectors to the i18n examples
- Fixed some problems with the runtime loaded locales


Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/957c1e19
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/957c1e19
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/957c1e19

Branch: refs/heads/as3httpclient-work
Commit: 957c1e1977d70fbddff450cf50b1107290f558ce
Parents: 2b7f3e9
Author: Christofer Dutz <christofer.d...@codecentric.de>
Authored: Sat Apr 25 14:36:07 2015 +0200
Committer: Christofer Dutz <christofer.d...@codecentric.de>
Committed: Sat Apr 25 14:36:07 2015 +0200

----------------------------------------------------------------------
 .../examples/i18n/compiled-locales/pom.xml      |  2 +-
 .../examples/i18n/compiled-locales/swf/pom.xml  |  5 +-
 .../swf/src/main/flex/Main.mxml                 | 25 +++++++--
 .../examples/i18n/compiled-locales/war/pom.xml  |  8 +--
 .../examples/i18n/runtime-locales/pom.xml       |  2 +-
 .../examples/i18n/runtime-locales/swf/pom.xml   |  5 +-
 .../runtime-locales/swf/src/main/flex/Main.mxml | 54 +++++++++++++++++++-
 .../examples/i18n/runtime-locales/war/pom.xml   |  8 +--
 8 files changed, 90 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/957c1e19/maven-flex-plugin/examples/i18n/compiled-locales/pom.xml
----------------------------------------------------------------------
diff --git a/maven-flex-plugin/examples/i18n/compiled-locales/pom.xml 
b/maven-flex-plugin/examples/i18n/compiled-locales/pom.xml
index 83d1e60..be807ff 100644
--- a/maven-flex-plugin/examples/i18n/compiled-locales/pom.xml
+++ b/maven-flex-plugin/examples/i18n/compiled-locales/pom.xml
@@ -28,7 +28,7 @@
         <version>1.0.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>compiled-locals</artifactId>
+    <artifactId>compiled-locales</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>pom</packaging>
 

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/957c1e19/maven-flex-plugin/examples/i18n/compiled-locales/swf/pom.xml
----------------------------------------------------------------------
diff --git a/maven-flex-plugin/examples/i18n/compiled-locales/swf/pom.xml 
b/maven-flex-plugin/examples/i18n/compiled-locales/swf/pom.xml
index a15264c..4c23e35 100644
--- a/maven-flex-plugin/examples/i18n/compiled-locales/swf/pom.xml
+++ b/maven-flex-plugin/examples/i18n/compiled-locales/swf/pom.xml
@@ -24,11 +24,11 @@
 
     <parent>
         <groupId>org.apache.flex.examples.i18n</groupId>
-        <artifactId>compiled-locals</artifactId>
+        <artifactId>compiled-locales</artifactId>
         <version>1.0.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>compiled-locals-swf</artifactId>
+    <artifactId>compiled-locales-swf</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>swf</packaging>
 
@@ -41,6 +41,7 @@
                 <version>7.1.0-SNAPSHOT</version>
                 <extensions>true</extensions>
                 <configuration>
+                    <debug>true</debug>
                     <localesCompiled>
                         <locale>en_US</locale>
                         <locale>de_DE</locale>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/957c1e19/maven-flex-plugin/examples/i18n/compiled-locales/swf/src/main/flex/Main.mxml
----------------------------------------------------------------------
diff --git 
a/maven-flex-plugin/examples/i18n/compiled-locales/swf/src/main/flex/Main.mxml 
b/maven-flex-plugin/examples/i18n/compiled-locales/swf/src/main/flex/Main.mxml
index ea188bc..a449ab7 100644
--- 
a/maven-flex-plugin/examples/i18n/compiled-locales/swf/src/main/flex/Main.mxml
+++ 
b/maven-flex-plugin/examples/i18n/compiled-locales/swf/src/main/flex/Main.mxml
@@ -18,13 +18,32 @@
 
 -->
 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
-               xmlns:s="library://ns.adobe.com/flex/spark"
-               xmlns:mx="library://ns.adobe.com/flex/mx">
+               xmlns:s="library://ns.adobe.com/flex/spark">
 
     <fx:Metadata>
         [ResourceBundle("myresources")]
     </fx:Metadata>
 
-    <s:Label text="{resourceManager.getString('myresources','greeting')}"/>
+    <fx:Script>
+      <![CDATA[
+        import mx.collections.ArrayCollection;
+
+        import spark.events.IndexChangeEvent;
+
+        [Bindable]
+        private var locales:ArrayCollection = new 
ArrayCollection([{label:"English", locale:"en_US"},
+            {label:"German", locale:"de_DE"}]);
+
+        private function onLanguageChange(event:IndexChangeEvent):void {
+            resourceManager.localeChain = [localeSelector.selectedItem.locale];
+        }
+
+        ]]>
+   </fx:Script>
+
+    <s:VGroup>
+        <s:ComboBox id="localeSelector" dataProvider="{locales}" 
change="onLanguageChange(event)"/>
+        <s:Label text="{resourceManager.getString('myresources','greeting')}"/>
+    </s:VGroup>
 
 </s:Application>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/957c1e19/maven-flex-plugin/examples/i18n/compiled-locales/war/pom.xml
----------------------------------------------------------------------
diff --git a/maven-flex-plugin/examples/i18n/compiled-locales/war/pom.xml 
b/maven-flex-plugin/examples/i18n/compiled-locales/war/pom.xml
index e646f0a..b68bd30 100644
--- a/maven-flex-plugin/examples/i18n/compiled-locales/war/pom.xml
+++ b/maven-flex-plugin/examples/i18n/compiled-locales/war/pom.xml
@@ -24,11 +24,11 @@
 
     <parent>
         <groupId>org.apache.flex.examples.i18n</groupId>
-        <artifactId>compiled-locals</artifactId>
+        <artifactId>compiled-locales</artifactId>
         <version>1.0.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>compiled-locals-war</artifactId>
+    <artifactId>compiled-locales-war</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>war</packaging>
 
@@ -37,7 +37,7 @@
         perform the filtering.
     -->
     <properties>
-        <swf>swf-1.0.0-SNAPSHOT</swf>
+        <swf>compiled-locales-swf-1.0.0-SNAPSHOT</swf>
         <width>100%</width>
         <height>100%</height>
         <title>My First Application</title>
@@ -107,7 +107,7 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.flex.examples.i18n</groupId>
-            <artifactId>compiled-locals-swf</artifactId>
+            <artifactId>compiled-locales-swf</artifactId>
             <version>1.0.0-SNAPSHOT</version>
             <type>swf</type>
         </dependency>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/957c1e19/maven-flex-plugin/examples/i18n/runtime-locales/pom.xml
----------------------------------------------------------------------
diff --git a/maven-flex-plugin/examples/i18n/runtime-locales/pom.xml 
b/maven-flex-plugin/examples/i18n/runtime-locales/pom.xml
index 635fc80..3a3a8d2 100644
--- a/maven-flex-plugin/examples/i18n/runtime-locales/pom.xml
+++ b/maven-flex-plugin/examples/i18n/runtime-locales/pom.xml
@@ -28,7 +28,7 @@
         <version>1.0.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>runtime-locals</artifactId>
+    <artifactId>runtime-locales</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>pom</packaging>
 

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/957c1e19/maven-flex-plugin/examples/i18n/runtime-locales/swf/pom.xml
----------------------------------------------------------------------
diff --git a/maven-flex-plugin/examples/i18n/runtime-locales/swf/pom.xml 
b/maven-flex-plugin/examples/i18n/runtime-locales/swf/pom.xml
index d6f6f7d..54818c6 100644
--- a/maven-flex-plugin/examples/i18n/runtime-locales/swf/pom.xml
+++ b/maven-flex-plugin/examples/i18n/runtime-locales/swf/pom.xml
@@ -24,11 +24,11 @@
 
     <parent>
         <groupId>org.apache.flex.examples.i18n</groupId>
-        <artifactId>runtime-locals</artifactId>
+        <artifactId>runtime-locales</artifactId>
         <version>1.0.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>runtime-locals-swf</artifactId>
+    <artifactId>runtime-locales-swf</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>swf</packaging>
 
@@ -41,6 +41,7 @@
                 <version>7.1.0-SNAPSHOT</version>
                 <extensions>true</extensions>
                 <configuration>
+                    <debug>true</debug>
                     <localesRuntime>
                         <locale>en_US</locale>
                         <locale>de_DE</locale>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/957c1e19/maven-flex-plugin/examples/i18n/runtime-locales/swf/src/main/flex/Main.mxml
----------------------------------------------------------------------
diff --git 
a/maven-flex-plugin/examples/i18n/runtime-locales/swf/src/main/flex/Main.mxml 
b/maven-flex-plugin/examples/i18n/runtime-locales/swf/src/main/flex/Main.mxml
index ea188bc..db86365 100644
--- 
a/maven-flex-plugin/examples/i18n/runtime-locales/swf/src/main/flex/Main.mxml
+++ 
b/maven-flex-plugin/examples/i18n/runtime-locales/swf/src/main/flex/Main.mxml
@@ -19,12 +19,62 @@
 -->
 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
                xmlns:s="library://ns.adobe.com/flex/spark"
-               xmlns:mx="library://ns.adobe.com/flex/mx">
+               creationComplete="onCreationComplete(event)">
 
     <fx:Metadata>
         [ResourceBundle("myresources")]
     </fx:Metadata>
 
-    <s:Label text="{resourceManager.getString('myresources','greeting')}"/>
+    <fx:Script>
+      <![CDATA[
+        import mx.collections.ArrayCollection;
+        import mx.events.FlexEvent;
+        import mx.events.ResourceEvent;
+        import mx.modules.ModuleBase;
+
+        import spark.events.IndexChangeEvent;
+
+        // Actually I don't quite know why I need to do this ...
+        // without it, I get an error, that this class is missing.
+        private var tst:ModuleBase = null;
+
+        [Bindable]
+        private var locales:ArrayCollection = new ArrayCollection([{label: 
"English", locale: "en_US"},
+            {label: "German", locale: "de_DE"}]);
+
+        private function onCreationComplete(event:FlexEvent):void {
+            if("en" == Capabilities.language) {
+                localeSelector.selectedItem = locales.getItemAt(0);
+            } else if("de" == Capabilities.language) {
+                localeSelector.selectedItem = locales.getItemAt(1);
+            }
+            onLanguageChange();
+        }
+
+        private function onLanguageChange(event:IndexChangeEvent = null):void {
+            var selectedLocale:String = 
String(localeSelector.selectedItem.locale);
+
+            // Ensure that you are not loading the same resource module more 
than once.
+            if (resourceManager.getLocales().indexOf(selectedLocale) != -1) {
+                completeHandler(null);
+            } else {
+                var resourceModuleURL:String =
+                        "./locales/runtime-locales-swf-1.0.0-SNAPSHOT-" + 
selectedLocale + ".swf";
+                var eventDispatcher:IEventDispatcher = 
resourceManager.loadResourceModule(resourceModuleURL);
+                eventDispatcher.addEventListener(ResourceEvent.COMPLETE, 
completeHandler);
+            }
+        }
+
+        private function completeHandler(event:ResourceEvent):void {
+            resourceManager.localeChain = [localeSelector.selectedItem.locale];
+        }
+
+        ]]>
+   </fx:Script>
+
+    <s:VGroup>
+        <s:ComboBox id="localeSelector" dataProvider="{locales}" 
change="onLanguageChange(event)"/>
+        <s:Label text="{resourceManager.getString('myresources','greeting')}"/>
+    </s:VGroup>
 
 </s:Application>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/957c1e19/maven-flex-plugin/examples/i18n/runtime-locales/war/pom.xml
----------------------------------------------------------------------
diff --git a/maven-flex-plugin/examples/i18n/runtime-locales/war/pom.xml 
b/maven-flex-plugin/examples/i18n/runtime-locales/war/pom.xml
index 1403603..d1d753e 100644
--- a/maven-flex-plugin/examples/i18n/runtime-locales/war/pom.xml
+++ b/maven-flex-plugin/examples/i18n/runtime-locales/war/pom.xml
@@ -24,11 +24,11 @@
 
     <parent>
         <groupId>org.apache.flex.examples.i18n</groupId>
-        <artifactId>runtime-locals</artifactId>
+        <artifactId>runtime-locales</artifactId>
         <version>1.0.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>runtime-locals-war</artifactId>
+    <artifactId>runtime-locales-war</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>war</packaging>
 
@@ -37,7 +37,7 @@
         perform the filtering.
     -->
     <properties>
-        <swf>swf-1.0.0-SNAPSHOT</swf>
+        <swf>runtime-locales-swf-1.0.0-SNAPSHOT</swf>
         <width>100%</width>
         <height>100%</height>
         <title>My First Application</title>
@@ -107,7 +107,7 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.flex.examples.i18n</groupId>
-            <artifactId>runtime-locals-swf</artifactId>
+            <artifactId>runtime-locales-swf</artifactId>
             <version>1.0.0-SNAPSHOT</version>
             <type>swf</type>
         </dependency>

Reply via email to