Many people are intimidated by localization (l10n) and internationalization (i18n) but they don’t have to be—Android provides many tools out of the box to aide you in global domination. Learn what to watch out for while coding your app that will make your life easier once you receive localized content. We’ll cover alternate resources, strings files, date and number formatters and other tips from Android Studio, Google, and third parties that will turn you into an i18n and l10n champion.
This talk was given at Droidcon NYC on August 27th, 2015.
These slides were revised for DroidKaigi in Tokyo, presented on February 19th, 2016.
7. @sienatime
Localization
• Displaying data (dates, numbers,
currencies, etc.) according to target region
• Adjusting branding according to target
culture
BUSINESS
• Translating content into target languages
8. @sienatime
Internationalization
• Preparing your app for localized content
• Defining alternate resource files
• Using number and date formatters
• Designing and implementing flexible
layouts
ENGINEERING
17. @sienatime
What content is localizable?
• Strings
• Numbers and currency
• Dates and time
• Images with text on them (avoid)
• Audio and video files
20. @sienatime
Strings
• Don’t hardcode strings that face the user
• Use position placeholders %1$s %2$s
• Provide context for your translators to
help make their job easier
I need to %s interpolate %s I need to %1$s interpolate %2$s
26. @sienatime
Dates & Time
// DateFormat.getDateFormat (short)
// DateFormat.getMediumDateFormat
// DateFormat.getLongDateFormat
en_US
short: 08/07/2015
medium: Aug 7, 2015
long: August 7, 2015
en_AU
short: 07/08/2015
medium: 7 Aug 2015
long: 7 August 2015
DateFormat dateFormatter = DateFormat.getDateFormat(context);
Date now = new Date();
dateFormatter.format(now);
27. @sienatime
Custom Date Formats: API 18+
String formatString = DateFormat.getBestDateTimePattern(
Locale.getDefault(), "MMMMyyyy"
);
SimpleDateFormat dateFormatter = new
SimpleDateFormat(formatString);
Date now = new Date();
String dateString = dateFormatter.format(now);
en_US: August 2015
ja_JP: 2015年8月
28. @sienatime
Custom Date Formats: API <18
• ¯_(ツ)_/¯
• Collect date formats you need and keep
them in your resources
• ...but Android is still going to format
according to the user’s locale even if you
don’t support it
• Joda-Time
30. @sienatime
Multi-Format Spannables
Replace, if you can, with HTML in your
strings.xml (limited tag support)
textView.setText(Html.fromHtml(
res.getString(R.string.fixed_funding))
);
<string name="flexible_funding">
<![CDATA[
<b>Flexible Funding.</b> Campaign keeps all
funds raised.
]]>
</string>
31. @sienatime
Build Flexible Layouts
• Thank God for wrap_content
• Be mindful of line lengths
• What would happen if these two pieces of
data needed to be switched around?
35. @sienatime
Google Play Developer Console → Statistics
• What languages and countries your users
are in
• How your app compares to others in your
category
38. @sienatime
Smartling: Pull
$ ./smartling.sh pull
Pulling non-English locales from smartling...
pulling fr-Fr from smartling...
saved fr-Fr to /app/src/main/res/values-fr/strings.xml
pulling de-DE from smartling...
saved de-DE to /app/src/main/res/values-de/strings.xml
pulling es from smartling...
saved es to /app/src/main/res/values-es/strings.xml
39. @sienatime
Further Reading
● Localizing with Resources
http://developer.android.com/guide/topics/resources/
localization.html
● Localization Checklist
http://developer.android.com/distribute/tools/localization-
checklist.html
● Google Play App Translation Service blog post
http://android-developers.blogspot.com/2013/11/app-
translation-service-now-available.html
● Smartling API http://docs.smartling.com/pages/API/v2/
● Smartling Java SDK
http://docs.smartling.com/pages/API/v2/SDKs/#Java