Chapter 20. All the Worldâs Not English: Strings and Internationalization
âAll the worldâs a stage,â wrote William Shakespeare. But not all the players on that great and turbulent stage speak the great Bardâs native tongue. To be usable on a global scale, your software needs to communicate in many different languages. The menu labels, button strings, dialog messages, title bar/action bar titles, and error messages must be settable to the userâs choice of language. This is the topic of internationalization and localization. (Because the words âinternationalizationâ and âlocalizationâ take a long time to say and write, theyâre often abbreviated using their first and last letters and the count of omitted letters: I18N and L10N.)
If youâve got your strings in a separate XML file, as we advised in Chapter 1, you have already done part of the work of internationalizing your app. Arenât you glad you followed our advice?
Android provides a Locale
class to discover/control the internationalization settings. A default Locale
is inherited from the userâs language settings when your app starts up.
As a best practice, your app should never ask the users to choose a language, because theyâll already have chosen one when setting up the device.
Note that if you know internationalization from desktop Java, itâs pretty much the same here. Weâll explain as we go along, with examples, in this chapter.
Ianâs basic steps: Internationalization
Internationalization ...
Get Android Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.