Add BabelFx translation library, with two example translations
authorAndy Allan <gravitystorm@gmail.com>
Fri, 18 Feb 2011 14:30:32 +0000 (14:30 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Fri, 18 Feb 2011 14:30:32 +0000 (14:30 +0000)
build.xml
l10n/locale/en_GB/help_dialog.properties [new file with mode: 0644]
l10n/locale/fr_FR/help_dialog.properties [new file with mode: 0644]
l10n/map/LocalizationMap.mxml [new file with mode: 0644]
lib/Framework_BabelFx.swc [new file with mode: 0644]
net/systemeD/potlatch2/help/HelpDialog.mxml
potlatch2.mxml

index 200c0e9..28a5997 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -28,7 +28,7 @@
   </target>
 
   <!-- delete and create the DEPLOY dir again -->
-  <target name="init" depends="git-buildnumber,svn-buildnumber">
+  <target name="init" depends="git-buildnumber,svn-buildnumber,deployLocales">
     <echo>Build Number ${build_number}</echo>
     <copy file="version.as.template" tofile="version.as" overwrite="true" />
     <replace file="version.as" token="@@@buildnumber@@@" value="${build_number}" />
 
   <target name="test" depends="init, compileTestRunner, runTestsAndReport" description="Compiles unit tests and generates test report artifacts." />
 
+  <!-- ======================================= -->
+  <!-- Locale Targets -->
+  <!-- ======================================= -->
+
+  <!-- Deploy compiled Localization Resource Bundles and resources. -->
+  <macrodef name="deployLocale" description="Deploying the compiled swfs">
+    <attribute name="locale" default="en_GB"/>
+    <sequential>
+      <echo>Copying @{locale}.swf to deploy directory...</echo>
+
+      <mkdir dir="${basedir}/resources/locales"/>
+      <copy file="${basedir}/l10n/locale/bundles/@{locale}.swf" tofile="${basedir}/resources/locales/@{locale}.swf" />
+
+    </sequential>
+  </macrodef>
+
+  <!-- Compiles Localization Resource Bundle. -->
+  <macrodef name="compileLocale" description="Compiles the Resource package for the given locale">
+    <attribute name="locale" default="en_GB"/>
+    <sequential>
+
+      <!--
+      Invoke MXMLC
+      - also include the MX Framework locale assets
+      Note: this requires user to invoke copyLocale.exe prior to running this script
+      -->
+      <mxmlc output="${basedir}/l10n/locale/bundles/@{locale}.swf">
+<!--         <locale>@{locale}</locale> -->
+
+
+        <source-path path-element="${basedir}/l10n/locale/@{locale}"/>
+        <include-resource-bundles>help_dialog</include-resource-bundles>
+
+<!--        <source-path path-element="${src.dir}/locale/framework/bundles/{locale}/src"/>
+        <include-resource-bundles>collections</include-resource-bundles>
+        <include-resource-bundles>containers</include-resource-bundles>
+        <include-resource-bundles>controls</include-resource-bundles>
+        <include-resource-bundles>core</include-resource-bundles>
+        <include-resource-bundles>effects</include-resource-bundles>
+        <include-resource-bundles>formatters</include-resource-bundles>
+        <include-resource-bundles>logging</include-resource-bundles>
+        <include-resource-bundles>SharedResources</include-resource-bundles>
+        <include-resource-bundles>skins</include-resource-bundles>
+        <include-resource-bundles>states</include-resource-bundles>
+        <include-resource-bundles>styles</include-resource-bundles>
+        <include-resource-bundles>utils</include-resource-bundles>
+        <include-resource-bundles>validators</include-resource-bundles>-->
+      </mxmlc>
+
+    </sequential>
+  </macrodef>
+
+  <target name="buildLocales">
+    <echo>Building Localization .swf's</echo>
+    <compileLocale locale="en_GB" />
+    <compileLocale locale="fr_FR" />
+  </target>
+
+
+  <target name="deployLocales" depends="buildLocales">
+    <echo>Deploying the compiled swf and assets package for the given locales</echo>
+    <deployLocale locale="en_GB" />
+    <deployLocale locale="fr_FR" />
+  </target>
+
 </project>
diff --git a/l10n/locale/en_GB/help_dialog.properties b/l10n/locale/en_GB/help_dialog.properties
new file mode 100644 (file)
index 0000000..7083728
--- /dev/null
@@ -0,0 +1,6 @@
+# en_GB resources file
+
+help.gettingStarted = Getting Started
+help.welcome = Welcome
+
+
diff --git a/l10n/locale/fr_FR/help_dialog.properties b/l10n/locale/fr_FR/help_dialog.properties
new file mode 100644 (file)
index 0000000..727b4d8
--- /dev/null
@@ -0,0 +1,4 @@
+# fr_FR resources file
+
+help.gettingStarted = De Commencer
+help.welcome = Bienvenue
\ No newline at end of file
diff --git a/l10n/map/LocalizationMap.mxml b/l10n/map/LocalizationMap.mxml
new file mode 100644 (file)
index 0000000..861ba06
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LocaleMap enableLog="true"
+    xmlns:mx="http://www.adobe.com/2006/mxml"
+    xmlns:factory="mx.core.*"
+    xmlns="library://ns.babelfx.org/l10n/flex/" >
+
+  <!-- Support for Locale ResourceBundle changes -->
+  <mx:Script>
+    <![CDATA[
+      import com.mindspace.l10n.commands.ExternalLocaleCommand;
+
+      import net.systemeD.potlatch2.help.HelpDialog;
+    ]]>
+  </mx:Script>
+
+  <commandFactory>
+    <factory:ClassFactory generator="{ExternalLocaleCommand}">
+      <factory:properties>
+        <mx:Object externalPath="locales/\{0\}.swf"/>
+      </factory:properties>
+    </factory:ClassFactory>
+  </commandFactory>
+
+  <!--
+  SmartResourceInjectors for targeted class instantiations. Instead of dependency injection of UI instances,
+  we use SRI(s) here to remove any need to know view hierarchy relationships... we simply want a reference
+  to the UI instance when ready.
+  -->
+
+  <SmartResourceInjector bundleName="help_dialog" target="{HelpDialog}">
+    <ResourceProxy property="gettingStarted.text" key="help.gettingStarted" />
+    <ResourceProxy property="welcome.label" key="help.welcome" />
+  </SmartResourceInjector>
+
+</LocaleMap>
\ No newline at end of file
diff --git a/lib/Framework_BabelFx.swc b/lib/Framework_BabelFx.swc
new file mode 100644 (file)
index 0000000..2f84eb7
Binary files /dev/null and b/lib/Framework_BabelFx.swc differ
index fa44bd6..3c73b34 100644 (file)
               ]]>
   </mx:Script>
   <mx:TabNavigator id="helpTN" width="100%" height="100%" styleName="helpTN" creationPolicy="all">
