<?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>dispatchEvent()™ &#187; resource bundles</title>
	<atom:link href="http://dispatchevent.org/tag/resource-bundles/feed/" rel="self" type="application/rss+xml" />
	<link>http://dispatchevent.org</link>
	<description>Collective thoughts on the Flash Platform, iOS, Unity, and any other technology we use.</description>
	<lastBuildDate>Mon, 23 Apr 2012 19:07:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Using %tokens% with Flex resource bundles</title>
		<link>http://dispatchevent.org/mims/using-tokens-with-flex-resource-bundles/</link>
		<comments>http://dispatchevent.org/mims/using-tokens-with-flex-resource-bundles/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 19:26:08 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[resource bundles]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[token]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=796</guid>
		<description><![CDATA[When I use Flex, I make extensive use of Resource Bundles for all but the most basic applications. In short, they allow you to keep all of your static string values (and non-string values) separated out of your code. That way, down the line it&#8217;s a very easy change when you want to localize the [...]]]></description>
			<content:encoded><![CDATA[<p>When I use Flex, I make extensive use of <a href="http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7fcf.html">Resource Bundles</a> for all but the most basic applications. In short, they allow you to keep all of your static string values (and non-string values) separated out of your code. That way, down the line it&#8217;s a very easy change when you want to localize the site in another language, rebrand it for another audience, or when a client asks you to change a button label or error message. Granted, this level of detail isn&#8217;t always necessary but I think it&#8217;s a good habit to get into even if it&#8217;s overkill for some projects.</p>
<p>But resource bundles can&#8217;t help you in every scenario. I often find myself needing to construct a sentence with live data inserted. For this, the resource strings are less helpful. For example, how would you write:</p>
<p><code>"At " + time + ", you received a message from " + userName + "."</code></p>
<p>With resource strings, you would have to do something like</p>
<pre>at=At
message=, you received a message from
period=.</pre>
<p>Which completely negates the whole point of using resource bundles. What to do?</p>
<h3>Token replacement</h3>
<p><img class="size-full wp-image-799 alignright" title="tokens" src="http://dispatchevent.org/wp-content/uploads/2009/12/tokens.jpg" alt="tokens" width="155" height="125" /><br />
What I really wanted was a way to inject data into the string. I&#8217;ve seen this done by use of tokens in other languages like <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html#//apple_ref/doc/uid/20000943">Objective-C</a> so I thought I&#8217;d give it a try. The result was surprisingly lightweight.</p>
<p>I created this utility that lets you use tokens (delimited by % signs) that can be replaced by live data when you retrieve the resource. Using this class, the example above would look more like this:</p>
<pre>receivedMessage=At %time%, you received a message from %userName%.

// then in your code
trace(ResourceStringUtil.getResoureceStringWithTokens("receivedMessage", {time: "11:49", userName: "Mims"}));

// displays
At 11:49, you received a message from Mims.</pre>
<p>Here&#8217;s the source code Feel free to use it and modify it for your purposes.</p>
<p><script src="http://gist.github.com/251904.js?file=ResourceStringUtil.as"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/using-tokens-with-flex-resource-bundles/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

