Sort Localization generation output (#44743)

* Sort Localization generation output

- When creating locales that were assumed from existing locales, the
file that is used is non-deterministic. This adds a sort to the iterator
to ensure that the same existing locale is used to generate the assumed
locale
- When generating material, cupertino and date localizations, the generated getters were not sorted. This
introduces an alphabetic sort

* remove main.dart.snapshot
This commit is contained in:
Shi-Hao Hong
2019-11-12 12:50:51 -08:00
committed by GitHub
parent d39e2bb776
commit 2b498567a4
4 changed files with 267 additions and 263 deletions

View File

@@ -99,7 +99,7 @@ String generateArbBasedLocalizationSubclasses({
}
languageToLocales[locale.languageCode] ??= <LocaleInfo>[];
languageToLocales[locale.languageCode].add(locale);
allResourceIdentifiers.addAll(localeToResources[locale].keys);
allResourceIdentifiers.addAll(localeToResources[locale].keys.toList()..sort());
}
// We generate one class per supported language (e.g.
@@ -155,7 +155,7 @@ String generateArbBasedLocalizationSubclasses({
));
output.writeln(generateConstructor(scriptBaseLocale));
final Map<String, String> scriptResources = localeToResources[scriptBaseLocale];
for (String key in scriptResources.keys) {
for (String key in scriptResources.keys.toList()..sort()) {
if (languageResources[key] == scriptResources[key])
continue;
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key];

View File

@@ -12,6 +12,10 @@ import 'package:meta/meta.dart';
typedef HeaderGenerator = String Function(String regenerateInstructions);
typedef ConstructorGenerator = String Function(LocaleInfo locale);
int sortFilesByPath (FileSystemEntity a, FileSystemEntity b) {
return a.path.compareTo(b.path);
}
/// Simple data class to hold parsed locale. Does not promise validity of any data.
class LocaleInfo implements Comparable<LocaleInfo> {
LocaleInfo({
@@ -153,7 +157,7 @@ void loadMatchingArbsIntoBundleMaps({
/// overwrite the existing assumed data.
final Set<LocaleInfo> assumedLocales = <LocaleInfo>{};
for (FileSystemEntity entity in directory.listSync()) {
for (FileSystemEntity entity in directory.listSync().toList()..sort(sortFilesByPath)) {
final String entityPath = entity.path;
if (FileSystemEntity.isFileSync(entityPath) && filenamePattern.hasMatch(entityPath)) {
final String localeString = filenamePattern.firstMatch(entityPath)[1];