supportedLocales property
The list of locales that this app has been localized for.
By default only the American English locale is supported. Apps should configure this list to match the locales they support.
This list must not null. Its default value is just
[const Locale('en', 'US')]
.
The order of the list matters. The default locale resolution algorithm,
basicLocaleListResolution
, attempts to match by the following priority:
- Locale.languageCode, Locale.scriptCode, and Locale.countryCode
- Locale.languageCode and Locale.countryCode only
- Locale.languageCode and Locale.countryCode only
- Locale.languageCode only
- Locale.countryCode only when all
preferredLocales
fail to match - returns
supportedLocales.first
as a fallback
When more than one supported locale matches one of these criteria, only the first
matching locale is returned. See basicLocaleListResolution
for a complete
description of the algorithm.
The default locale resolution algorithm can be overridden by providing a value for
localeListResolutionCallback. The provided basicLocaleListResolution
is optimized
for speed and does not implement a full algorithm (such as the one defined in
Unicode TR35) that takes
distances between languages into account.
When supporting languages with more than one script, it is recommended to specify the Locale.scriptCode explicitly. Locales may also be defined without Locale.countryCode to specify a generic fallback for a particular script.
A fully supported language with multiple scripts should define a generic language-only locale (eg. 'zh'), language+script only locales (eg. 'zh_Hans' and 'zh_Hant'), and any language+script+country locales (eg. 'zh_Hans_CN'). Fully defining all of these locales as supported is not strictly required but allows for proper locale resolution in the most number of cases. These locales can be specified with the Locale.fromSubtags constructor:
// Full Chinese support for CN, TW, and HK
supportedLocales: [
const Locale.fromSubtags(languageCode: 'zh'), // generic Chinese 'zh'
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), // generic simplified Chinese 'zh_Hans'
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'), // generic traditional Chinese 'zh_Hant'
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN'), // 'zh_Hans_CN'
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'TW'), // 'zh_Hant_TW'
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'HK'), // 'zh_Hant_HK'
],
Omitting some these fallbacks may result in improperly resolved edge-cases, for example, a simplified Chinese user in Taiwan ('zh_Hans_TW') may resolve to traditional Chinese if 'zh_Hans' and 'zh_Hans_CN' are omitted.
It is passed along unmodified to the WidgetsApp built by this widget.
Implementation
final Iterable<Locale> supportedLocales