﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digital Primates&#187; i18n</title>
	<atom:link href="http://www.digitalprimates.net/author/category/i18n/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digitalprimates.net</link>
	<description>Development and Consulting</description>
	<lastBuildDate>Thu, 16 May 2013 21:25:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Internationalizing Flex 2 Apps Pt 2</title>
		<link>http://www.digitalprimates.net/author/tapper/2006/10/13/internationalizing-flex-2-apps-pt-2/</link>
		<comments>http://www.digitalprimates.net/author/tapper/2006/10/13/internationalizing-flex-2-apps-pt-2/#comments</comments>
		<pubDate>Fri, 13 Oct 2006 11:10:00 +0000</pubDate>
		<dc:creator>tapper</dc:creator>
				<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://test.digitalprimates.net/2006/10/13/internationalizing-flex-2-apps-pt-2/</guid>
		<description><![CDATA[As the 2nd part of my 3 part series on internationalizing Flex Applications, this article will explore the use of multiple instances of the ResourceBundle class to allow for run time switching of locales.&#160; As you may recall from the &#8230; <a href="http://www.digitalprimates.net/author/tapper/2006/10/13/internationalizing-flex-2-apps-pt-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As the 2nd part of my <a href="http://jeff.mxdj.com/internationalizing_flex_2_applications.htm">3 part series</a> on internationalizing Flex Applications, this article will explore the use of multiple instances of the ResourceBundle class to allow for run time switching of locales.&#160; As you may recall from the <a href="http://jeff.mxdj.com/internationalizing_flex_apps_pt_1.htm">first article on this subject</a>, the native use of the ResourceBundle class requires separate compiled swfs for each language.&#160; This is not always desirable, and there are times when you may want to allow for switching of languages at run time.&#160;&#160;One strategy I&#8217;ve used successfully for this is to trick the flex compiler and have several different properties in the same locale folder, and to create separate instances of the ResourceBundle class for each of them.&#160; This way, its a fairly simple process to determine what the current locale is, and to pull the labels from that ResourceBundle.&#160; To start, I took 3 properties files and placed them in a single directory.&#160; </p>
<p>Here is a simple example of how to get it working:</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; <br />&#160;layout=&quot;vertical&quot; creationComplete=&quot;doLangChange()&quot;&gt;<br />&#160;&lt;mx:Script&gt;<br />&#160;&#160;&lt;![CDATA[<br />&#160;&#160;&#160;import mx.formatters.DateFormatter;<br />&#160;&#160;<br />&#160;&#160;&#160;import mx.resources.ResourceBundle;<br />&#160;&#160;&#160;[ResourceBundle(&quot;helloWorld_us&quot;)]<br />&#160;&#160;&#160;private var rb_us:ResourceBundle;<br />&#160;&#160;&#160;[ResourceBundle(&quot;helloWorld_uk&quot;)]<br />&#160;&#160;&#160;private var rb_uk:ResourceBundle;<br />&#160;&#160;&#160;[ResourceBundle(&quot;helloWorld_fr&quot;)]<br />&#160;&#160;&#160;private var rb_fr:ResourceBundle;<br />&#160;&#160;&#160;[Bindable]<br />&#160;&#160;&#160;private var today:Date = new Date();<br />&#160;&#160;&#160;[Bindable(event=&quot;langChange&quot;)]<br />&#160;&#160;&#160;private function geti18nText(key:String):String{<br />&#160;&#160;&#160;&#160;return this[&quot;rb_&quot;+lang.selectedItem.lang].getString(key);<br />&#160;&#160;&#160;}<br />&#160;&#160;&#160;[Bindable(event=&quot;langChange&quot;)]<br />&#160;&#160;&#160;private function geti18nDate(dt:Date):String{<br />&#160;&#160;&#160;&#160;var formatter:DateFormatter = new DateFormatter();<br />&#160;&#160;&#160;&#160;formatter.formatString = geti18nText(&quot;dtformat&quot;);<br />&#160;&#160;&#160;&#160;return formatter.format(dt);<br />&#160;&#160;&#160;}<br />&#160;&#160;&#160;private function doLangChange():void{<br />&#160;&#160;&#160;&#160;var e:Event = new Event(&quot;langChange&quot;);<br />&#160;&#160;&#160;&#160;this.dispatchEvent(e);<br />&#160;&#160;&#160;}<br />&#160;&#160;]]&gt;<br />&#160;&lt;/mx:Script&gt;<br />&#160;&lt;mx:DateFormatter id=&quot;smeNme&quot; formatString=&quot;MM/DD/YYYY&quot;/&gt;<br />&#160;&lt;mx:ApplicationControlBar dock=&quot;true&quot;&gt;<br />&#160;&#160;&lt;mx:ComboBox id=&quot;lang&quot; change=&quot;doLangChange()&quot;&gt;<br />&#160;&#160;&#160;&lt;mx:dataProvider&gt;<br />&#160;&#160;&#160;&#160;&lt;mx:Object label=&quot;US English&quot; lang=&quot;us&quot;/&gt;<br />&#160;&#160;&#160;&#160;&lt;mx:Object label=&quot;UK English&quot; lang=&quot;uk&quot;/&gt;<br />&#160;&#160;&#160;&#160;&lt;mx:Object label=&quot;French&quot; lang=&quot;fr&quot;/&gt;<br />&#160;&#160;&#160;&lt;/mx:dataProvider&gt;<br />&#160;&#160;&lt;/mx:ComboBox&gt;<br />&#160;&lt;/mx:ApplicationControlBar&gt;<br />&#160;&lt;mx:Label fontSize=&quot;50&quot; text=&quot;{geti18nText('hello')}&quot;/&gt;<br />&#160;&lt;mx:Label fontSize=&quot;50&quot; text=&quot;{geti18nText('welcome')}&quot;/&gt;<br />&#160;&lt;mx:Label fontSize=&quot;50&quot; text=&quot;{geti18nDate(today)}&quot;/&gt;<br />&lt;/mx:Application&gt;</pre>
<p>I named each file based on the language it was there to support (<font face="Arial">helloWorld_fr.properties, <font face="Arial">helloWorld_uk.properties, <font face="Arial">helloWorld_us.properties).&#160; Notice that there is ResourceBundle instance for each of the three files.&#160; I&#8217;ve also added some simple functions to get the data from these files (geti18nText, geti18nDate).&#160; Bare in mind, this is a simplistic example.&#160; In real world apps, I tend to have a singleton responsible for embedding and retrieving the data from the files.&#160; But, even in this simple case, you can see the power of it, as simply switching the selected language in the combo box instantly translates the labels and dates to the appropriate format.</font></font></font></p>
<p>Remember to add a compiler argument to specify the proper directory for the locale files.&#160; In my case, all three files where in a locales/multi directory, so i added the argument:&#160;<font face="Arial">&#160;-sp ../locales/multi</font></p>
<p>&#160;</p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalprimates.net/author/tapper/2006/10/13/internationalizing-flex-2-apps-pt-2/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Internationalizing Flex 2 Applications</title>
		<link>http://www.digitalprimates.net/author/tapper/2006/09/12/internationalizing-flex-2-applications/</link>
		<comments>http://www.digitalprimates.net/author/tapper/2006/09/12/internationalizing-flex-2-applications/#comments</comments>
		<pubDate>Tue, 12 Sep 2006 12:09:00 +0000</pubDate>
		<dc:creator>tapper</dc:creator>
				<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://test.digitalprimates.net/2006/09/12/internationalizing-flex-2-applications/</guid>
		<description><![CDATA[I&#8217;ll be speaking at the first ever meeting of the New York Flex User Group, this thursday 9/14, on the subject of &#34;Strategies for Internationalizing Flex Applications.&#34;&#160; I&#8217;m also in the midst of writing a 3 part blog series on &#8230; <a href="http://www.digitalprimates.net/author/tapper/2006/09/12/internationalizing-flex-2-applications/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be speaking at the first ever meeting of the <a target="_blank" href="http://www.nyflex.org">New York Flex User Group</a>, this thursday 9/14, on the subject of &quot;Strategies for Internationalizing Flex Applications.&quot;&#160; I&#8217;m also in the midst of writing a 3 part blog series on the topic.&#160; For those of you who can&#8217;t wait for parts 2 and 3, come on down to the meeting on Thursday, otherwise, you&#8217;ll have to wait until i finish writing the other two.</p>
<p><a href="http://jeff.mxdj.com/internationalizing_flex_apps_pt_1.htm">Part 1: Use of the ResourceBundle class</a></p>
<p><a href="http://jeff.mxdj.com/internationalizing_flex_2_apps_pt_2.htm">Part 2: Allowing run-time locale switching with the ResourceBundle class</a></p>
<p>Part 3: Loading locale specific XML at run-time.</p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalprimates.net/author/tapper/2006/09/12/internationalizing-flex-2-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internationalizing Flex apps Pt 1</title>
		<link>http://www.digitalprimates.net/author/tapper/2006/09/01/internationalizing-flex-apps-pt-1/</link>
		<comments>http://www.digitalprimates.net/author/tapper/2006/09/01/internationalizing-flex-apps-pt-1/#comments</comments>
		<pubDate>Fri, 01 Sep 2006 07:09:00 +0000</pubDate>
		<dc:creator>tapper</dc:creator>
				<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex2]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://test.digitalprimates.net/2006/09/01/internationalizing-flex-apps-pt-1/</guid>
		<description><![CDATA[This is part 1 of a 3 part series on Internationalizng flex apps. One of the many features available in Flex 2.0 is a ResourceBundle class, which allows for a standardized approach for internationalizing applications.&#160; Many recent projects of mine &#8230; <a href="http://www.digitalprimates.net/author/tapper/2006/09/01/internationalizing-flex-apps-pt-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><font face="Arial">This is part 1 of a <a href="http://jeff.mxdj.com/internationalizing_flex_2_applications.htm">3 part series </a>on Internationalizng flex apps.</font></p>
<p><font face="Arial"><br />
</font></p>
<p><font face="Arial">One of the many features available in Flex 2.0 is a ResourceBundle class, which allows for a standardized approach for internationalizing applications.&#160; Many recent projects of mine have had requirements that we build applications so that they can easily be ported to other languages.&#160; Traditionally, I&#8217;ve used a series of XML files for this, one for each of the various languages which need to be supported.&#160; This strategy is still viable, and I still use it on some of my projects.&#160; I&#8217;ve recently discovered a different approach, which is available natively in Flex.&#160; Flex provides a ResourceBundle class, which allows you to set up your text in .properties files (identical structure that you would use for internationalizing java applications).&#160; These properties files are arranged in a folder structure, relating to the language and country, so, the properties file for US English would be in a folder called en_US, the file for the UK would be en_UK, while the French would be in fr_FR.&#160; The strucutre of the files is very simple, like this:</font></p>
<pre>hello = Hello World<br />welcome = Welcome!</pre>
<p>or, for the french version</p>
<pre>hello = Bonjour Monde<br />welcome = Bienvenue</pre>
<p>To use these in an application, you have two options:&#160; you can use the @Resource command each time you need a value, or, you can declare a variable for the ResourceBundle, and use the getString(), getNumber(), getBoolean(), etc methods.&#160; In this example, you can see both being used:</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;&gt;<br />&#160;&lt;mx:Script&gt;<br />&#160;&#160;&lt;![CDATA[<br />&#160;&#160;&#160;import mx.resources.ResourceBundle;<br />&#160;&#160;&#160;[ResourceBundle(&quot;helloWorld&quot;)]<br />&#160;&#160;&#160;private static var rb:ResourceBundle;<br />&#160;&#160;&#160;private function geti18nText(key:String):String{<br />&#160;&#160;&#160;&#160;return rb.getString(key);<br />&#160;&#160;&#160;}<br />&#160;&#160;]]&gt;<br />&#160;&lt;/mx:Script&gt;<br />&#160;&lt;mx:Label fontSize=&quot;50&quot; text=&quot;@Resource(key='hello', bundle='helloWorld')&quot;/&gt;<br />&#160;&lt;mx:Label fontSize=&quot;50&quot; text=&quot;{geti18nText('welcome')}&quot;/&gt;<br />&lt;/mx:Application&gt;</pre>
<p>So, here you can see the top label uses the @Resource directive to specifically pull the hello key from the helloWorld bundle.&#160; If the application is compiled for en_US, that key will show &quot;Hello World,&quot; compile the same app for fr_FR, and it will read &quot;Bonjour Monde&quot;</p>
<p>The remaining trick is to tell the compiler which language to use, and where to find the files.&#160;&#160;&#160; You can do this from the command line like this:</p>
<p>&#160;&#160;mxmlc -locale en_UK -sp ../locales/{locale} -o HelloWorld_en_UK.swf I18N_HelloWorld.mxml<br />
&#160;&#160;mxmlc -locale&#160;fr_FR -sp ../locales/{locale} -o HelloWorld_fr_FR.swf I18N_HelloWorld.mxml</p>
<p>or, you can specifiy compiler arguments in flexbuilder </p>
<p><font face="Arial">-locale en_US -sp ../locales/{locale}</font></p>
<p>I&#8217;ll put a zip of the files to use this up here over the weekend.</p>
<p>In my next article, I&#8217;ll explore how i often use xml files as an alternative to this&#8230;</p>
<p>&#160;</p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalprimates.net/author/tapper/2006/09/01/internationalizing-flex-apps-pt-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
