Chapter 18 Localization
Finding the best-matching resources
Let’s walk through how Android determined which version of crime_title_hint to display in this
run. First, consider the four alternatives for the string resource named crime_title_hint and an
example device configuration for a Nexus 5x set to Spanish language and with an available screen
width greater than 600dp:
Device configuration App values for crime_title_hint
- Language: es (Spanish) • values
- Available height: 411dp • values-es
- Available width: 731dp • values-es-w600dp
- (etc.) • values-w600dp
Ruling out incompatible directories
The first step that Android takes to find the best resource is to rule out any resource directory that is
incompatible with the current configuration.
None of the four choices is incompatible with the current configuration. (If you rotated the device to
portrait, the available width would become 411dp, and the resource directories values-w600dp/ and
values-es-w600dp/ would be incompatible and thus ruled out.)
Stepping through the precedence table
After the incompatible resource directories have been ruled out, Android starts working through the
precedence table shown in the section called Configuration Qualifiers, starting with the highest priority
qualifier: MCC. If there is a resource directory with an MCC qualifier, then all resource directories
that do not have an MCC qualifier are ruled out. If there is still more than one matching directory,
then Android considers the next-highest precedence qualifier and continues until only one directory
remains.
In our example, no directories contain an MCC qualifier, so no directories are ruled out, and Android
moves down the list to the language qualifier. Two directories (values-es/ and values-es-w600dp/)
contain language qualifiers. One directory (values-w600dp/) does not and is ruled out:
Device Configuration App values for crime_title_hint
- Language: es (Spanish) • values
- Available height: 411dp • values-es
- Available width: 731dp • values-es-w600dp
- (etc.) • values-w600dp (not language specific)