royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [royale-asjs] branch develop updated: rudimentary localized string implementation
Date Tue, 07 Nov 2017 17:11:48 GMT
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new a1498d0  rudimentary localized string implementation
a1498d0 is described below

commit a1498d05f3ccefe311a26d8d6608874561303462
Author: Alex Harui <aharui@apache.org>
AuthorDate: Tue Nov 7 09:11:33 2017 -0800

    rudimentary localized string implementation
---
 .../Core/src/main/resources/basic-manifest.xml     |   1 +
 .../org/apache/royale/core/ILocalizedValuesImpl.as |  68 ++++++++++++
 .../royale/core/SimpleLocalizedValuesImpl.as       | 116 +++++++++++++++++++++
 manualtests/LocaleTest/build.xml                   |  44 ++++++++
 manualtests/LocaleTest/src/LocaleTest.mxml         |  49 +++++++++
 .../LocaleTest/src/locale/de_DE/main.properties    |  22 ++++
 .../LocaleTest/src/locale/en_US/main.properties    |  22 ++++
 7 files changed, 322 insertions(+)

diff --git a/frameworks/projects/Core/src/main/resources/basic-manifest.xml b/frameworks/projects/Core/src/main/resources/basic-manifest.xml
index e58692a..5556ce8 100644
--- a/frameworks/projects/Core/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Core/src/main/resources/basic-manifest.xml
@@ -31,6 +31,7 @@
     <component id="SimpleStatesImpl" class="org.apache.royale.core.SimpleStatesImpl"/>
     <component id="MXMLDragInitiator" class="org.apache.royale.core.MXMLDragInitiator"
/>
     <component id="CallLaterBead" class="org.apache.royale.core.CallLaterBead" />
