Chapter 18 Localization
Consider an example. Suppose you set the language on your device to Spanish and your region to
Chile (Figure 18.9). An app on your device contains Spanish strings.xml files tailored for Spain and
Mexico (in values-es-rES and values-es-rMX). The default values directory contains an English
strings.xml. If your device is running pre-Nougat Android, you will see the English contents of the
default values directory. But if your device is running Nougat, you will have a better experience: You
will see the contents of values-es-rMX/strings.xml – which means you will see Spanish, though not
tailored to Chile.
Figure 18.9 Locale resolution example (pre- and post-Nougat)
This example is a bit contrived. But it highlights an important point: Provide strings in as general a
context as possible, using language-only qualified directories as much as possible and region-qualified
directories only when necessary. Rather than maintaining all Spanish user-facing strings in three
region-qualified directories, the example app above would be better off storing the Spanish strings in a
language-only qualified values-es directory and providing region-qualified strings only for words and
phrases that are different in the different regional dialects. This not only makes maintaining the strings
files easier for the programmer, but it also helps the system resolve the resources on both pre-Nougat
devices and Nougat devices by providing a language-only match.