<?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>Froogloid &#187; android development blog</title>
	<atom:link href="http://www.froogloid.com/tag/android-development-blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.froogloid.com</link>
	<description>Mobile Application Development</description>
	<lastBuildDate>Wed, 07 Apr 2010 18:58:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Localizing an Android App</title>
		<link>http://www.froogloid.com/android-news/localizing-an-android-app</link>
		<comments>http://www.froogloid.com/android-news/localizing-an-android-app#comments</comments>
		<pubDate>Tue, 05 May 2009 15:02:28 +0000</pubDate>
		<dc:creator>Chris Fagan</dc:creator>
				<category><![CDATA[Android News]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[android design]]></category>
		<category><![CDATA[android development blog]]></category>
		<category><![CDATA[dan morril]]></category>
		<category><![CDATA[google android]]></category>
		<category><![CDATA[localizing]]></category>

		<guid isPermaLink="false">http://www.froogloid.com/?p=556</guid>
		<description><![CDATA[Hi everyone, I ran across and interesting post over @ the android developer group created by Dan Morril.  He discusses the ins and outs of localizing your android app for other markets.  I thought I&#8217;d repost it here.  Here&#8217;s a link to the original post:  https://groups.google.com/group/android-developers/web/localizing-android-apps-draft   Enjoy!



Localizing Android Apps [DRAFT]   
 







 

 









 
Android will run on many [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone, I ran across and interesting post over @ the android developer group created by Dan Morril.  He discusses the ins and outs of localizing your android app for other markets.  I thought I&#8217;d repost it here.  <span id="more-556"></span>Here&#8217;s a link to the original post:  <a href="https://groups.google.com/group/android-developers/web/localizing-android-apps-draft">https://groups.google.com/group/android-developers/web/localizing-android-apps-draft</a>   Enjoy!</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><span class="secttl">Localizing Android Apps [DRAFT]   </span></td>
<td align="right"> </td>
</tr>
</tbody>
</table>
<div>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td> </td>
<td width="100%" height="4" bgcolor="#ffffff"><img alt="" width="1" height="1" /></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div class="maincontboxhead">
<div id="moduleEditablePage1" class="module">
<div class="layout">
<div class="layoutregion">
<div id="g_body" style="overflow: auto;">
<p> </p>
<p>Android will run on many different devices in many different regions, and used by speakers of many different languages. To reach the most users in the most effective way, developers will want to localize their applications to the native languages spoken by the users they wish to reach.  This document explains how to localize an Android application.</p>
<h2>What You Should Know Already</h2>
<p>This is not an introduction to how to build Android applications; for that information, you can begin here: http://code.google.com/android/intro/index.html  This document assumes that you are generally familiar with Android resource loading, declarative UI building via Android&#8217;s XML system, and general Android development considerations such as Activity lifecycle.</p>
<h2>Introduction to the L10nDemo App</h2>
<p>To illustrate the concepts discussed in this document, we&#8217;ve created the L10nDemo application.  This application is very simple, and specifically constructed to illustrate the key moving parts of Android&#8217;s localization framework.</p>
<p>The application consists of a simple UI that displays 3 TextViews, and a button with a background image.  The 3 TextViews display text that is localized appropriately for the system&#8217;s current locale, and the button shows an image of the national flag for the system&#8217;s current locale. When clicked, the button displays a Dialog containing additional text.  The UI is implemented with two variants: one used for portrait orientations, and one for landscape. The contents of each variant are the same, but are visually arranged in a slightly different way.</p>
<p>Here is a screenshot of the L10nDemo application, running in English in the 1.0_r2 SDK emulator.</p>
<p>To download the source code, you can <a rel="nofollow" href="https://android-developers.googlegroups.com/web/L10nDemo.zip?gda=VkhgDT4AAABbwPBSOzVTOhnH8QAAJRGkc_eKk8aavG57jinPV4YF8hrrnv28OuiyeMcIjswJCkvjsKXVs-X7bdXZc5buSfmx&amp;gsc=gg7xFCEAAAB2IECM3xdqRKAbz0TqF_32sQtvHZRPiJNW1GKaHu4ct0zfKN-m9S9niuHrq-IEXAE">click here.</a></p>
<h2>Android Localization: Theory of Operation</h2>
<p>Before we dive in to the details of of the L10nDemo, let&#8217;s begin with an overview of how Android implements localization.</p>
<p>Android provides a framework that allows developers to separate their UI from their application logic. Generally, Android breaks down an application&#8217;s UI into 3 general concepts:</p>
<ol>
<li>The layout of a UI &#8212; which buttons go where, where labels and data go, and so on. Android allows developers to specify these UIs declaratively via XML files.</li>
<li>Assets used to implement or &#8220;fill in&#8221; a UI, such as sounds and images.</li>
<li>Application code (written in Java) that drives the various behaviors of the UI and mutates the screen contents in response to user input.</li>
</ol>
<p>Developers are not required to make use of these resources; for instance, developers could simply put all their images into the &#8216;raw/&#8217; directory in a project, and build up user interfaces programmatically directly from Java source code.  However, this design approach is generally considered to be poorly &#8220;internationalized&#8221; (meaning that it is difficult to localize to multiple languages.)  The framework used by Android is specifically designed to be easy to localize, and so we strongly encourage developers to make use of this framework.</p>
<p>As you know, Android loads resources such as declarative layout XML files and media assets from the project&#8217;s &#8216;res/&#8217; directory. However, there&#8217;s a bit more to it than just that: Android can actually selectively load resources from different directories, based on the current device configuration and locale.  For instance, your application code might wish to refer to a string value named &#8216;R.string.title&#8217;. Android will choose the correct value for that string at runtime by loading the appropriate strings.xml file from a matching &#8216;res/values&#8217; directory.  For instance, if the current locale is &#8216;en-US&#8217;, then Android will look for a value for R.string.title by looking in the following files, in this order: &#8216;res/values-en-rUS/strings.xml&#8217;, &#8216;res/values-en/strings.xml&#8217;, &#8216;res/values/strings.xml&#8217;.  Android chooses the first value it finds &#8212; that is, the value most specific to the current locale, eventually falling back on the default.  (Note that you use whatever language you like for the default file in &#8216;res/values/strings.xml&#8217;; many developers choose English, but it doesn&#8217;t need to be.)</p>
<p>Besides locale, Android will also perform similar resource resolution for device configurations or states, such as whether the screen is currently portrait or landscape.  For instance, on a T-Mobile G1 with the screen open and keyboard exposed, Android will look for a layout file matching &#8216;R.layout.main&#8217; in this order:  &#8216;res/layout-land/main.xml&#8217;, &#8216;res/layout/main.xml&#8217;.  You can also mix-and-match these permutations.  For instance, &#8216;res/values-fr-rCA-land/strings.xml&#8217; would be used to supply values for strings whenever a French-Canadian device is in landscape mode.  This particular example is somewhat contrived since it&#8217;s unlikely you&#8217;d have special needs for that specific combination, but if you have a particularly busy UI it might be useful for providing field labels of varying lengths for different screen modes.</p>
<p>For the full details on how Android resolves resources, see:  http://code.google.com/android/devel/resources-i18n.html#AlternateResources  As you&#8217;ll see, the resource-resolution framework is fairly sophisticaed and can be used for more than just localization.  The remainder of this document, however, focuses on showing how to use this framework to localize an app.</p>
<h2>L10nDemo Resources</h2>
<p>Below is a list of all the resource directories present in the L10nDemo project, and an explanation of when they are used.</p>
<ul>
<li>Layouts:<br />
res/layout-land &#8212; used when the device is in landscape mode.<br />
res/layout &#8212; the default, used when a more specific layout mode is not matched (i.e. when device is in portrait mode)</li>
<li>Strings<br />
res/values-fr &#8212; application strings localized to French (for use in Canada and France)<br />
res/values-de &#8212; application strings localized to German (for use in Germany and Austria)<br />
res/values-en-rUS &#8212; application strings used for US English<br />
res/values &#8212; application strings used when no more specific locale is matched. In this case, the default strings are in British English.</li>
<li>Drawables (i.e. national flag images):<br />
res/drawable-de-rDE &#8212; used when the current locale is Germany<br />
res/drawable-fr-rCA &#8212; used when the current locale is French-Canadian (fr-CA)<br />
res/drawable-fr-rFR &#8212; used when the current locale is France (fr-FR)<br />
res/drawable-en-rCA &#8212; used when the current locale is English Canadian (en-CA)<br />
res/drawable-en-rAU &#8212; used when the current locale is Australia<br />
res/drawable-en-rUS &#8212; used when the current locale is the United States<br />
res/drawable &#8212; used when no other more specific locale is matched. In this case, the default content is in English, and consists of the UK flag.</li>
</ul>
<p>Finally, here is a table specifying exactly which resources are loaded for while locales:</p>
<div>
<table border="0" cellspacing="0" cellpadding="3" width="100%">
<tbody>
<tr>
<td width="16%"><strong>Language<br />
</strong></td>
<td width="16%"><strong>Country<br />
</strong></td>
<td width="16%"><strong>Locale Code (/data/locale)<br />
</strong></td>
<td width="16%"><strong>Strings<br />
</strong></td>
<td width="16%"><strong>Layouts [1]<br />
</strong></td>
<td width="16%"><strong>Drawables</strong></td>
</tr>
<tr>
<td width="16%">German</td>
<td width="16%">Germany</td>
<td width="16%">de-DE</td>
<td width="16%">res/values-de/strings.xml</td>
<td width="16%">res/layout (or res/layout-land)</td>
<td width="16%">res/drawable-de-rDE/flag.png</td>
</tr>
<tr>
<td width="16%">German</td>
<td width="16%">Austria</td>
<td width="16%">de-AT</td>
<td width="16%">res/values-de/strings.xml</td>
<td width="16%">res/layout (or res/layout-land)</td>
<td width="16%">res/drawable/flag.png [2]</td>
</tr>
<tr>
<td width="16%">French</td>
<td width="16%">France</td>
<td width="16%">fr-FR</td>
<td width="16%">res/values-fr/strings.xml</td>
<td width="16%">res/layout (or res/layout-land)</td>
<td width="16%">res/drawable-fr-rFR/flag.png</td>
</tr>
<tr>
<td width="16%">French</td>
<td width="16%">Canada</td>
<td width="16%">fr-CA</td>
<td width="16%">res/values-fr/strings.xml</td>
<td width="16%">res/layout (or res/layout-land)</td>
<td width="16%">res/drawable-fr-rCA/flag.png</td>
</tr>
<tr>
<td width="16%">English</td>
<td width="16%">Canada</td>
<td width="16%">en-CA</td>
<td width="16%">res/values/strings.xml [3]</td>
<td width="16%">res/layout (or res/layout-land)</td>
<td width="16%">res/drawable-en-rCA/flag.png</td>
</tr>
<tr>
<td width="16%">English</td>
<td width="16%">United Kingdom</td>
<td width="16%">en-GB</td>
<td width="16%">res/values/strings.xml [3]</td>
<td width="16%">res/layout (or res/layout-land)</td>
<td width="16%">res/drawable/flag.png</td>
</tr>
<tr>
<td width="16%">English</td>
<td width="16%">Australia</td>
<td width="16%">en-AU</td>
<td width="16%">res/values/strings.xml [3]</td>
<td width="16%">res/layout (or res/layout-land)</td>
<td width="16%">res/drawable-en-rAU/flag.png</td>
</tr>
<tr>
<td width="16%">English</td>
<td width="16%">United States</td>
<td width="16%">en-US</td>
<td width="16%">res/values-en-rUS/strings.xml</td>
<td width="16%">res/layout (or res/layout-land)</td>
<td width="16%">res/drawable-en-rUS/flag.png</td>
</tr>
</tbody>
</table>
</div>
<ul>
<li>[1] &#8211; Because this demo has no need to load different layouts based on language, the same layout file will be used for all languages. It will change only when the device orientation changes.  However, if your application is localized to a language with a different alphabet, such as to Japanese or Chinese, it may make sense to have a different layout entirely for those languages.  In such cases you could use something like &#8216;res/layout-jp&#8217;, &#8216;res/layout-land-jp&#8217;, and &#8216;res/layout-port-jp&#8217;.</li>
<li>[2] &#8211; Because the project does not have a flag specifically for Austria, the system will fall back on the default, which is the US flag defined in &#8216;res/drawable&#8217;. In a real-world app this would be inappropriate and considered a mistake, but is included here as an illustrative example. If you were to change &#8216;res/drawable-de-rDE&#8217; to &#8216;res/drawable-de&#8217;, then it becomes more generic (less specific) and would be used for all German-speaking locales &#8212; in this case, Austria and Germany. This would still be incorrect for Austria, but it might be better than the default of the UK flag.</li>
<li>[3] &#8211; Canada, Australia, and the United Kingdom all share strings. Since there are 3 such nations, it is reasonable to use the default/fallback strings file for this case, and use a more specific match for US-English strings (since US English has different spellings for some words.)  However, a real-world developer might consider the more explicit res/values-en/strings.xml to be &#8220;better style&#8221;.</li>
</ul>
<h2>Localization Techniques in Java Code</h2>
<p>In some cases, you cannot avoid needing to access resources from code.  The most common example is filling in a template string with values computed at runtime.  Fortunately, the Android localization framework is also used when resolving resources from code.  For example, the snippet of code below from the L10nDemo uses the standard Java MessageFormat functionality in conjunction with Android&#8217;s localization framework to transparently select the correct template string for the current locale and fill it in with values derived from code:</p>
<div style="margin-left: 40px;">String msg = getResources().getString(R.string.text_c); // contains {0}, {1}, and {2} in the XML file<br />
msg = java.text.MessageFormat.format(msg, &#8220;foo&#8221;, &#8220;bar&#8221;, myStringVariable);</div>
<p>In some cases, developers may wish to look up specific resources manually.  For example, a project being ported from a different platform that doesn&#8217;t have a localization framework might have lots of resources simply placed into a shared directory, such as &#8216;raw/&#8217;.  In such cases we recommend that developers convert over to use Android&#8217;s framework, but those who choose not to may wish to look up the current locale to select resources manually.  That can be accomplished via the standard Java API, or by using the Android Context.  For instance, the two lines below are equivalent:</p>
<div style="margin-left: 40px;">String locale = context.getResources().getConfiguration().locale.getDisplayName();<br />
String locale = java.util.Locale.getDefault().getDisplayName();</div>
<div>
<h2>Testing Localized Applications</h2>
<p>Currently it is difficult to test localized applications on devices, since all shipping production devices are themselves not localized to conserve space. This means that on actual devices, there is currently no easy way to change the system locale, and thus no easy way to test the localization of applications in anything other than the device&#8217;s native locale.  We expect that this will become easier to do in the future.</p>
<p>Fortunately, it is easy to test localized applications in the emulator; you can simply change the default system locale and restart the emulator runtime.</p>
<ol>
<li>Pick the locale you want to test and determine its language code such as &#8216;fr&#8217; for French and its country code such as &#8216;CA&#8217; for Canada.</li>
<li>Launch an emulator (such as from the command line, or via Eclipse.)</li>
<li>From a command shell on the host computer, run the following command: &#8220;adb shell&#8221;</li>
<li>At the adb shell prompt, run this command: &#8220;setprop persist.sys.language [[language code]];setprop persist.sys.country [[country code]];stop;sleep 5;start&#8221;  Replace bracketed sections with the appropriate codes from Step #1.</li>
</ol>
<p> <br />
For instance, to test in Canadian English, type: &#8220;setprop persist.sys.language en;setprop persist.sys.country CA;stop;sleep 5;start&#8221;</p>
<p>This will cause the emulator runtime to restart (which will appear similar to a reboot, but is not actually a full reboot.) Once the Home screen appears again, simply re-launch your application (such as by clicking the Run icon in Eclipse) and the application will launch with the new desired locale.  Note that the default localization for the system itself is English, so if you choose a non-English locale for which no localization is present in the emulator, the system itself will still display in English.  However even in this case, the locale will have been changed and your own application will localize properly.</p>
<p>Note: This only works with the 1.1_r1 SDK, and will not work on devices. For instructions on how to do this on 1.0_r1 and 1.0_r2 SDKs, please see version 5 of this document which can be accessed from the &#8220;Version&#8221; select menu at the end of this document. Also, this process may change in a future SDK version.</p>
<h2>Publishing Localized Applications</h2>
<p>Most developers will want to publish their applications in the Android Market, which is the main application distribution system for Android devices.  The process for publishing localized apps is very similar to the process for publishing single-country applications, but there are a few extra considerations.  This section describes them; generally, they revolve around managing your .apk files.</p>
<p>If your application has just a few localizations, then you probably will simply roll up a single .apk that includes them all.  However, on the other extreme, applications that are aggressively localized (such as an application localized to the 40 languages that Google supports for its top-tier products) will end up with 40 different values for the same string, layout, and other resource keys.  No individual user will need the localized assets for all 40 languages, so delivering those assets to every user is a waste of space.  On a mobile device with limited bandwidth and storage, this waste is even more problematic.  In view of this, developers should consider at what point to break their .apk files apart into different builds for different groups of languages.  There is no single right answer for every developer; some may only have a handful of languages and choose to place them all in the same .apk, while others may have many assets and choose to have a separate .apk for each supported locale.  Still other developers may choose to build apk files for regions &#8212; for instance, one for European locales, one for North American, another for Asian locales, etc.</p>
<p>Once you&#8217;ve determined how you want to split up your application, you&#8217;ll need to construct the .apk files.  Unfortunately, due to some bugs in the current SDK tools, the &#8216;aapt -c&#8217; command (which would normally be used for this purpose) does not function correctly.  This will be fixed in a future version, but in the meantime the only known workaround is to run the aapt command multiple times.  The easiest way to do this is to create a temporary folder in Eclipse, move out the resource directories which you do not wish to appear, rebuild the project, and then export an unsigned build as you normally would.  Then move the resource directories back in.  A future build of the SDK and ADT will fix this issue.</p>
<h2>Future Changes to Localization</h2>
<p>Like all parts of Android, the localization features are under active development.  Here are a few changes that will be coming soon to a development environment near you:</p>
<ul>
<li>There is currently a bug in the &#8216;aapt&#8217; tool shipped in 1.0_r2 that does not correctly strip unused localized resources (such as strings) when the &#8216;-c&#8217; flag is used, which makes .apk file sizes larger than they need to be.  This will be fixed in a future release.  Additionally, enhanced support for this technique in the &#8220;ADT&#8221; Eclipse plugin will also be included in a future version.</li>
<li>The emulator will be improved to make it easier to switch system locales and thus test localized applications.</li>
<li>As additional devices come to market in new form factors, we will update the localization tools and framework accordingly.</li>
</ul>
<h2>Localization Checklist</h2>
<p>Now that you have an understanding of how the Android localization framework is used, here is a short checklist to summarize the process of localizing an Android application.</p>
<ol>
<li>Design your application.</li>
<li>Choose your localization strategy: which countries, which languages?</li>
<li>Use no hard-coded strings or string constants; use R.string and strings.xml files.</li>
<li>Use no hard-coded drawables or layouts; use R.drawable and R.layout</li>
<li>Translate your strings files; localize your drawables.</li>
<li>Place your localized resources in the appropriate directories under &#8216;res/&#8217;.</li>
<li>Create your final build or builds, using &#8216;aapt&#8217; as necessary.</li>
<li>Upload your .apk file or files to Market, selecting the appropriate languages as you upload.</li>
</ol>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.froogloid.com/android-news/localizing-an-android-app/feed</wfw:commentRss>
		<slash:comments>195</slash:comments>
		</item>
	</channel>
</rss>
