Unverified Commit c0c5901c authored by Tae Hyung Kim's avatar Tae Hyung Kim Committed by GitHub

Fix gen_date_localizations script and regenerate (#124547)

Internal bug: b/256596915

Turns out we need to regenerate date localizations in order for the
`intl` package to be setup properly within Flutter. This PR fixes the
script (since it assumes the use of the old `.packages` way of handling
packages), and regenerates the `generated_date_localizations.dart` file.
parent cf189121
...@@ -46,32 +46,39 @@ Future<void> main(List<String> rawArgs) async { ...@@ -46,32 +46,39 @@ Future<void> main(List<String> rawArgs) async {
final bool writeToFile = parseArgs(rawArgs).writeToFile; final bool writeToFile = parseArgs(rawArgs).writeToFile;
final File dotPackagesFile = File(path.join('packages', 'flutter_localizations', '.packages')); final File packageConfigFile = File(path.join('packages', 'flutter_localizations', '.dart_tool', 'package_config.json'));
final bool dotPackagesExists = dotPackagesFile.existsSync(); final bool packageConfigExists = packageConfigFile.existsSync();
if (!dotPackagesExists) { if (!packageConfigExists) {
exitWithError( exitWithError(
'File not found: ${dotPackagesFile.path}. $_kCommandName must be run ' 'File not found: ${packageConfigFile.path}. $_kCommandName must be run '
'after a successful "flutter update-packages".' 'after a successful "flutter update-packages".'
); );
} }
final String pathToIntl = dotPackagesFile final List<Object?> packages = (
.readAsStringSync() json.decode(packageConfigFile.readAsStringSync()) as Map<String, Object?>
.split('\n') )['packages']! as List<Object?>;
.firstWhere(
(String line) => line.startsWith('intl:'), String? pathToIntl;
orElse: () { for (final Object? package in packages) {
exitWithError('intl dependency not found in ${dotPackagesFile.path}'); final Map<String, Object?> packageAsMap = package! as Map<String, Object?>;
return ''; // unreachable if (packageAsMap['name'] == 'intl') {
}, pathToIntl = Uri.parse(packageAsMap['rootUri']! as String).toFilePath();
) break;
.split(':') }
.last; }
final Directory dateSymbolsDirectory = Directory(path.join(pathToIntl, 'src', 'data', 'dates', 'symbols')); if (pathToIntl == null) {
exitWithError(
'Could not find "intl" package. $_kCommandName must be run '
'after a successful "flutter update-packages".'
);
}
final Directory dateSymbolsDirectory = Directory(path.join(pathToIntl!, 'lib', 'src', 'data', 'dates', 'symbols'));
final Map<String, File> symbolFiles = _listIntlData(dateSymbolsDirectory); final Map<String, File> symbolFiles = _listIntlData(dateSymbolsDirectory);
final Directory datePatternsDirectory = Directory(path.join(pathToIntl, 'src', 'data', 'dates', 'patterns')); final Directory datePatternsDirectory = Directory(path.join(pathToIntl, 'lib', 'src', 'data', 'dates', 'patterns'));
final Map<String, File> patternFiles = _listIntlData(datePatternsDirectory); final Map<String, File> patternFiles = _listIntlData(datePatternsDirectory);
final StringBuffer buffer = StringBuffer(); final StringBuffer buffer = StringBuffer();
final Set<String> supportedLocales = _supportedLocales(); final Set<String> supportedLocales = _supportedLocales();
......
...@@ -31,7 +31,7 @@ void main() { ...@@ -31,7 +31,7 @@ void main() {
// Tests a different first day of week. // Tests a different first day of week.
const Locale('ru', 'RU'): <String, dynamic>{ const Locale('ru', 'RU'): <String, dynamic>{
'textDirection': TextDirection.ltr, 'textDirection': TextDirection.ltr,
'expectedDaysOfWeek': <String>['пн', 'вт', 'ср', 'чт', 'пт', 'сб', 'вс'], 'expectedDaysOfWeek': <String>['В', 'П', 'В', 'С', 'Ч', 'П', 'С',],
'expectedDaysOfMonth': List<String>.generate(30, (int i) => '${i + 1}'), 'expectedDaysOfMonth': List<String>.generate(30, (int i) => '${i + 1}'),
'expectedMonthYearHeader': 'сентябрь 2017 г.', 'expectedMonthYearHeader': 'сентябрь 2017 г.',
}, },
......
...@@ -193,6 +193,22 @@ void main() { ...@@ -193,6 +193,22 @@ void main() {
expect(dateFormat.locale, 'en_US'); expect(dateFormat.locale, 'en_US');
}); });
testWidgets('cy is initialized correctly by Flutter when DateFormat is used', (WidgetTester tester) async {
late DateFormat dateFormat;
await tester.pumpWidget(MaterialApp(
locale: const Locale('cy'),
localizationsDelegates: GlobalMaterialLocalizations.delegates,
home: Builder(builder: (BuildContext context) {
dateFormat = DateFormat.yMMMd('cy');
return Container();
}),
));
expect(dateFormat.locale, 'cy');
expect(dateFormat.format(DateTime(2023, 4, 10, 2, 32)), equals('10 Ebr 2023'));
});
} }
enum DateType { year, medium, full, monthYear } enum DateType { year, medium, full, monthYear }
...@@ -176,7 +176,7 @@ void main() { ...@@ -176,7 +176,7 @@ void main() {
expect(localizations.formatFullDate(DateTime(2015, 7, 23)), 'Thursday, 23 July 2015'); expect(localizations.formatFullDate(DateTime(2015, 7, 23)), 'Thursday, 23 July 2015');
localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('es')); localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('es'));
expect(localizations.formatMediumDate(DateTime(2015, 7, 23)), 'jue., 23 jul.'); expect(localizations.formatMediumDate(DateTime(2015, 7, 23)), 'jue, 23 jul');
expect(localizations.formatFullDate(DateTime(2015, 7, 23)), 'jueves, 23 de julio de 2015'); expect(localizations.formatFullDate(DateTime(2015, 7, 23)), 'jueves, 23 de julio de 2015');
localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('de')); localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('de'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment