Targeting a region
Targeting a region
You can qualify a resource directory with a language-plus-region qualifier that targets resources even
more specifically. For instance, the qualifier for Spanish spoken in Spain is -es-rES, where the r
denotes a region qualifier and ES is the ISO 3166-1-alpha-2 code for Spain. Configuration qualifiers are
not case sensitive, but it is good to follow Android’s convention here: Use a lowercase language code
and an uppercase region code prefixed with a lowercase r.
Note that a language-region qualifier, such as -es-rES, may look like two distinct configuration
qualifiers that have been combined, but it is just one. The region is not a valid qualifier on its own.
Figure 18.8 shows the locale resource resolution strategy and how it differs based on the device’s
Android version.
Figure 18.8 Locale resolution (pre- and post-Nougat)
A resource qualified with both a locale and region has two opportunities for matching a user’s locale.
An exact match occurs when both the language and region qualifiers match the user’s locale. If no
exact match is found, the system will strip off the region qualifier and look for an exact match for the
language only.
On devices running pre-Nougat versions of Android, if no language match is found, the default
(unqualified resource) is used. Nougat has enhanced locale support, with more locales and the ability
to select more than one locale in the device’s settings. The system also uses a more intelligent resource
resolution strategy for locale with the aim of showing the correct language as often as possible, even
if the app does not provide an exact region match or a nonqualified language match. If no exact match
is found on a device running Nougat, and no language-only match is found, the system will look
for a resource qualified with the same language but a different region and will use the best match of
resources that meet those criteria.