Skip to content

Commit 72a4083

Browse files
authored
Cupertino localization step 4: let generated date localization combine material and cupertino locales (flutter#29650)
1 parent 069aabf commit 72a4083

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

dev/tools/localization/gen_date_localizations.dart

+9-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Future<void> main(List<String> rawArgs) async {
6868
final Map<String, File> symbolFiles = _listIntlData(dateSymbolsDirectory);
6969
final Directory datePatternsDirectory = Directory(path.join(pathToIntl, 'src', 'data', 'dates', 'patterns'));
7070
final Map<String, File> patternFiles = _listIntlData(datePatternsDirectory);
71-
final List<String> materialLocales = _materialLocales().toList();
7271
final StringBuffer buffer = StringBuffer();
7372

7473
buffer.writeln(
@@ -88,7 +87,7 @@ Future<void> main(List<String> rawArgs) async {
8887
/// supported by flutter_localizations.''');
8988
buffer.writeln('const Map<String, dynamic> dateSymbols = <String, dynamic> {');
9089
symbolFiles.forEach((String locale, File data) {
91-
if (materialLocales.contains(locale))
90+
if (_supportedLocales().contains(locale))
9291
buffer.writeln(_jsonToMapEntry(locale, json.decode(data.readAsStringSync())));
9392
});
9493
buffer.writeln('};');
@@ -100,7 +99,7 @@ Future<void> main(List<String> rawArgs) async {
10099
/// supported by flutter_localizations.''');
101100
buffer.writeln('const Map<String, Map<String, String>> datePatterns = <String, Map<String, String>> {');
102101
patternFiles.forEach((String locale, File data) {
103-
if (materialLocales.contains(locale)) {
102+
if (_supportedLocales().contains(locale)) {
104103
final Map<String, dynamic> patterns = json.decode(data.readAsStringSync());
105104
buffer.writeln("'$locale': <String, String>{");
106105
patterns.forEach((String key, dynamic value) {
@@ -154,14 +153,16 @@ String _jsonToMap(dynamic json) {
154153
throw 'Unsupported JSON type ${json.runtimeType} of value $json.';
155154
}
156155

157-
Iterable<String> _materialLocales() sync* {
158-
final RegExp filenameRE = RegExp(r'material_(\w+)\.arb$');
159-
final Directory materialLocalizationsDirectory = Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
160-
for (FileSystemEntity entity in materialLocalizationsDirectory.listSync()) {
156+
Set<String> _supportedLocales() {
157+
final Set<String> supportedLocales = <String>{};
158+
final RegExp filenameRE = RegExp(r'(?:material|cupertino)_(\w+)\.arb$');
159+
final Directory supportedLocalesDirectory = Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
160+
for (FileSystemEntity entity in supportedLocalesDirectory.listSync()) {
161161
final String filePath = entity.path;
162162
if (FileSystemEntity.isFileSync(filePath) && filenameRE.hasMatch(filePath))
163-
yield filenameRE.firstMatch(filePath)[1];
163+
supportedLocales.add(filenameRE.firstMatch(filePath)[1]);
164164
}
165+
return supportedLocales;
165166
}
166167

167168
Map<String, File> _listIntlData(Directory directory) {

0 commit comments

Comments
 (0)