O'Reilly logo

Android Cookbook, 2nd Edition by Ian F. Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 and localization consist of:

Sensitivity ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required