+    <component id="SimpleLocalizedValuesImpl" class="org.apache.royale.core.SimpleLocalizedValuesImpl"/>
 
     <component id="BindableCSSStyles" class="org.apache.royale.core.BindableCSSStyles"/>
     <component id="BindableCSSStylesWithFlex" class="org.apache.royale.core.BindableCSSStylesWithFlex"/>
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ILocalizedValuesImpl.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ILocalizedValuesImpl.as
new file mode 100644
index 0000000..f1177a6
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ILocalizedValuesImpl.as
@@ -0,0 +1,68 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.core
+{
+    /**
+     *  The ILocalizedValuesImpl interface is the basic interface for the subsystem that
+     *  provides localized values to components.  In Royale, different interfaces and
+	 *  implementations will handle different aspects of localization.  For example,
+	 *  implementations of this interface returns strings and possibly other values
+	 *  stored in the application, whereas a different interface will tackle date
+	 *  formatting, yet another may take on date parsing, because, per the 
+	 *  pay-as-you-go (PAYG) principle, applications don't need to carry every
+	 *  localization feature if they don't need them.
+     *  
+     *  @see org.apache.royale.core.SimpleLocalizedValuesImpl
+     * 
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+     */
+	public interface ILocalizedValuesImpl extends IBead
+	{
+        /**
+         *  Returns a value for a given object based on a property name,
+         *  and optionally, the current state, and a set of property value pairs.
+         *
+         *  @param bundleName The name of a property bundle.
+         *  @param key The name of a value in the bundle
+         *  @return A value or undefined
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+		function getValue(bundleName:String, key:String):*;
+
+		/**
+		 *  Determines the locale(s) to use for getting the values.
+		 *
+		 *  @param locales A comma delimited list of locales.
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.0
+		 */
+		function set localeChain(locales:String):void;
+        
+    }
+}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleLocalizedValuesImpl.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleLocalizedValuesImpl.as
new file mode 100644
index 0000000..c7564b9
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/SimpleLocalizedValuesImpl.as
@@ -0,0 +1,116 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.core
+{
+	import org.apache.royale.events.EventDispatcher;
+	
+    /**
+     *  The SimpleLocalizedValuesImpl class implements a simple getValue
+	 *  implementation that is sufficient for many very simple applications.  
+	 *  Every key in every bundle must be provided in every locale.  There
+	 *  is no fall-through logic to the next locale.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+     */
+	public class SimpleLocalizedValuesImpl extends EventDispatcher implements ILocalizedValuesImpl
+	{
+		public function SimpleLocalizedValuesImpl()
+		{
+			super();
+		}
+		
+		private var mainClass:Object;
+		private var locale:String;
+		
+        /**
+         *  The map of bundles.  The format is not documented and it is not recommended
+         *  to manipulate this structure directly.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+		public var bundles:Object = {};
+		
+        /**
+         *  @copy org.apache.royale.core.ILocalizedValuesImpl#getValue()
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+		public function getValue(bundleName:String, key:String):*
+		{
+			var actualBundleName:String = locale + bundleName;
+			var bundle:Object = bundles[actualBundleName];
+			if (!bundle)
+			{
+				bundle = {};
+				bundles[actualBundleName] = bundle;
+				// go look for the bundle
+				var data:String = mainClass[actualBundleName];
+				var rows:Array = data.split("\n");
+				var n:int = rows.length;
+				for (var i:int = 0; i < n; i++)
+				{
+					var row:String = rows[i];
+					if (row.charAt(0) == "#") 
+						continue; // comments
+					var parts:Array = row.split("=");
+					if (parts.length != 2)
+						continue; // blank line?
+					bundle[parts[0]] = parts[1];
+				}				
+			}
+			return bundle[key];
+		}
+				
+        /**
+         *  @copy org.apache.royale.core.ILocalizedValuesImpl#localeChain()
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+		public function set localeChain(value:String):void
+		{
+			locale = value;
+		}
+        
+        /**
+         *  @copy org.apache.royale.core.IBead#strand()
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+        public function set strand(value:IStrand):void
+        {
+            this.mainClass = value;
+        }
+
+    }
+}
diff --git a/manualtests/LocaleTest/build.xml b/manualtests/LocaleTest/build.xml
new file mode 100644
index 0000000..63ba446
--- /dev/null
+++ b/manualtests/LocaleTest/build.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<!--
+
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+-->
+
+
+<project name="localetest" default="main" basedir=".">
+    <property name="ROYALE_HOME" location="../.."/>
+    <property name="example" value="LocaleTest" />
+    
+    <property file="${ROYALE_HOME}/env.properties"/>
+    <property environment="env"/>
+	<property file="${ROYALE_HOME}/build.properties"/>
+    <property name="FLEX_HOME" value="${ROYALE_HOME}"/>
+	
+    
+    <include file="${basedir}/../build_example.xml" />
+
+    <target name="main" depends="clean,build_example.compile" description="Clean build
of ${example}">
+    </target>
+    
+    <target name="clean">
+        <delete dir="${basedir}/bin" failonerror="false" />
+        <delete dir="${basedir}/bin-debug" failonerror="false" />
+        <delete dir="${basedir}/bin-release" failonerror="false" />
+        <delete dir="${basedir}/target" failonerror="false" />
+    </target>
+
+</project>
diff --git a/manualtests/LocaleTest/src/LocaleTest.mxml b/manualtests/LocaleTest/src/LocaleTest.mxml
new file mode 100644
index 0000000..d12b2b3
--- /dev/null
+++ b/manualtests/LocaleTest/src/LocaleTest.mxml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-->
+<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+                   xmlns:js="library://ns.apache.org/royale/basic" 
+				   applicationComplete="setit()">
+	<fx:Script>
+		<![CDATA[
+			private function setit():void
+			{
+				resourceManager.localeChain = "de_DE";
+				lbl.text = resourceManager.getValue("main", "hello");
+			}
+			
+			[Embed("locale/en_US/main.properties", mimeType="text/plain")]
+			public var en_USmain:String;
+			[Embed("locale/de_DE/main.properties", mimeType="text/plain")]
+			public var de_DEmain:String;
+			
+		]]>
+	</fx:Script>
+    <js:valuesImpl>
+        <js:SimpleCSSValuesImpl />
+    </js:valuesImpl>
+    <js:initialView>
+        <js:View>
+        	<js:Label id="lbl"/>
+        </js:View>
+    </js:initialView>
+	<js:beads>
+		<js:SimpleLocalizedValuesImpl id="resourceManager" />
+	</js:beads>
+</js:Application>
diff --git a/manualtests/LocaleTest/src/locale/de_DE/main.properties b/manualtests/LocaleTest/src/locale/de_DE/main.properties
new file mode 100644
index 0000000..3afbcc0
--- /dev/null
+++ b/manualtests/LocaleTest/src/locale/de_DE/main.properties
@@ -0,0 +1,22 @@
+################################################################################
+##
+##  Licensed to the Apache Software Foundation (ASF) under one or more
+##  contributor license agreements.  See the NOTICE file distributed with
+##  this work for additional information regarding copyright ownership.
+##  The ASF licenses this file to You under the Apache License, Version 2.0
+##  (the "License"); you may not use this file except in compliance with
+##  the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+##  Unless required by applicable law or agreed to in writing, software
+##  distributed under the License is distributed on an "AS IS" BASIS,
+##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+##  See the License for the specific language governing permissions and
+##  limitations under the License.
+##
+################################################################################
+
+# Sample string bundle
+title=LocaleTest
+hello=Hallo Welt
diff --git a/manualtests/LocaleTest/src/locale/en_US/main.properties b/manualtests/LocaleTest/src/locale/en_US/main.properties
new file mode 100644
index 0000000..0540c77
--- /dev/null
+++ b/manualtests/LocaleTest/src/locale/en_US/main.properties
@@ -0,0 +1,22 @@
+################################################################################
+##
+##  Licensed to the Apache Software Foundation (ASF) under one or more
+##  contributor license agreements.  See the NOTICE file distributed with
+##  this work for additional information regarding copyright ownership.
+##  The ASF licenses this file to You under the Apache License, Version 2.0
+##  (the "License"); you may not use this file except in compliance with
+##  the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+##  Unless required by applicable law or agreed to in writing, software
+##  distributed under the License is distributed on an "AS IS" BASIS,
+##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+##  See the License for the specific language governing permissions and
+##  limitations under the License.
+##
+################################################################################
+
+# Sample string bundle
+title=LocaleTest
+hello=Hello World

-- 
To stop receiving notification emails like this one, please contact
['"commits@royale.apache.org" <commits@royale.apache.org>'].

Mime
View raw message