Unverified Commit 183da8f8 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

[gen_l10n] Fix suppportedLocales list (#52448)

* Fix suppportedLocales list

* Refactor integration tests for gen_l10n tool to catch exceptions
parent d98213c4
......@@ -532,7 +532,7 @@ class LocalizationsGenerator {
final Iterable<String> supportedLocalesCode = supportedLocales.map((LocaleInfo locale) {
final String country = locale.countryCode;
final String countryArg = country == null ? '' : ', $country';
final String countryArg = country == null ? '' : "', '$country";
return 'Locale(\'${locale.languageCode}$countryArg\')';
});
......
......@@ -76,33 +76,40 @@ void main() {
await l10nEnd.future;
await subscription.cancel();
expect(stdout.toString(),
'#l10n 0 (CA Hello World)\n'
'#l10n 1 (Hello CA fallback World)\n'
'#l10n 2 (GB Hello World)\n'
'#l10n 3 (Hello GB fallback World)\n'
'#l10n 4 (Hello World)\n'
'#l10n 5 (Hello World)\n'
'#l10n 6 (Hello World)\n'
'#l10n 7 (Hello World on Friday, January 1, 1960)\n'
'#l10n 8 (Hello world argument on 1/1/1960 at 00:00)\n'
'#l10n 9 (Hello World from 1960 to 2020)\n'
'#l10n 10 (Hello for 123)\n'
'#l10n 11 (Hello for price USD123.00)\n'
'#l10n 12 (Hello)\n'
'#l10n 0 (--- supportedLocales tests ---)\n'
'#l10n 1 (supportedLocales[0]: languageCode: en, countryCode: null, scriptCode: null)\n'
'#l10n 2 (supportedLocales[1]: languageCode: en, countryCode: CA, scriptCode: null)\n'
'#l10n 3 (supportedLocales[2]: languageCode: en, countryCode: GB, scriptCode: null)\n'
'#l10n 4 (--- countryCode (en_CA) tests ---)\n'
'#l10n 5 (CA Hello World)\n'
'#l10n 6 (Hello CA fallback World)\n'
'#l10n 7 (--- countryCode (en_GB) tests ---)\n'
'#l10n 8 (GB Hello World)\n'
'#l10n 9 (Hello GB fallback World)\n'
'#l10n 10 (--- General formatting tests ---)\n'
'#l10n 11 (Hello World)\n'
'#l10n 12 (Hello World)\n'
'#l10n 13 (Hello World)\n'
'#l10n 14 (Hello two worlds)\n'
'#l10n 15 (Hello)\n'
'#l10n 16 (Hello new World)\n'
'#l10n 17 (Hello two new worlds)\n'
'#l10n 18 (Hello on Friday, January 1, 1960)\n'
'#l10n 19 (Hello World, on Friday, January 1, 1960)\n'
'#l10n 20 (Hello two worlds, on Friday, January 1, 1960)\n'
'#l10n 21 (Hello other 0 worlds, with a total of 100 citizens)\n'
'#l10n 22 (Hello World of 101 citizens)\n'
'#l10n 23 (Hello two worlds with 102 total citizens)\n'
'#l10n 24 ([Hello] -World- #123#)\n'
'#l10n 25 (Flutter\'s amazing!)\n'
'#l10n 26 (Flutter is "amazing"!)\n'
'#l10n 14 (Hello World on Friday, January 1, 1960)\n'
'#l10n 15 (Hello world argument on 1/1/1960 at 00:00)\n'
'#l10n 16 (Hello World from 1960 to 2020)\n'
'#l10n 17 (Hello for 123)\n'
'#l10n 18 (Hello for price USD123.00)\n'
'#l10n 19 (Hello)\n'
'#l10n 20 (Hello World)\n'
'#l10n 21 (Hello two worlds)\n'
'#l10n 22 (Hello)\n'
'#l10n 23 (Hello new World)\n'
'#l10n 24 (Hello two new worlds)\n'
'#l10n 25 (Hello on Friday, January 1, 1960)\n'
'#l10n 26 (Hello World, on Friday, January 1, 1960)\n'
'#l10n 27 (Hello two worlds, on Friday, January 1, 1960)\n'
'#l10n 28 (Hello other 0 worlds, with a total of 100 citizens)\n'
'#l10n 29 (Hello World of 101 citizens)\n'
'#l10n 30 (Hello two worlds with 102 total citizens)\n'
'#l10n 31 ([Hello] -World- #123#)\n'
'#l10n 32 (Flutter\'s amazing!)\n'
'#l10n 33 (Flutter is "amazing"!)\n'
'#l10n END\n'
);
});
......
......@@ -43,19 +43,37 @@ import 'package:flutter/material.dart';
import 'l10n/app_localizations.dart';
class LocaleBuilder extends StatelessWidget {
const LocaleBuilder({ Key key, this.locale, this.callback }) : super(key: key);
const LocaleBuilder({ Key key, this.locale, this.test, this.callback }) : super(key: key);
final Locale locale;
final String test;
final void Function (BuildContext context) callback;
@override build(BuildContext context) {
return Localizations.override(
locale: locale,
context: context,
child: Builder(
child: ResultBuilder(
test: test,
callback: callback,
),
);
}
}
class ResultBuilder extends StatelessWidget {
const ResultBuilder({ Key key, this.test, this.callback }) : super(key: key);
final String test;
final void Function (BuildContext context) callback;
@override build(BuildContext context) {
return Builder(
builder: (BuildContext context) {
try {
callback(context);
} on Exception catch (e) {
print('#l10n A(n) $e has occurred trying to generate "$test" results.');
print('#l10n END');
}
return Container();
},
),
);
}
}
......@@ -66,25 +84,43 @@ class Home extends StatelessWidget {
final List<String> results = [];
return Row(
children: <Widget>[
ResultBuilder(
test: 'supportedLocales',
callback: (BuildContext context) {
results.add('--- supportedLocales tests ---');
int n = 0;
for (Locale locale in AppLocalizations.supportedLocales) {
String languageCode = locale.languageCode;
String countryCode = locale.countryCode;
String scriptCode = locale.scriptCode;
results.add('supportedLocales[$n]: languageCode: $languageCode, countryCode: $countryCode, scriptCode: $scriptCode');
n += 1;
}
},
),
LocaleBuilder(
locale: Locale('en', 'CA'),
test: 'countryCode - en_CA',
callback: (BuildContext context) {
results.add('--- countryCode (en_CA) tests ---');
results.add(AppLocalizations.of(context).helloWorld);
results.add(AppLocalizations.of(context).hello("CA fallback World"));
},
),
LocaleBuilder(
locale: Locale('en', 'GB'),
test: 'countryCode - en_GB',
callback: (BuildContext context) {
results.add('--- countryCode (en_GB) tests ---');
results.add(AppLocalizations.of(context).helloWorld);
results.add(AppLocalizations.of(context).hello("GB fallback World"));
},
),
LocaleBuilder(
locale: Locale('en'),
test: 'General formatting',
callback: (BuildContext context) {
int n = 0;
try {
results.add('--- General formatting tests ---');
final AppLocalizations localizations = AppLocalizations.of(context);
results.addAll(<String>[
'${localizations.helloWorld}',
......@@ -111,13 +147,19 @@ class Home extends StatelessWidget {
'${localizations.singleQuote}',
'${localizations.doubleQuote}',
]);
},
),
Builder(
builder: (BuildContext context) {
try {
int n = 0;
for (final String result in results) {
print('#l10n $n ($result)\n');
print('#l10n $n ($result)');
n += 1;
}
}
finally {
print('#l10n END\n');
print('#l10n END');
}
},
),
......
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