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.
This commit is contained in:
@@ -46,32 +46,39 @@ Future<void> main(List<String> rawArgs) async {
|
||||
|
||||
final bool writeToFile = parseArgs(rawArgs).writeToFile;
|
||||
|
||||
final File dotPackagesFile = File(path.join('packages', 'flutter_localizations', '.packages'));
|
||||
final bool dotPackagesExists = dotPackagesFile.existsSync();
|
||||
final File packageConfigFile = File(path.join('packages', 'flutter_localizations', '.dart_tool', 'package_config.json'));
|
||||
final bool packageConfigExists = packageConfigFile.existsSync();
|
||||
|
||||
if (!dotPackagesExists) {
|
||||
if (!packageConfigExists) {
|
||||
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".'
|
||||
);
|
||||
}
|
||||
|
||||
final String pathToIntl = dotPackagesFile
|
||||
.readAsStringSync()
|
||||
.split('\n')
|
||||
.firstWhere(
|
||||
(String line) => line.startsWith('intl:'),
|
||||
orElse: () {
|
||||
exitWithError('intl dependency not found in ${dotPackagesFile.path}');
|
||||
return ''; // unreachable
|
||||
},
|
||||
)
|
||||
.split(':')
|
||||
.last;
|
||||
final List<Object?> packages = (
|
||||
json.decode(packageConfigFile.readAsStringSync()) as Map<String, Object?>
|
||||
)['packages']! as List<Object?>;
|
||||
|
||||
final Directory dateSymbolsDirectory = Directory(path.join(pathToIntl, 'src', 'data', 'dates', 'symbols'));
|
||||
String? pathToIntl;
|
||||
for (final Object? package in packages) {
|
||||
final Map<String, Object?> packageAsMap = package! as Map<String, Object?>;
|
||||
if (packageAsMap['name'] == 'intl') {
|
||||
pathToIntl = Uri.parse(packageAsMap['rootUri']! as String).toFilePath();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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 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 StringBuffer buffer = StringBuffer();
|
||||
final Set<String> supportedLocales = _supportedLocales();
|
||||
|
||||
Reference in New Issue
Block a user