|
|
|
|
@@ -11,14 +11,25 @@ import 'package:intl/date_symbols.dart' as intl;
|
|
|
|
|
import 'package:intl/date_symbol_data_custom.dart' as date_symbol_data_custom;
|
|
|
|
|
import 'l10n/date_localizations.dart' as date_localizations;
|
|
|
|
|
|
|
|
|
|
import 'l10n/localizations.dart' show TranslationBundle, translationBundleForLocale;
|
|
|
|
|
import 'l10n/localizations.dart';
|
|
|
|
|
import 'widgets_localizations.dart';
|
|
|
|
|
|
|
|
|
|
// Watch out: the supported locales list in the doc comment below must be kept
|
|
|
|
|
// in sync with the list we test, see test/translations_test.dart, and of course
|
|
|
|
|
// the actual list of supported locales in _MaterialLocalizationsDelegate.
|
|
|
|
|
|
|
|
|
|
/// Localized strings for the material widgets.
|
|
|
|
|
/// Implementation of localized strings for the material widgets using the
|
|
|
|
|
/// `intl` package for date and time formatting.
|
|
|
|
|
///
|
|
|
|
|
/// ## Supported languages
|
|
|
|
|
///
|
|
|
|
|
/// This class supports locales with the following [Locale.languageCode]s:
|
|
|
|
|
///
|
|
|
|
|
/// {@macro flutter.localizations.languages}
|
|
|
|
|
///
|
|
|
|
|
/// This list is available programatically via [kSupportedLanguages].
|
|
|
|
|
///
|
|
|
|
|
/// ## Sample code
|
|
|
|
|
///
|
|
|
|
|
/// To include the localizations provided by this class in a [MaterialApp],
|
|
|
|
|
/// add [GlobalMaterialLocalizations.delegates] to
|
|
|
|
|
@@ -29,133 +40,87 @@ import 'widgets_localizations.dart';
|
|
|
|
|
/// new MaterialApp(
|
|
|
|
|
/// localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
|
|
|
|
/// supportedLocales: [
|
|
|
|
|
/// const Locale('en', 'US'), // English
|
|
|
|
|
/// const Locale('he', 'IL'), // Hebrew
|
|
|
|
|
/// const Locale('en', 'US'), // American English
|
|
|
|
|
/// const Locale('he', 'IL'), // Israeli Hebrew
|
|
|
|
|
/// // ...
|
|
|
|
|
/// ],
|
|
|
|
|
/// // ...
|
|
|
|
|
/// )
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// This class supports locales with the following [Locale.languageCode]s:
|
|
|
|
|
/// ## Overriding translations
|
|
|
|
|
///
|
|
|
|
|
/// * ar - Arabic
|
|
|
|
|
/// * bg - Bulgarian
|
|
|
|
|
/// * bs - Bosnian
|
|
|
|
|
/// * ca - Catalan
|
|
|
|
|
/// * cs - Czech
|
|
|
|
|
/// * da - Danish
|
|
|
|
|
/// * de - German
|
|
|
|
|
/// * el - Greek
|
|
|
|
|
/// * en - English
|
|
|
|
|
/// * es - Spanish
|
|
|
|
|
/// * et - Estonian
|
|
|
|
|
/// * fa - Farsi
|
|
|
|
|
/// * fi - Finnish
|
|
|
|
|
/// * fil - Fillipino
|
|
|
|
|
/// * fr - French
|
|
|
|
|
/// * gsw - Swiss German
|
|
|
|
|
/// * hi - Hindi
|
|
|
|
|
/// * he - Hebrew
|
|
|
|
|
/// * hr - Croatian
|
|
|
|
|
/// * hu - Hungarian
|
|
|
|
|
/// * id - Indonesian
|
|
|
|
|
/// * it - Italian
|
|
|
|
|
/// * ja - Japanese
|
|
|
|
|
/// * ko - Korean
|
|
|
|
|
/// * lv - Latvian
|
|
|
|
|
/// * lt - Lithuanian
|
|
|
|
|
/// * ms - Malay
|
|
|
|
|
/// * nl - Dutch
|
|
|
|
|
/// * nb - Norwegian
|
|
|
|
|
/// * pl - Polish
|
|
|
|
|
/// * ps - Pashto
|
|
|
|
|
/// * pt - Portuguese
|
|
|
|
|
/// * ro - Romanian
|
|
|
|
|
/// * ru - Russian
|
|
|
|
|
/// * sk - Slovak
|
|
|
|
|
/// * sl - Slovenian
|
|
|
|
|
/// * sr - Serbian
|
|
|
|
|
/// * sv - Swedish
|
|
|
|
|
/// * tl - Tagalog
|
|
|
|
|
/// * th - Thai
|
|
|
|
|
/// * tr - Turkish
|
|
|
|
|
/// * uk - Ukranian
|
|
|
|
|
/// * ur - Urdu
|
|
|
|
|
/// * vi - Vietnamese
|
|
|
|
|
/// * zh - Simplified Chinese
|
|
|
|
|
/// To create a translation that's similar to an existing language's translation
|
|
|
|
|
/// but has slightly different strings, subclass the relevant translation
|
|
|
|
|
/// directly and then create a [LocalizationsDelegate<MaterialLocalizations>]
|
|
|
|
|
/// subclass to define how to load it.
|
|
|
|
|
///
|
|
|
|
|
/// Avoid subclassing an unrelated language (for example, subclassing
|
|
|
|
|
/// [MaterialLocalizationEn] and then passing a non-English `localeName` to the
|
|
|
|
|
/// constructor). Doing so will cause confusion for locale-specific behaviors;
|
|
|
|
|
/// in particular, translations that use the `localeName` for determining how to
|
|
|
|
|
/// pluralize will end up doing invalid things. Subclassing an existing
|
|
|
|
|
/// language's translations is only suitable for making small changes to the
|
|
|
|
|
/// existing strings. For providing a new language entirely, implement
|
|
|
|
|
/// [MaterialLocalizations] directly.
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
/// * The Flutter Internationalization Tutorial,
|
|
|
|
|
/// <https://flutter.io/tutorials/internationalization/>.
|
|
|
|
|
/// * [DefaultMaterialLocalizations], which only provides US English translations.
|
|
|
|
|
class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|
|
|
|
/// Constructs an object that defines the material widgets' localized strings
|
|
|
|
|
abstract class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|
|
|
|
/// Initializes 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.
|
|
|
|
|
GlobalMaterialLocalizations(this.locale)
|
|
|
|
|
: assert(locale != null),
|
|
|
|
|
_localeName = _computeLocaleName(locale) {
|
|
|
|
|
_loadDateIntlDataIfNotLoaded();
|
|
|
|
|
|
|
|
|
|
_translationBundle = translationBundleForLocale(locale);
|
|
|
|
|
assert(_translationBundle != null);
|
|
|
|
|
|
|
|
|
|
if (intl.DateFormat.localeExists(_localeName)) {
|
|
|
|
|
_fullYearFormat = new intl.DateFormat.y(_localeName);
|
|
|
|
|
_mediumDateFormat = new intl.DateFormat.MMMEd(_localeName);
|
|
|
|
|
_longDateFormat = new intl.DateFormat.yMMMMEEEEd(_localeName);
|
|
|
|
|
_yearMonthFormat = new intl.DateFormat.yMMMM(_localeName);
|
|
|
|
|
} else if (intl.DateFormat.localeExists(locale.languageCode)) {
|
|
|
|
|
_fullYearFormat = new intl.DateFormat.y(locale.languageCode);
|
|
|
|
|
_mediumDateFormat = new intl.DateFormat.MMMEd(locale.languageCode);
|
|
|
|
|
_longDateFormat = new intl.DateFormat.yMMMMEEEEd(locale.languageCode);
|
|
|
|
|
_yearMonthFormat = new intl.DateFormat.yMMMM(locale.languageCode);
|
|
|
|
|
} else {
|
|
|
|
|
_fullYearFormat = new intl.DateFormat.y();
|
|
|
|
|
_mediumDateFormat = new intl.DateFormat.MMMEd();
|
|
|
|
|
_longDateFormat = new intl.DateFormat.yMMMMEEEEd();
|
|
|
|
|
_yearMonthFormat = new intl.DateFormat.yMMMM();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (intl.NumberFormat.localeExists(_localeName)) {
|
|
|
|
|
_decimalFormat = new intl.NumberFormat.decimalPattern(_localeName);
|
|
|
|
|
_twoDigitZeroPaddedFormat = new intl.NumberFormat('00', _localeName);
|
|
|
|
|
} else if (intl.NumberFormat.localeExists(locale.languageCode)) {
|
|
|
|
|
_decimalFormat = new intl.NumberFormat.decimalPattern(locale.languageCode);
|
|
|
|
|
_twoDigitZeroPaddedFormat = new intl.NumberFormat('00', locale.languageCode);
|
|
|
|
|
} else {
|
|
|
|
|
_decimalFormat = new intl.NumberFormat.decimalPattern();
|
|
|
|
|
_twoDigitZeroPaddedFormat = new intl.NumberFormat('00');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The locale for which the values of this class's localized resources
|
|
|
|
|
/// have been translated.
|
|
|
|
|
final Locale locale;
|
|
|
|
|
/// The arguments are used for further runtime localization of data,
|
|
|
|
|
/// specifically for selecting plurals, date and time formatting, and number
|
|
|
|
|
/// formatting. They correspond to the following values:
|
|
|
|
|
///
|
|
|
|
|
/// 1. The string that would be returned by [Intl.canonicalizedLocale] for
|
|
|
|
|
/// the locale.
|
|
|
|
|
/// 2. The [intl.DateFormat] for [formatYear].
|
|
|
|
|
/// 3. The [intl.DateFormat] for [formatMediumDate].
|
|
|
|
|
/// 4. The [intl.DateFormat] for [formatFullDate].
|
|
|
|
|
/// 5. The [intl.DateFormat] for [formatMonthYear].
|
|
|
|
|
/// 6. The [NumberFormat] for [formatDecimal] (also used by [formatHour] and
|
|
|
|
|
/// [formatTimeOfDay] when [timeOfDayFormat] doesn't use [HourFormat.HH]).
|
|
|
|
|
/// 7. The [NumberFormat] for [formatHour] and the hour part of
|
|
|
|
|
/// [formatTimeOfDay] when [timeOfDayFormat] uses [HourFormat.HH], and for
|
|
|
|
|
/// [formatMinute] and the minute part of [formatTimeOfDay].
|
|
|
|
|
///
|
|
|
|
|
/// The [narrowWeekdays] and [firstDayOfWeekIndex] properties use the values
|
|
|
|
|
/// from the [intl.DateFormat] used by [formatFullDate].
|
|
|
|
|
const GlobalMaterialLocalizations({
|
|
|
|
|
@required String localeName,
|
|
|
|
|
@required intl.DateFormat fullYearFormat,
|
|
|
|
|
@required intl.DateFormat mediumDateFormat,
|
|
|
|
|
@required intl.DateFormat longDateFormat,
|
|
|
|
|
@required intl.DateFormat yearMonthFormat,
|
|
|
|
|
@required intl.NumberFormat decimalFormat,
|
|
|
|
|
@required intl.NumberFormat twoDigitZeroPaddedFormat,
|
|
|
|
|
}) : assert(localeName != null),
|
|
|
|
|
this._localeName = localeName,
|
|
|
|
|
assert(fullYearFormat != null),
|
|
|
|
|
this._fullYearFormat = fullYearFormat,
|
|
|
|
|
assert(mediumDateFormat != null),
|
|
|
|
|
this._mediumDateFormat = mediumDateFormat,
|
|
|
|
|
assert(longDateFormat != null),
|
|
|
|
|
this._longDateFormat = longDateFormat,
|
|
|
|
|
assert(yearMonthFormat != null),
|
|
|
|
|
this._yearMonthFormat = yearMonthFormat,
|
|
|
|
|
assert(decimalFormat != null),
|
|
|
|
|
this._decimalFormat = decimalFormat,
|
|
|
|
|
assert(twoDigitZeroPaddedFormat != null),
|
|
|
|
|
this._twoDigitZeroPaddedFormat = twoDigitZeroPaddedFormat;
|
|
|
|
|
|
|
|
|
|
final String _localeName;
|
|
|
|
|
|
|
|
|
|
TranslationBundle _translationBundle;
|
|
|
|
|
|
|
|
|
|
intl.NumberFormat _decimalFormat;
|
|
|
|
|
|
|
|
|
|
intl.NumberFormat _twoDigitZeroPaddedFormat;
|
|
|
|
|
|
|
|
|
|
intl.DateFormat _fullYearFormat;
|
|
|
|
|
|
|
|
|
|
intl.DateFormat _mediumDateFormat;
|
|
|
|
|
|
|
|
|
|
intl.DateFormat _longDateFormat;
|
|
|
|
|
|
|
|
|
|
intl.DateFormat _yearMonthFormat;
|
|
|
|
|
|
|
|
|
|
static String _computeLocaleName(Locale locale) {
|
|
|
|
|
return intl.Intl.canonicalizedLocale(locale.toString());
|
|
|
|
|
}
|
|
|
|
|
final intl.DateFormat _fullYearFormat;
|
|
|
|
|
final intl.DateFormat _mediumDateFormat;
|
|
|
|
|
final intl.DateFormat _longDateFormat;
|
|
|
|
|
final intl.DateFormat _yearMonthFormat;
|
|
|
|
|
final intl.NumberFormat _decimalFormat;
|
|
|
|
|
final intl.NumberFormat _twoDigitZeroPaddedFormat;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String formatHour(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }) {
|
|
|
|
|
@@ -198,11 +163,11 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
List<String> get narrowWeekdays {
|
|
|
|
|
return _fullYearFormat.dateSymbols.NARROWWEEKDAYS;
|
|
|
|
|
return _longDateFormat.dateSymbols.NARROWWEEKDAYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
int get firstDayOfWeekIndex => (_fullYearFormat.dateSymbols.FIRSTDAYOFWEEK + 1) % 7;
|
|
|
|
|
int get firstDayOfWeekIndex => (_longDateFormat.dateSymbols.FIRSTDAYOFWEEK + 1) % 7;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String formatDecimal(int number) {
|
|
|
|
|
@@ -234,7 +199,6 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|
|
|
|
case TimeOfDayFormat.frenchCanadian:
|
|
|
|
|
return '$hour h $minute';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -248,152 +212,162 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get openAppDrawerTooltip => _translationBundle.openAppDrawerTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get backButtonTooltip => _translationBundle.backButtonTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get closeButtonTooltip => _translationBundle.closeButtonTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get deleteButtonTooltip => _translationBundle.deleteButtonTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get nextMonthTooltip => _translationBundle.nextMonthTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get previousMonthTooltip => _translationBundle.previousMonthTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get nextPageTooltip => _translationBundle.nextPageTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get previousPageTooltip => _translationBundle.previousPageTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get showMenuTooltip => _translationBundle.showMenuTooltip;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get drawerLabel => _translationBundle.alertDialogLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get popupMenuLabel => _translationBundle.popupMenuLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get dialogLabel => _translationBundle.dialogLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get alertDialogLabel => _translationBundle.alertDialogLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get searchFieldLabel => _translationBundle.searchFieldLabel;
|
|
|
|
|
/// The raw version of [aboutListTileTitle], with `$applicationName` verbatim
|
|
|
|
|
/// in the string.
|
|
|
|
|
@protected
|
|
|
|
|
String get aboutListTileTitleRaw;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String aboutListTileTitle(String applicationName) {
|
|
|
|
|
final String text = _translationBundle.aboutListTileTitle;
|
|
|
|
|
final String text = aboutListTileTitleRaw;
|
|
|
|
|
return text.replaceFirst(r'$applicationName', applicationName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get licensesPageTitle => _translationBundle.licensesPageTitle;
|
|
|
|
|
/// The raw version of [pageRowsInfoTitle], with `$firstRow`, `$lastRow`' and
|
|
|
|
|
/// `$rowCount` verbatim in the string, for the case where the value is
|
|
|
|
|
/// approximate.
|
|
|
|
|
@protected
|
|
|
|
|
String get pageRowsInfoTitleApproximateRaw;
|
|
|
|
|
|
|
|
|
|
/// The raw version of [pageRowsInfoTitle], with `$firstRow`, `$lastRow`' and
|
|
|
|
|
/// `$rowCount` verbatim in the string, for the case where the value is
|
|
|
|
|
/// precise.
|
|
|
|
|
@protected
|
|
|
|
|
String get pageRowsInfoTitleRaw;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate) {
|
|
|
|
|
String text = rowCountIsApproximate ? _translationBundle.pageRowsInfoTitleApproximate : null;
|
|
|
|
|
text ??= _translationBundle.pageRowsInfoTitle;
|
|
|
|
|
assert(text != null, 'A $locale localization was not found for pageRowsInfoTitle or pageRowsInfoTitleApproximate');
|
|
|
|
|
// TODO(hansmuller): this could be more efficient.
|
|
|
|
|
String text = rowCountIsApproximate ? pageRowsInfoTitleApproximateRaw : null;
|
|
|
|
|
text ??= pageRowsInfoTitleRaw;
|
|
|
|
|
assert(text != null, 'A $_localeName localization was not found for pageRowsInfoTitle or pageRowsInfoTitleApproximate');
|
|
|
|
|
return text
|
|
|
|
|
.replaceFirst(r'$firstRow', formatDecimal(firstRow))
|
|
|
|
|
.replaceFirst(r'$lastRow', formatDecimal(lastRow))
|
|
|
|
|
.replaceFirst(r'$rowCount', formatDecimal(rowCount));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get rowsPerPageTitle => _translationBundle.rowsPerPageTitle;
|
|
|
|
|
/// The raw version of [tabLabel], with `$tabIndex` and `$tabCount` verbatim
|
|
|
|
|
/// in the string.
|
|
|
|
|
@protected
|
|
|
|
|
String get tabLabelRaw;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String tabLabel({int tabIndex, int tabCount}) {
|
|
|
|
|
assert(tabIndex >= 1);
|
|
|
|
|
assert(tabCount >= 1);
|
|
|
|
|
final String template = _translationBundle.tabLabel;
|
|
|
|
|
final String template = tabLabelRaw;
|
|
|
|
|
return template
|
|
|
|
|
.replaceFirst(r'$tabIndex', formatDecimal(tabIndex))
|
|
|
|
|
.replaceFirst(r'$tabCount', formatDecimal(tabCount));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The "zero" form of [selectedRowCountTitle].
|
|
|
|
|
///
|
|
|
|
|
/// This form is optional.
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
/// * [Intl.plural], to which this form is passed.
|
|
|
|
|
/// * [selectedRowCountTitleOne], the "one" form
|
|
|
|
|
/// * [selectedRowCountTitleTwo], the "two" form
|
|
|
|
|
/// * [selectedRowCountTitleFew], the "few" form
|
|
|
|
|
/// * [selectedRowCountTitleMany], the "many" form
|
|
|
|
|
/// * [selectedRowCountTitleOther], the "other" form
|
|
|
|
|
@protected
|
|
|
|
|
String get selectedRowCountTitleZero => null;
|
|
|
|
|
|
|
|
|
|
/// The "one" form of [selectedRowCountTitle].
|
|
|
|
|
///
|
|
|
|
|
/// This form is optional.
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
/// * [Intl.plural], to which this form is passed.
|
|
|
|
|
/// * [selectedRowCountTitleZero], the "zero" form
|
|
|
|
|
/// * [selectedRowCountTitleTwo], the "two" form
|
|
|
|
|
/// * [selectedRowCountTitleFew], the "few" form
|
|
|
|
|
/// * [selectedRowCountTitleMany], the "many" form
|
|
|
|
|
/// * [selectedRowCountTitleOther], the "other" form
|
|
|
|
|
@protected
|
|
|
|
|
String get selectedRowCountTitleOne => null;
|
|
|
|
|
|
|
|
|
|
/// The "two" form of [selectedRowCountTitle].
|
|
|
|
|
///
|
|
|
|
|
/// This form is optional.
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
/// * [Intl.plural], to which this form is passed.
|
|
|
|
|
/// * [selectedRowCountTitleZero], the "zero" form
|
|
|
|
|
/// * [selectedRowCountTitleOne], the "one" form
|
|
|
|
|
/// * [selectedRowCountTitleFew], the "few" form
|
|
|
|
|
/// * [selectedRowCountTitleMany], the "many" form
|
|
|
|
|
/// * [selectedRowCountTitleOther], the "other" form
|
|
|
|
|
@protected
|
|
|
|
|
String get selectedRowCountTitleTwo => null;
|
|
|
|
|
|
|
|
|
|
/// The "few" form of [selectedRowCountTitle].
|
|
|
|
|
///
|
|
|
|
|
/// This form is optional.
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
/// * [Intl.plural], to which this form is passed.
|
|
|
|
|
/// * [selectedRowCountTitleZero], the "zero" form
|
|
|
|
|
/// * [selectedRowCountTitleOne], the "one" form
|
|
|
|
|
/// * [selectedRowCountTitleTwo], the "two" form
|
|
|
|
|
/// * [selectedRowCountTitleMany], the "many" form
|
|
|
|
|
/// * [selectedRowCountTitleOther], the "other" form
|
|
|
|
|
@protected
|
|
|
|
|
String get selectedRowCountTitleFew => null;
|
|
|
|
|
|
|
|
|
|
/// The "many" form of [selectedRowCountTitle].
|
|
|
|
|
///
|
|
|
|
|
/// This form is optional.
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
/// * [Intl.plural], to which this form is passed.
|
|
|
|
|
/// * [selectedRowCountTitleZero], the "zero" form
|
|
|
|
|
/// * [selectedRowCountTitleOne], the "one" form
|
|
|
|
|
/// * [selectedRowCountTitleTwo], the "two" form
|
|
|
|
|
/// * [selectedRowCountTitleFew], the "few" form
|
|
|
|
|
/// * [selectedRowCountTitleOther], the "other" form
|
|
|
|
|
@protected
|
|
|
|
|
String get selectedRowCountTitleMany => null;
|
|
|
|
|
|
|
|
|
|
/// The "other" form of [selectedRowCountTitle].
|
|
|
|
|
///
|
|
|
|
|
/// This form is required.
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
/// * [Intl.plural], to which this form is passed.
|
|
|
|
|
/// * [selectedRowCountTitleZero], the "zero" form
|
|
|
|
|
/// * [selectedRowCountTitleOne], the "one" form
|
|
|
|
|
/// * [selectedRowCountTitleTwo], the "two" form
|
|
|
|
|
/// * [selectedRowCountTitleFew], the "few" form
|
|
|
|
|
/// * [selectedRowCountTitleMany], the "many" form
|
|
|
|
|
@protected
|
|
|
|
|
String get selectedRowCountTitleOther;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String selectedRowCountTitle(int selectedRowCount) {
|
|
|
|
|
// TODO(hmuller): the rules for mapping from an integer value to
|
|
|
|
|
// "one" or "two" etc. are locale specific and an additional "few" category
|
|
|
|
|
// is needed. See http://cldr.unicode.org/index/cldr-spec/plural-rules
|
|
|
|
|
String text;
|
|
|
|
|
if (selectedRowCount == 0)
|
|
|
|
|
text = _translationBundle.selectedRowCountTitleZero;
|
|
|
|
|
else if (selectedRowCount == 1)
|
|
|
|
|
text = _translationBundle.selectedRowCountTitleOne;
|
|
|
|
|
else if (selectedRowCount == 2)
|
|
|
|
|
text = _translationBundle.selectedRowCountTitleTwo;
|
|
|
|
|
else if (selectedRowCount > 2)
|
|
|
|
|
text = _translationBundle.selectedRowCountTitleMany;
|
|
|
|
|
text ??= _translationBundle.selectedRowCountTitleOther;
|
|
|
|
|
assert(text != null);
|
|
|
|
|
|
|
|
|
|
return text.replaceFirst(r'$selectedRowCount', formatDecimal(selectedRowCount));
|
|
|
|
|
return intl.Intl.plural(
|
|
|
|
|
selectedRowCount,
|
|
|
|
|
zero: selectedRowCountTitleZero,
|
|
|
|
|
one: selectedRowCountTitleOne,
|
|
|
|
|
two: selectedRowCountTitleTwo,
|
|
|
|
|
few: selectedRowCountTitleFew,
|
|
|
|
|
many: selectedRowCountTitleMany,
|
|
|
|
|
other: selectedRowCountTitleOther,
|
|
|
|
|
locale: _localeName,
|
|
|
|
|
).replaceFirst(r'$selectedRowCount', formatDecimal(selectedRowCount));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get cancelButtonLabel => _translationBundle.cancelButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get closeButtonLabel => _translationBundle.closeButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get continueButtonLabel => _translationBundle.continueButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get copyButtonLabel => _translationBundle.copyButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get cutButtonLabel => _translationBundle.cutButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get okButtonLabel => _translationBundle.okButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get pasteButtonLabel => _translationBundle.pasteButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get selectAllButtonLabel => _translationBundle.selectAllButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get viewLicensesButtonLabel => _translationBundle.viewLicensesButtonLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get anteMeridiemAbbreviation => _translationBundle.anteMeridiemAbbreviation;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get postMeridiemAbbreviation => _translationBundle.postMeridiemAbbreviation;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get timePickerHourModeAnnouncement => _translationBundle.timePickerHourModeAnnouncement;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get timePickerMinuteModeAnnouncement => _translationBundle.timePickerMinuteModeAnnouncement;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get modalBarrierDismissLabel => _translationBundle.modalBarrierDismissLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get signedInLabel => _translationBundle.signedInLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get hideAccountsLabel => _translationBundle.hideAccountsLabel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String get showAccountsLabel => _translationBundle.showAccountsLabel;
|
|
|
|
|
/// The format to use for [timeOfDayFormat].
|
|
|
|
|
@protected
|
|
|
|
|
TimeOfDayFormat get timeOfDayFormatRaw;
|
|
|
|
|
|
|
|
|
|
/// The [TimeOfDayFormat] corresponding to one of the following supported
|
|
|
|
|
/// patterns:
|
|
|
|
|
@@ -409,44 +383,28 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
/// * http://demo.icu-project.org/icu-bin/locexp?d_=en&_=en_US shows the
|
|
|
|
|
/// short time pattern used in locale en_US
|
|
|
|
|
/// * <http://demo.icu-project.org/icu-bin/locexp?d_=en&_=en_US>, which shows
|
|
|
|
|
/// the short time pattern used in the `en_US` locale.
|
|
|
|
|
@override
|
|
|
|
|
TimeOfDayFormat timeOfDayFormat({ bool alwaysUse24HourFormat = false }) {
|
|
|
|
|
final String icuShortTimePattern = _translationBundle.timeOfDayFormat;
|
|
|
|
|
|
|
|
|
|
assert(() {
|
|
|
|
|
if (!_icuTimeOfDayToEnum.containsKey(icuShortTimePattern)) {
|
|
|
|
|
throw new FlutterError(
|
|
|
|
|
'"$icuShortTimePattern" is not one of the ICU short time patterns '
|
|
|
|
|
'supported by the material library. Here is the list of supported '
|
|
|
|
|
'patterns:\n ' +
|
|
|
|
|
_icuTimeOfDayToEnum.keys.join('\n ')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
final TimeOfDayFormat icuFormat = _icuTimeOfDayToEnum[icuShortTimePattern];
|
|
|
|
|
|
|
|
|
|
assert(alwaysUse24HourFormat != null);
|
|
|
|
|
if (alwaysUse24HourFormat)
|
|
|
|
|
return _get24HourVersionOf(icuFormat);
|
|
|
|
|
|
|
|
|
|
return icuFormat;
|
|
|
|
|
return _get24HourVersionOf(timeOfDayFormatRaw);
|
|
|
|
|
return timeOfDayFormatRaw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The script category used by [localTextGeometry]. Must be one of the strings
|
|
|
|
|
/// declared in [MaterialTextGeometry].
|
|
|
|
|
///
|
|
|
|
|
/// TODO(ianh): make this return a TextTheme from MaterialTextGeometry.
|
|
|
|
|
/// TODO(ianh): drop the constructor on MaterialTextGeometry.
|
|
|
|
|
/// TODO(ianh): drop the strings on MaterialTextGeometry.
|
|
|
|
|
@protected
|
|
|
|
|
String get scriptCategory;
|
|
|
|
|
|
|
|
|
|
/// Looks up text geometry defined in [MaterialTextGeometry].
|
|
|
|
|
@override
|
|
|
|
|
TextTheme get localTextGeometry => MaterialTextGeometry.forScriptCategory(_translationBundle.scriptCategory);
|
|
|
|
|
|
|
|
|
|
/// Creates an object that provides localized resource values for the
|
|
|
|
|
/// for the widgets of the material library.
|
|
|
|
|
///
|
|
|
|
|
/// This method is typically used to create a [LocalizationsDelegate].
|
|
|
|
|
/// The [MaterialApp] does so by default.
|
|
|
|
|
static Future<MaterialLocalizations> load(Locale locale) {
|
|
|
|
|
return new SynchronousFuture<MaterialLocalizations>(new GlobalMaterialLocalizations(locale));
|
|
|
|
|
}
|
|
|
|
|
TextTheme get localTextGeometry => MaterialTextGeometry.forScriptCategory(scriptCategory);
|
|
|
|
|
|
|
|
|
|
/// A [LocalizationsDelegate] that uses [GlobalMaterialLocalizations.load]
|
|
|
|
|
/// to create an instance of this class.
|
|
|
|
|
@@ -459,6 +417,8 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|
|
|
|
/// A value for [MaterialApp.localizationsDelegates] that's typically used by
|
|
|
|
|
/// internationalized apps.
|
|
|
|
|
///
|
|
|
|
|
/// ## Sample code
|
|
|
|
|
///
|
|
|
|
|
/// To include the localizations provided by this class and by
|
|
|
|
|
/// [GlobalWidgetsLocalizations] in a [MaterialApp],
|
|
|
|
|
/// use [GlobalMaterialLocalizations.delegates] as the value of
|
|
|
|
|
@@ -481,17 +441,6 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Map<String, TimeOfDayFormat> _icuTimeOfDayToEnum = <String, TimeOfDayFormat>{
|
|
|
|
|
'HH:mm': TimeOfDayFormat.HH_colon_mm,
|
|
|
|
|
'HH.mm': TimeOfDayFormat.HH_dot_mm,
|
|
|
|
|
"HH 'h' mm": TimeOfDayFormat.frenchCanadian,
|
|
|
|
|
'HH:mm น.': TimeOfDayFormat.HH_colon_mm,
|
|
|
|
|
'H:mm': TimeOfDayFormat.H_colon_mm,
|
|
|
|
|
'h:mm a': TimeOfDayFormat.h_colon_mm_space_a,
|
|
|
|
|
'a h:mm': TimeOfDayFormat.a_space_h_colon_mm,
|
|
|
|
|
'ah:mm': TimeOfDayFormat.a_space_h_colon_mm,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Finds the [TimeOfDayFormat] to use instead of the `original` when the
|
|
|
|
|
/// `original` uses 12-hour format and [MediaQueryData.alwaysUse24HourFormat]
|
|
|
|
|
/// is true.
|
|
|
|
|
@@ -509,86 +458,91 @@ TimeOfDayFormat _get24HourVersionOf(TimeOfDayFormat original) {
|
|
|
|
|
return TimeOfDayFormat.HH_colon_mm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Tracks if date i18n data has been loaded.
|
|
|
|
|
bool _dateIntlDataInitialized = false;
|
|
|
|
|
|
|
|
|
|
/// Loads i18n data for dates if it hasn't be loaded yet.
|
|
|
|
|
///
|
|
|
|
|
/// Only the first invocation of this function has the effect of loading the
|
|
|
|
|
/// data. Subsequent invocations have no effect.
|
|
|
|
|
void _loadDateIntlDataIfNotLoaded() {
|
|
|
|
|
if (!_dateIntlDataInitialized) {
|
|
|
|
|
date_localizations.dateSymbols.forEach((String locale, dynamic data) {
|
|
|
|
|
assert(date_localizations.datePatterns.containsKey(locale));
|
|
|
|
|
final intl.DateSymbols symbols = new intl.DateSymbols.deserializeFromMap(data);
|
|
|
|
|
date_symbol_data_custom.initializeDateFormattingCustom(
|
|
|
|
|
locale: locale,
|
|
|
|
|
symbols: symbols,
|
|
|
|
|
patterns: date_localizations.datePatterns[locale],
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
_dateIntlDataInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> {
|
|
|
|
|
const _MaterialLocalizationsDelegate();
|
|
|
|
|
|
|
|
|
|
// Watch out: this list must match the one in the GlobalMaterialLocalizations
|
|
|
|
|
// class doc and the list we test, see test/translations_test.dart.
|
|
|
|
|
static const List<String> _supportedLanguages = <String>[
|
|
|
|
|
'ar', // Arabic
|
|
|
|
|
'bg', // Bulgarian
|
|
|
|
|
'bs', // Bosnian
|
|
|
|
|
'ca', // Catalan
|
|
|
|
|
'cs', // Czech
|
|
|
|
|
'da', // Danish
|
|
|
|
|
'de', // German
|
|
|
|
|
'el', // Greek
|
|
|
|
|
'en', // English
|
|
|
|
|
'es', // Spanish
|
|
|
|
|
'et', // Estonian
|
|
|
|
|
'fa', // Farsi (Persian)
|
|
|
|
|
'fi', // Finnish
|
|
|
|
|
'fil', // Fillipino
|
|
|
|
|
'fr', // French
|
|
|
|
|
'gsw', // Swiss German
|
|
|
|
|
'he', // Hebrew
|
|
|
|
|
'hi', // Hindi
|
|
|
|
|
'hr', // Croatian
|
|
|
|
|
'hu', // Hungarian
|
|
|
|
|
'id', // Indonesian
|
|
|
|
|
'it', // Italian
|
|
|
|
|
'ja', // Japanese
|
|
|
|
|
'ko', // Korean
|
|
|
|
|
'lv', // Latvian
|
|
|
|
|
'lt', // Lithuanian
|
|
|
|
|
'ms', // Malay
|
|
|
|
|
'nl', // Dutch
|
|
|
|
|
'nb', // Norwegian
|
|
|
|
|
'pl', // Polish
|
|
|
|
|
'ps', // Pashto
|
|
|
|
|
'pt', // Portugese
|
|
|
|
|
'ro', // Romanian
|
|
|
|
|
'ru', // Russian
|
|
|
|
|
'sr', // Serbian
|
|
|
|
|
'sk', // Slovak
|
|
|
|
|
'sl', // Slovenian
|
|
|
|
|
'th', // Thai
|
|
|
|
|
'sv', // Swedish
|
|
|
|
|
'tl', // Tagalog
|
|
|
|
|
'tr', // Turkish
|
|
|
|
|
'uk', // Ukranian
|
|
|
|
|
'ur', // Urdu
|
|
|
|
|
'vi', // Vietnamese
|
|
|
|
|
'zh', // Chinese (simplified)
|
|
|
|
|
];
|
|
|
|
|
@override
|
|
|
|
|
bool isSupported(Locale locale) => kSupportedLanguages.contains(locale.languageCode);
|
|
|
|
|
|
|
|
|
|
/// Tracks if date i18n data has been loaded.
|
|
|
|
|
static bool _dateIntlDataInitialized = false;
|
|
|
|
|
|
|
|
|
|
/// Loads i18n data for dates if it hasn't be loaded yet.
|
|
|
|
|
///
|
|
|
|
|
/// Only the first invocation of this function has the effect of loading the
|
|
|
|
|
/// data. Subsequent invocations have no effect.
|
|
|
|
|
static void _loadDateIntlDataIfNotLoaded() {
|
|
|
|
|
if (!_dateIntlDataInitialized) {
|
|
|
|
|
date_localizations.dateSymbols.forEach((String locale, dynamic data) {
|
|
|
|
|
assert(date_localizations.datePatterns.containsKey(locale));
|
|
|
|
|
final intl.DateSymbols symbols = new intl.DateSymbols.deserializeFromMap(data);
|
|
|
|
|
date_symbol_data_custom.initializeDateFormattingCustom(
|
|
|
|
|
locale: locale,
|
|
|
|
|
symbols: symbols,
|
|
|
|
|
patterns: date_localizations.datePatterns[locale],
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
_dateIntlDataInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static final Map<Locale, Future<MaterialLocalizations>> _loadedTranslations = <Locale, Future<MaterialLocalizations>>{};
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool isSupported(Locale locale) => _supportedLanguages.contains(locale.languageCode);
|
|
|
|
|
Future<MaterialLocalizations> load(Locale locale) {
|
|
|
|
|
assert(isSupported(locale));
|
|
|
|
|
return _loadedTranslations.putIfAbsent(locale, () {
|
|
|
|
|
_loadDateIntlDataIfNotLoaded();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<MaterialLocalizations> load(Locale locale) => GlobalMaterialLocalizations.load(locale);
|
|
|
|
|
final String localeName = intl.Intl.canonicalizedLocale(locale.toString());
|
|
|
|
|
|
|
|
|
|
intl.DateFormat fullYearFormat;
|
|
|
|
|
intl.DateFormat mediumDateFormat;
|
|
|
|
|
intl.DateFormat longDateFormat;
|
|
|
|
|
intl.DateFormat yearMonthFormat;
|
|
|
|
|
if (intl.DateFormat.localeExists(localeName)) {
|
|
|
|
|
fullYearFormat = new intl.DateFormat.y(localeName);
|
|
|
|
|
mediumDateFormat = new intl.DateFormat.MMMEd(localeName);
|
|
|
|
|
longDateFormat = new intl.DateFormat.yMMMMEEEEd(localeName);
|
|
|
|
|
yearMonthFormat = new intl.DateFormat.yMMMM(localeName);
|
|
|
|
|
} else if (intl.DateFormat.localeExists(locale.languageCode)) {
|
|
|
|
|
fullYearFormat = new intl.DateFormat.y(locale.languageCode);
|
|
|
|
|
mediumDateFormat = new intl.DateFormat.MMMEd(locale.languageCode);
|
|
|
|
|
longDateFormat = new intl.DateFormat.yMMMMEEEEd(locale.languageCode);
|
|
|
|
|
yearMonthFormat = new intl.DateFormat.yMMMM(locale.languageCode);
|
|
|
|
|
} else {
|
|
|
|
|
fullYearFormat = new intl.DateFormat.y();
|
|
|
|
|
mediumDateFormat = new intl.DateFormat.MMMEd();
|
|
|
|
|
longDateFormat = new intl.DateFormat.yMMMMEEEEd();
|
|
|
|
|
yearMonthFormat = new intl.DateFormat.yMMMM();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intl.NumberFormat decimalFormat;
|
|
|
|
|
intl.NumberFormat twoDigitZeroPaddedFormat;
|
|
|
|
|
if (intl.NumberFormat.localeExists(localeName)) {
|
|
|
|
|
decimalFormat = new intl.NumberFormat.decimalPattern(localeName);
|
|
|
|
|
twoDigitZeroPaddedFormat = new intl.NumberFormat('00', localeName);
|
|
|
|
|
} else if (intl.NumberFormat.localeExists(locale.languageCode)) {
|
|
|
|
|
decimalFormat = new intl.NumberFormat.decimalPattern(locale.languageCode);
|
|
|
|
|
twoDigitZeroPaddedFormat = new intl.NumberFormat('00', locale.languageCode);
|
|
|
|
|
} else {
|
|
|
|
|
decimalFormat = new intl.NumberFormat.decimalPattern();
|
|
|
|
|
twoDigitZeroPaddedFormat = new intl.NumberFormat('00');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(locale.toString() == localeName, 'comparing "$locale" to "$localeName"');
|
|
|
|
|
|
|
|
|
|
return new SynchronousFuture<MaterialLocalizations>(getTranslation(
|
|
|
|
|
locale,
|
|
|
|
|
fullYearFormat,
|
|
|
|
|
mediumDateFormat,
|
|
|
|
|
longDateFormat,
|
|
|
|
|
yearMonthFormat,
|
|
|
|
|
decimalFormat,
|
|
|
|
|
twoDigitZeroPaddedFormat,
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool shouldReload(_MaterialLocalizationsDelegate old) => false;
|
|
|
|
|
|