From 02e9afef64956797bacf4641d18ad81d1dab14fe Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 2 Aug 2018 01:13:53 -0700 Subject: [PATCH] Der Datumsauswahldialog spricht jetzt deutsch (#20115) --- .../lib/src/material_localizations.dart | 14 +++---- .../test/date_time_test.dart | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/packages/flutter_localizations/lib/src/material_localizations.dart b/packages/flutter_localizations/lib/src/material_localizations.dart index 5f121c5664..0da50239b5 100644 --- a/packages/flutter_localizations/lib/src/material_localizations.dart +++ b/packages/flutter_localizations/lib/src/material_localizations.dart @@ -104,23 +104,21 @@ class GlobalMaterialLocalizations implements MaterialLocalizations { _translationBundle = translationBundleForLocale(locale); assert(_translationBundle != null); - const String kMediumDatePattern = 'E, MMM\u00a0d'; if (intl.DateFormat.localeExists(_localeName)) { _fullYearFormat = new intl.DateFormat.y(_localeName); - _mediumDateFormat = new intl.DateFormat(kMediumDatePattern, _localeName); + _mediumDateFormat = new intl.DateFormat.MMMEd(_localeName); _longDateFormat = new intl.DateFormat.yMMMMEEEEd(_localeName); - _yearMonthFormat = new intl.DateFormat('yMMMM', _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(kMediumDatePattern, locale.languageCode); - + _mediumDateFormat = new intl.DateFormat.MMMEd(locale.languageCode); _longDateFormat = new intl.DateFormat.yMMMMEEEEd(locale.languageCode); - _yearMonthFormat = new intl.DateFormat('yMMMM', locale.languageCode); + _yearMonthFormat = new intl.DateFormat.yMMMM(locale.languageCode); } else { _fullYearFormat = new intl.DateFormat.y(); - _mediumDateFormat = new intl.DateFormat(kMediumDatePattern); + _mediumDateFormat = new intl.DateFormat.MMMEd(); _longDateFormat = new intl.DateFormat.yMMMMEEEEd(); - _yearMonthFormat = new intl.DateFormat('yMMMM'); + _yearMonthFormat = new intl.DateFormat.yMMMM(); } if (intl.NumberFormat.localeExists(_localeName)) { diff --git a/packages/flutter_localizations/test/date_time_test.dart b/packages/flutter_localizations/test/date_time_test.dart index 0a1fb7a7f2..8f5efd752f 100644 --- a/packages/flutter_localizations/test/date_time_test.dart +++ b/packages/flutter_localizations/test/date_time_test.dart @@ -114,5 +114,47 @@ void main() { expect(await formatTimeOfDay(tester, const Locale('zh', ''), const TimeOfDay(hour: 9, minute: 32)), '上午 9:32'); }); }); + + group('date formatters', () { + Future> formatDate(WidgetTester tester, Locale locale, DateTime dateTime) async { + final Completer> completer = new Completer>(); + await tester.pumpWidget(new MaterialApp( + supportedLocales: [locale], + locale: locale, + localizationsDelegates: const >[ + GlobalMaterialLocalizations.delegate, + ], + home: new Builder(builder: (BuildContext context) { + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + completer.complete({ + DateType.year: localizations.formatYear(dateTime), + DateType.medium: localizations.formatMediumDate(dateTime), + DateType.full: localizations.formatFullDate(dateTime), + DateType.monthYear: localizations.formatMonthYear(dateTime), + }); + return new Container(); + }), + )); + return completer.future; + } + + testWidgets('formats dates in English', (WidgetTester tester) async { + final Map formatted = await formatDate(tester, const Locale('en', ''), new DateTime(2018, 8, 1)); + expect(formatted[DateType.year], '2018'); + expect(formatted[DateType.medium], 'Wed, Aug 1'); + expect(formatted[DateType.full], 'Wednesday, August 1, 2018'); + expect(formatted[DateType.monthYear], 'August 2018'); + }); + + testWidgets('formats dates in German', (WidgetTester tester) async { + final Map formatted = await formatDate(tester, const Locale('de', ''), new DateTime(2018, 8, 1)); + expect(formatted[DateType.year], '2018'); + expect(formatted[DateType.medium], 'Mi., 1. Aug.'); + expect(formatted[DateType.full], 'Mittwoch, 1. August 2018'); + expect(formatted[DateType.monthYear], 'August 2018'); + }); + }); }); } + +enum DateType { year, medium, full, monthYear }