-    <mx:VBox label="Welcome" width="100%" height="100%">
+    <mx:VBox label="Welcome" id="welcome" width="100%" height="100%">
       <mx:Grid width="100%"><!-- prepare for a column of icons, at some point -->
         <mx:GridRow width="100%">
           <mx:GridItem width="100%">
         </mx:GridRow>
         <mx:GridRow width="100%">
           <mx:GridItem width="100%">
-            <mx:Label text="Getting Started" textAlign="center" width="100%" styleName="helpPageHeader" />
+            <mx:Label id="gettingStarted" text="Getting Started" textAlign="center" width="100%" styleName="helpPageHeader" />
           </mx:GridItem>
         </mx:GridRow>
         <mx:GridRow width="100%">
index b0861e2..00eb7b0 100644 (file)
@@ -51,6 +51,8 @@
         <mx:Button label="Save" icon="@Embed('embedded/upload.svg')" disabledIcon="@Embed('embedded/upload_disabled.svg')" styleName="appBarButton"
                        click="SaveManager.saveChanges();" id="saveButton" enabled="false"/>
     </mx:ApplicationControlBar>
+
+    <map:LocalizationMap xmlns:map="l10n.map.*" />
     
     <mx:HDividedBox width="100%" height="100%">
 
         import mx.managers.DragManager;
         import mx.core.DragSource;
         import mx.controls.Alert;
+        import com.mindspace.l10n.events.LocaleEvent;
 
         public var theMap:Map;
         public var theController:EditController;
 
                private function initApp():void {
 
+            /* For reasons that I don't yet understand, the en_US locale is the default and doesn't work at all. Use en_GB instead. */
+            /* Change this to another locale (e.g. fr_FR) to see the differences. This will obviously become done differently at some point. */
+            dispatchEvent(new LocaleEvent(LocaleEvent.LOAD_LOCALE,'en_GB'));
+
                        Globals.vars.map_area = map_area;
                        Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
                        var _root:IChildList = map_area.rawChildren;            // convenient local shorthand