Starting in Android 7.0 (API level 24), Android provides enhanced support for multilingual users, allowing them to select multiple locales in settings. Android provides this capability by greatly expanding the number of locales supported and changing the way the system resolves resources.
This document starts by explaining the resource resolution strategy in versions of Android lower than 7.0 (API level 24). Next, it describes the improved resource resolution strategy in Android 7.0. Last, it explains how to take advantage of the expanded number of locales to support more multilingual users.
Challenges in resolving language resources
Prior to Android 7.0, Android could not always successfully match app and system locales.
For example, assume that you have the following situation:
- Your app's default language is
en_US(US English), and it also has Spanish strings localized ines_ESresource files. - A device is set to
es_MX
When your Java code refers to strings, the system would load
strings from the default (en_US) resource file, even if the app has
Spanish resources localized under es_ES. This is because when the system
cannot find an exact match, it continues to look for resources by stripping the
country code off the locale. Finally, if no match is found, the system falls
back to the default, which is en_US.
The system would also default to en_US if the user chose a language that
the app didn't support at all, like French. For example:
Table 1. Resource resolution without an exact locale match.
| User Settings | App Resources | Resource Resolution |
|---|---|---|
| fr_CH |
default (en) de_DE es_ES fr_FR it_IT |
Try fr_CH => Fail Try fr => Fail Use default (en) |
In this example, the system displays English strings without knowing whether the user can understand English. This behavior is pretty common today.
Improvements to resource-resolution strategy
Android 7.0 (API level 24) brings more robust resource resolution, and
finds better fallbacks automatically.
However, to speed up resolution and improve
maintainability, you should store resources in the most common parent dialect.
For example, if you were storing Spanish resources
in the values-es-rUS directory
before, move them into the values-b+es+419 directory,
which contains Latin American Spanish.
Similarly, if you have resource strings in a
directory named values-en-rGB, rename
the directory to values-b+en+001 (International
English), because the most common
parent for en-GB strings is en-001.
The following examples explain why these practices improve performance and
reliability of resource resolution.
Resource resolution examples
With versions of Android greater than 7.0, the case described in Table 1 is resolved differently:
Table 2. An improved resolution strategy for when there is no exact locale match.
| User Settings | App Resources | Resource Resolution |
|---|---|---|
|
default (en) de_DE es_ES fr_FR it_IT |
Try fr_CH => Fail Try fr => Fail Try children of fr => fr_FR Use fr_FR |
Now the user gets French resources instead of English. This example also shows
why you should store French strings in fr rather than fr_FR
for Android 7.0 or higher. Here the course of action is
to match the closest parent dialect,
making resolution faster and more predictable.
Note: Android doesn't fall back across
different scripts of the same language. For multi-script languages, resolution
skips folders with a different script and falls back to the next preferred
locale or your default res/values/ resources. For more information,
see Multi-script languages: Chinese and regional
variants.
In addition to this improved resolution logic, Android now offers more user languages to choose from. Let’s try the above example again with Italian specified as an additional user language, but without app support for French.
Table 3. Resource resolution when the app only matches the user's second-preferred locale setting.
| User Settings | App Resources | Resource Resolution |
|---|---|---|
|
default (en) de_DE es_ES it_IT |
Try fr_CH => Fail Try fr => Fail Try children of fr => Fail Try it_CH => Fail Try it => Fail Try children of it => it_IT Use it_IT |
The user still gets a language they understand, even though the app doesn’t support French.
Multi-script languages: Chinese and regional variants
Languages written in multiple scripts, such as Chinese (zh),
require explicit script or region qualifiers on Android 7.0 (API level 24) and
higher. Android resolves resource directories using both the language and the
script (explicit or inferred from the region). If a resource folder uses a
different script from the user's locale, Android doesn't treat it as a match.
Android determines each locale's implied script and parent fallback path from
Unicode Common Locale Data Repository (CLDR) rules. When a locale uses a
non-default script, CLDR maps its parent to root—your app's default
res/values/ resources—rather than the unqualified language
directory. Beyond Chinese, this cross-script rule applies to other multi-script
languages:
- Serbian in Latin script, such as
sr-Latnandsr-ME, doesn't fall back tovalues-sr/, which implies Cyrillic (sr-Cyrl). - Azerbaijani in Arabic or Cyrillic script, such as
az-Arab,az-IR, andaz-Cyrl, doesn't fall back tovalues-az/, which implies Latin (az-Latn). - Punjabi in Arabic script, such as
pa-Arabandpa-PK, doesn't fall back tovalues-pa/, which implies Gurmukhi (pa-Guru). - Uzbek in Arabic or Cyrillic script, such as
uz-Arab,uz-AF, anduz-Cyrl, doesn't fall back tovalues-uz/, which implies Latin (uz-Latn).
Because CLDR data evolves across Android releases, don't rely on a fixed list of script exceptions. For more information about inferred scripts and fallback rules, see the Unicode CLDR specification for Likely Subtags and Parent Locales.
Caution: Avoid placing Chinese strings in
an unqualified res/values-zh/ directory. On Android 7.0 and higher,
the system infers the Simplified Chinese script (Hans) for bare
zh. Devices set to Traditional Chinese locales such as
zh-Hant-TW, zh-Hant-HK, or zh-Hant-MO
don't match values-zh/ and fall back to your default
res/values/ resources (typically English). Library dependencies
that ship values-zh/ can also introduce an unqualified
zh locale into your app unless you filter supported locales.
Table 4. Resource resolution for Traditional Chinese users
when an app ships bare values-zh/ compared to script-qualified
directories.
| User settings | App resources | Resource resolution |
|---|---|---|
zh-Hant-HK |
values/ (default, en)values-zh/ (inferred as zh-Hans)
|
Try zh-Hant-HK => FailTry zh-Hant => FailTry children of zh-Hant => FailUse default ( en)
|
zh-Hant-HK |
values/ (default, en)values-b+zh+Hans/values-b+zh+Hant/values-zh-rTW/values-zh-rHK/
|
Try zh-Hant-HK => Match values-zh-rHK/For strings not overridden in values-zh-rHK/, fall back to
values-b+zh+Hant/
|
Recommended Chinese resource directories
Use BCP
47 language tags (prefixed with b+) to establish clean
script-level baselines, then add region-specific directories only for strings
whose terminology or conventions differ by region:
Table 5. Recommended resource directories for Chinese and Cantonese variants on Android 7.0 and higher.
| Target audience | Directory | Role |
|---|---|---|
| Simplified Chinese (baseline) | values-b+zh+Hans/ |
Shared baseline for zh-Hans-CN, zh-Hans-SG,
and other Simplified Chinese locales. Add values-zh-rCN/ or
values-zh-rSG/ only for regional deltas (or use
values-zh-rCN/ if your app supports Android 6.0 and lower). |
| Traditional Chinese (baseline) | values-b+zh+Hant/ |
Shared baseline for zh-Hant-TW, zh-Hant-HK,
zh-Hant-MO, and diaspora Traditional Chinese locales so users
don't fall back to English when an exact region isn't present. |
| Traditional Chinese (Taiwan) | values-zh-rTW/ |
Taiwan-specific terminology overrides on top of
values-b+zh+Hant/. |
| Traditional Chinese (Hong Kong) | values-zh-rHK/ |
Hong Kong-specific terminology overrides on top of
values-b+zh+Hant/. Providing values-zh-rHK/
alongside values-zh-rTW/ prevents Hong Kong and Macau users
from seeing Taiwan-only vocabulary. |
| Cantonese (optional) | values-b+yue/ or values-b+yue+Hant+HK/ |
Dedicated Cantonese UI strings using the three-letter ISO 639-2/3 code
yue. |
Comparing Chinese locales at runtime
On Android 7.0 and higher, runtime Locale instances returned by
the system include a script subtag (for example, zh-Hans-CN or
zh-Hant-TW). Because Locale constants such as
Locale.SIMPLIFIED_CHINESE
(zh-CN) and Locale.TRADITIONAL_CHINESE
(zh-TW) omit the script subtag, exact equality checks
(locale == Locale.TRADITIONAL_CHINESE or
locale.equals(Locale.SIMPLIFIED_CHINESE)) return
false at runtime.
To check whether a user's locale matches a supported Chinese script or variant, use one of the following APIs instead of exact equality:
LocaleListCompat.matchesLanguageAndScript()(AndroidX Core 1.9.0 and higher) orLocaleList.matchesLanguageAndScript()(Android 13 (API level 33) and higher) to compare locales by language and explicit or inferred script. For example,zh-HKmatcheszh-Hant.ULocale.addLikelySubtags()(Android 7.0 and higher) to resolve the effective script (HansorHant) before branching on script.
Designing your app to support additional locales
Android provides tools that make it easier to localize app content and engage users in their preferred languages. We recommend using the following techniques to configure your app so it can accommodate different languages and formatting conventions, in a scalable way.
Specify the languages your app supports
To keep only the language resources your app officially supports—and prevent
untranslated or unqualified library resources (such as a dependency's
values-zh/ folder) from being merged into your app—specify your
supported locales with the
localeFilters
property inside the androidResources block of your module-level
build file (Android Gradle plugin 8.8 and higher).
The following code sample shows how to configure localeFilters
for an app that supports English, Spanish, Simplified Chinese, and Traditional
Chinese with Taiwan and Hong Kong variants:
Groovy
android { androidResources { localeFilters += ["en", "es", "b+zh+Hans", "b+zh+Hant", "zh-rTW", "zh-rHK"] } }
Kotlin
android { androidResources { localeFilters += listOf("en", "es", "b+zh+Hans", "b+zh+Hant", "zh-rTW", "zh-rHK") } }
Use Android resource qualifier syntax (such as b+zh+Hans and
zh-rHK) in localeFilters. If you use an Android
Gradle plugin version lower than 8.8, specify the same values with the
deprecated resourceConfigurations property in
defaultConfig instead.
For apps targeting Android 13 (API level 33) and higher, also enable
generateLocaleConfig = true so Android Studio and the Android
Gradle plugin automatically generate your per-app language configuration using
the filtered locale set. For details, see
Enable
automatic per-app language support.
LocaleList API
Starting with Android 7.0 (API level 24), Android exposes the
LocaleList.getDefault() API
that lets apps directly query the list of languages a user has specified. This API
allows you to create more sophisticated
app behavior and better-optimized display of content. For example, Search
can show results in multiple languages based on user’s settings. Browser apps
can avoid offering to translate pages in a language the user already knows,
and keyboard apps can auto-enable all appropriate layouts.
Formatters
Up through Android 6.0 (API level 23), Android supported only one or two locales for many common languages (en, es, ar, fr, ru). Because there were only a few variants of each language, apps could get away with storing some numbers and dates as hard coded strings in resource files. However, with Android's broadened set of supported locales, there can be significant differences in formats for dates, times, currencies, and similar information even within a single locale. Hard-coding your formats can produce a confusing experience for end users. Therefore, when developing for Android 7.0 or higher versions, make sure to use formatters instead of hard coding numbers and date strings.
For example, Android 7.0 and higher includes support for 27 Arabic locales. These locales can share most resources, but some prefer ASCII digits, while others prefer native digits. For example, when you want to create a sentence with a digit variable, such as "Choose a 4 digit pin", use formatters as shown below:
format(locale, "Choose a %d-digit PIN", 4)