From f16a569e2451adb4b91bf61069c6f9e0d03809c4 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Sun, 11 Nov 2018 03:43:16 -0800 Subject: [PATCH] Supported locales docs to explain proper scriptCode usage. (#24184) --- packages/flutter/lib/src/widgets/app.dart | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index f2893e83d5..e0a5e9e80b 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -560,6 +560,34 @@ class WidgetsApp extends StatefulWidget { /// [supportedLocales] with a matching [Locale.languageCode] is used. If that /// fails then the first locale in [supportedLocales] is used. The default /// locale resolution algorithm can be overridden with [localeResolutionCallback]. + /// + /// 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: + /// + /// ```dart + /// // 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. /// {@endtemplate} /// /// See also: