Der Datumsauswahldialog spricht jetzt deutsch (#20115)
This commit is contained in:
committed by
GitHub
parent
47d7a7201e
commit
02e9afef64
@@ -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)) {
|
||||
|
||||
@@ -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<Map<DateType, String>> formatDate(WidgetTester tester, Locale locale, DateTime dateTime) async {
|
||||
final Completer<Map<DateType, String>> completer = new Completer<Map<DateType, String>>();
|
||||
await tester.pumpWidget(new MaterialApp(
|
||||
supportedLocales: <Locale>[locale],
|
||||
locale: locale,
|
||||
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
],
|
||||
home: new Builder(builder: (BuildContext context) {
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
completer.complete(<DateType, String>{
|
||||
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<DateType, String> 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<DateType, String> 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 }
|
||||
|
||||
Reference in New Issue
Block a user