diff --git a/packages/flutter_localizations/lib/src/utils/date_localizations.dart b/packages/flutter_localizations/lib/src/utils/date_localizations.dart index 6033a165caf..132e304dea3 100644 --- a/packages/flutter_localizations/lib/src/utils/date_localizations.dart +++ b/packages/flutter_localizations/lib/src/utils/date_localizations.dart @@ -16,29 +16,9 @@ bool _dateIntlDataInitialized = false; /// invocations have no effect. void loadDateIntlDataIfNotLoaded() { if (!_dateIntlDataInitialized) { - // TODO(garyq): Add support for scriptCodes. Do not strip scriptCode from string. - - // Keeps track of initialized locales. This can only happen if a locale - // with a stripped scriptCode has already been initialized. The set of - // initialized locales should be removed when scriptCode stripping is - // removed. - final Set initializedLocales = {}; date_localizations.dateSymbols .cast>() .forEach((String locale, Map data) { - // Strip scriptCode from the locale, as we do not distinguish between scripts - // for dates. - final List codes = locale.split('_'); - String? countryCode; - if (codes.length == 2) { - countryCode = codes[1].length < 4 ? codes[1] : null; - } else if (codes.length == 3) { - countryCode = codes[1].length < codes[2].length ? codes[1] : codes[2]; - } - locale = codes[0] + (countryCode != null ? '_$countryCode' : ''); - if (initializedLocales.contains(locale)) - return; - initializedLocales.add(locale); // Perform initialization. assert(date_localizations.datePatterns.containsKey(locale)); final intl.DateSymbols symbols = intl.DateSymbols.deserializeFromMap(data); diff --git a/packages/flutter_localizations/test/material/date_time_test.dart b/packages/flutter_localizations/test/material/date_time_test.dart index 7022a7a4ad3..39f56f4e385 100644 --- a/packages/flutter_localizations/test/material/date_time_test.dart +++ b/packages/flutter_localizations/test/material/date_time_test.dart @@ -158,6 +158,23 @@ void main() { expect(formatted[DateType.full], 'Mittwoch, 1. August 2018'); expect(formatted[DateType.monthYear], 'August 2018'); }); + + testWidgets('formats dates in Serbian', (WidgetTester tester) async { + final Map formatted = await formatDate(tester, const Locale('sr'), DateTime(2018, 8, 1)); + expect(formatted[DateType.year], '2018.'); + expect(formatted[DateType.medium], 'сре 1. авг'); + expect(formatted[DateType.full], 'среда, 1. август 2018.'); + expect(formatted[DateType.monthYear], 'август 2018.'); + }); + + testWidgets('formats dates in Serbian (Latin)', (WidgetTester tester) async { + final Map formatted = await formatDate(tester, + const Locale.fromSubtags(languageCode:'sr', scriptCode: 'Latn'), DateTime(2018, 8, 1)); + expect(formatted[DateType.year], '2018.'); + expect(formatted[DateType.medium], 'sre 1. avg'); + expect(formatted[DateType.full], 'sreda, 1. avgust 2018.'); + expect(formatted[DateType.monthYear], 'avgust 2018.'); + }); }); });