Allow custom locale URLs to be set via a parameter
authorTom Hughes <tom@compton.nu>
Sun, 25 Mar 2012 11:10:10 +0000 (12:10 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 25 Mar 2012 11:46:48 +0000 (12:46 +0100)
l10n/map/LocalizationMap.mxml
net/systemeD/potlatch2/CustomLocaleCommand.as [new file with mode: 0644]
potlatch2.mxml

index 3b8d932..b887854 100644 (file)
@@ -7,7 +7,7 @@
   <!-- Support for Locale ResourceBundle changes -->
   <mx:Script>
     <![CDATA[
-      import org.babelfx.commands.ExternalLocaleCommand;
+      import net.systemeD.potlatch2.CustomLocaleCommand;
       import org.babelfx.events.LocaleEvent;
       import mx.resources.ResourceManager;
       import mx.resources.IResourceManager;
@@ -46,9 +46,9 @@
   </mx:Script>
 
   <commandFactory>
-    <factory:ClassFactory generator="{ExternalLocaleCommand}">
+    <factory:ClassFactory generator="{CustomLocaleCommand}">
       <factory:properties>
-        <mx:Object externalPath="locales/\{0\}.swf"/>
+        <mx:Object defaultExternalPath="locales/\{0\}.swf"/>
       </factory:properties>
     </factory:ClassFactory>
   </commandFactory>
diff --git a/net/systemeD/potlatch2/CustomLocaleCommand.as b/net/systemeD/potlatch2/CustomLocaleCommand.as
new file mode 100644 (file)
index 0000000..b4b8160
--- /dev/null
@@ -0,0 +1,24 @@
+package net.systemeD.potlatch2 {
+    import org.babelfx.commands.ExternalLocaleCommand;
+    import net.systemeD.halcyon.Globals;
+
+    public class CustomLocaleCommand extends ExternalLocaleCommand {
+        public var defaultExternalPath:String;
+
+        override protected function loadLocale(locale:String):void {
+            externalPath = defaultExternalPath;
+
+            if (Globals.vars.locale_paths) {
+                for each (var path:String in Globals.vars.locale_paths.split(";")) {
+                    var args:Array = path.split("=");
+
+                    if (args[0] == locale) {
+                        externalPath = args[1];
+                    }
+                }
+            }
+
+            super.loadLocale(locale);
+        }
+    }
+}
index ea4ed06..32bc8d8 100644 (file)
             if (loaderInfo.parameters['locale'] && loaderInfo.parameters['locale']!='en_US') {
                 // we don't bother with localisation if the user is en_US, as P2 is in English by default
                 Globals.vars.locale = loaderInfo.parameters['locale'];
+                Globals.vars.locale_paths = loaderInfo.parameters['locale_paths'];
                 dispatchEvent(new LocaleEvent(LocaleEvent.LOAD_LOCALE, loaderInfo.parameters['locale']));
                 dispatchEvent(new LocaleEvent(LocaleEvent.LOAD_LOCALE, 'en_US')); // think en_US is default
                 resourceManager.localeChain = [loaderInfo.parameters['locale'], 'en_US'];