diff --git a/dev/tools/gen_localizations.dart b/dev/tools/gen_localizations.dart index 0a7a838961..4249f72fb6 100644 --- a/dev/tools/gen_localizations.dart +++ b/dev/tools/gen_localizations.dart @@ -68,7 +68,12 @@ String generateString(String s) { String generateLocalizationsMap() { final StringBuffer output = new StringBuffer(); - output.writeln('const Map> localizations = const > {'); + output.writeln(''' +/// Maps from [Locale.languageCode] to a map that contains the localized strings +/// for that locale. +/// +/// This variable is used by [MaterialLocalizations]. +const Map> localizations = const > {'''); final String lastLocale = localeToResources.keys.last; for (String locale in localeToResources.keys) { diff --git a/packages/flutter/lib/src/material/i18n/localizations.dart b/packages/flutter/lib/src/material/i18n/localizations.dart index 1808dbc9d2..ff5de3f756 100644 --- a/packages/flutter/lib/src/material/i18n/localizations.dart +++ b/packages/flutter/lib/src/material/i18n/localizations.dart @@ -6,6 +6,10 @@ // To regenerate the file, use: // dart gen_localizations packages/flutter/lib/src/material/i18n material +/// Maps from [Locale.languageCode] to a map that contains the localized strings +/// for that locale. +/// +/// This variable is used by [MaterialLocalizations]. const Map> localizations = const > { "ar": const { "openAppDrawerTooltip": r"افتح قائمة التنقل", diff --git a/packages/flutter/lib/src/material/material_localizations.dart b/packages/flutter/lib/src/material/material_localizations.dart index 6289bf4e1f..343f1250ac 100644 --- a/packages/flutter/lib/src/material/material_localizations.dart +++ b/packages/flutter/lib/src/material/material_localizations.dart @@ -52,6 +52,9 @@ abstract class MaterialLocalizations { class DefaultMaterialLocalizations implements MaterialLocalizations { /// Construct an object that defines the material widgets' localized strings /// for the given `locale`. + /// + /// [LocalizationsDelegate] implementations typically call the static [load] + /// function, rather than constructing this class directly. DefaultMaterialLocalizations(this.locale) { assert(locale != null); _nameToValue = localizations[locale.toString()] diff --git a/packages/flutter/lib/src/widgets/localizations.dart b/packages/flutter/lib/src/widgets/localizations.dart index 34ba4496ed..266b6b8dbf 100644 --- a/packages/flutter/lib/src/widgets/localizations.dart +++ b/packages/flutter/lib/src/widgets/localizations.dart @@ -78,9 +78,10 @@ Future> _loadAll(Locale locale, Iterable { /// Abstract const constructor. This constructor enables subclasses to provide /// const constructors so that they can be used in const expressions. @@ -102,6 +103,17 @@ abstract class LocalizationsDelegate { /// after [load] has completed. bool shouldReload(covariant LocalizationsDelegate old); + /// The type of the object returned by the [load] method, T by default. + /// + /// This type is used to retrieve the object "loaded" by this + /// [LocalizationsDelegate] from the [Localizations] inherited widget. + /// For example the object loaded by `LocalizationsDelegate` would + /// be retrieved with: + /// ```dart + /// Foo foo = Localizations.of(context, Foo); + /// ``` + /// + /// It's rarely necessary to override this getter. Type get type => T; @override @@ -141,6 +153,11 @@ abstract class WidgetsLocalizations { /// Localized values for widgets. class DefaultWidgetsLocalizations implements WidgetsLocalizations { + /// Construct an object that defines the localized values for the widgets + /// library for the given `locale`. + /// + /// [LocalizationsDelegate] implementations typically call the static [load] + /// function, rather than constructing this class directly. DefaultWidgetsLocalizations(this.locale) { final String language = locale.languageCode.toLowerCase(); _textDirection = _rtlLanguages.contains(language) ? TextDirection.rtl : TextDirection.ltr;