Unverified Commit be601c26 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Correct gen_date_localizations.dart supported locales computation (#20920)

parent e235ccd7
...@@ -83,7 +83,7 @@ Future<Null> main(List<String> rawArgs) async { ...@@ -83,7 +83,7 @@ Future<Null> main(List<String> rawArgs) async {
// ignore_for_file: public_member_api_docs // ignore_for_file: public_member_api_docs
''' '''
); );
buffer.writeln('const Map<String, dynamic> dateSymbols = const <String, dynamic> {'); buffer.writeln('const Map<String, dynamic> dateSymbols = <String, dynamic> {');
symbolFiles.forEach((String locale, File data) { symbolFiles.forEach((String locale, File data) {
if (materialLocales.contains(locale)) if (materialLocales.contains(locale))
buffer.writeln(_jsonToMapEntry(locale, json.decode(data.readAsStringSync()))); buffer.writeln(_jsonToMapEntry(locale, json.decode(data.readAsStringSync())));
...@@ -92,11 +92,11 @@ Future<Null> main(List<String> rawArgs) async { ...@@ -92,11 +92,11 @@ Future<Null> main(List<String> rawArgs) async {
// Code that uses datePatterns expects it to contain values of type // Code that uses datePatterns expects it to contain values of type
// Map<String, String> not Map<String, dynamic>. // Map<String, String> not Map<String, dynamic>.
buffer.writeln('const Map<String, Map<String, String>> datePatterns = const <String, Map<String, String>> {'); buffer.writeln('const Map<String, Map<String, String>> datePatterns = <String, Map<String, String>> {');
patternFiles.forEach((String locale, File data) { patternFiles.forEach((String locale, File data) {
if (materialLocales.contains(locale)) { if (materialLocales.contains(locale)) {
final Map<String, dynamic> patterns = json.decode(data.readAsStringSync()); final Map<String, dynamic> patterns = json.decode(data.readAsStringSync());
buffer.writeln("'$locale': const <String, String>{"); buffer.writeln("'$locale': <String, String>{");
patterns.forEach((String key, dynamic value) { patterns.forEach((String key, dynamic value) {
assert(value is String); assert(value is String);
buffer.writeln(_jsonToMapEntry(key, value)); buffer.writeln(_jsonToMapEntry(key, value));
...@@ -134,10 +134,10 @@ String _jsonToMap(dynamic json) { ...@@ -134,10 +134,10 @@ String _jsonToMap(dynamic json) {
} }
if (json is Iterable) if (json is Iterable)
return 'const <dynamic>[${json.map(_jsonToMap).join(',')}]'; return '<dynamic>[${json.map(_jsonToMap).join(',')}]';
if (json is Map<String, dynamic>) { if (json is Map<String, dynamic>) {
final StringBuffer buffer = new StringBuffer('const <String, dynamic>{'); final StringBuffer buffer = new StringBuffer('<String, dynamic>{');
json.forEach((String key, dynamic value) { json.forEach((String key, dynamic value) {
buffer.writeln(_jsonToMapEntry(key, value)); buffer.writeln(_jsonToMapEntry(key, value));
}); });
...@@ -149,7 +149,7 @@ String _jsonToMap(dynamic json) { ...@@ -149,7 +149,7 @@ String _jsonToMap(dynamic json) {
} }
Iterable<String> _materialLocales() sync* { Iterable<String> _materialLocales() sync* {
final RegExp filenameRE = new RegExp(r'.*_(\w+)\.arb$'); final RegExp filenameRE = new RegExp(r'material_(\w+)\.arb$');
final Directory materialLocalizationsDirectory = new Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n')); final Directory materialLocalizationsDirectory = new Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
for (FileSystemEntity entity in materialLocalizationsDirectory.listSync()) { for (FileSystemEntity entity in materialLocalizationsDirectory.listSync()) {
final String filePath = entity.path; final String filePath = entity.path;
......
...@@ -110,4 +110,22 @@ void main() { ...@@ -110,4 +110,22 @@ void main() {
expect(localizations.selectedRowCountTitle(10019), '10.019 articole selectate'); expect(localizations.selectedRowCountTitle(10019), '10.019 articole selectate');
expect(localizations.selectedRowCountTitle(123456789), '123.456.789 de articole selectate'); expect(localizations.selectedRowCountTitle(123456789), '123.456.789 de articole selectate');
}); });
testWidgets('spot check formatMediumDate(), formatFullDate() translations', (WidgetTester tester) async {
MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('en', ''));
expect(localizations.formatMediumDate(new DateTime(2015, 7, 23)), 'Thu, Jul 23');
expect(localizations.formatFullDate(new DateTime(2015, 7, 23)), 'Thursday, July 23, 2015');
localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('en', 'GB'));
expect(localizations.formatMediumDate(new DateTime(2015, 7, 23)), 'Thu 23 Jul');
expect(localizations.formatFullDate(new DateTime(2015, 7, 23)), 'Thursday, 23 July 2015');
localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('es', ''));
expect(localizations.formatMediumDate(new DateTime(2015, 7, 23)), 'jue., 23 jul.');
expect(localizations.formatFullDate(new DateTime(2015, 7, 23)), 'jueves, 23 de julio de 2015');
localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('de', ''));
expect(localizations.formatMediumDate(new DateTime(2015, 7, 23)), 'Do., 23. Juli');
expect(localizations.formatFullDate(new DateTime(2015, 7, 23)), 'Donnerstag, 23. Juli 2015');
});
} }
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