[gen_l10n] Fix suppportedLocales list (#52448)
* Fix suppportedLocales list * Refactor integration tests for gen_l10n tool to catch exceptions
This commit is contained in:
@@ -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,34 +76,41 @@ 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 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 END\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 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,81 +43,123 @@ 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(
|
||||
builder: (BuildContext context) {
|
||||
callback(context);
|
||||
return Container();
|
||||
},
|
||||
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();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Home extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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;
|
||||
results.add('--- General formatting tests ---');
|
||||
final AppLocalizations localizations = AppLocalizations.of(context);
|
||||
results.addAll(<String>[
|
||||
'${localizations.helloWorld}',
|
||||
'${localizations.hello("World")}',
|
||||
'${localizations.greeting("Hello", "World")}',
|
||||
'${localizations.helloWorldOn(DateTime(1960))}',
|
||||
'${localizations.helloOn("world argument", DateTime(1960), DateTime(1960))}',
|
||||
'${localizations.helloWorldDuring(DateTime(1960), DateTime(2020))}',
|
||||
'${localizations.helloFor(123)}',
|
||||
'${localizations.helloCost("price", 123)}',
|
||||
'${localizations.helloWorlds(0)}',
|
||||
'${localizations.helloWorlds(1)}',
|
||||
'${localizations.helloWorlds(2)}',
|
||||
'${localizations.helloAdjectiveWorlds(0, "new")}',
|
||||
'${localizations.helloAdjectiveWorlds(1, "new")}',
|
||||
'${localizations.helloAdjectiveWorlds(2, "new")}',
|
||||
'${localizations.helloWorldsOn(0, DateTime(1960))}',
|
||||
'${localizations.helloWorldsOn(1, DateTime(1960))}',
|
||||
'${localizations.helloWorldsOn(2, DateTime(1960))}',
|
||||
'${localizations.helloWorldPopulation(0, 100)}',
|
||||
'${localizations.helloWorldPopulation(1, 101)}',
|
||||
'${localizations.helloWorldPopulation(2, 102)}',
|
||||
'${localizations.helloWorldsInterpolation(123, "Hello", "World")}',
|
||||
'${localizations.singleQuote}',
|
||||
'${localizations.doubleQuote}',
|
||||
]);
|
||||
},
|
||||
),
|
||||
Builder(
|
||||
builder: (BuildContext context) {
|
||||
try {
|
||||
final AppLocalizations localizations = AppLocalizations.of(context);
|
||||
results.addAll(<String>[
|
||||
'${localizations.helloWorld}',
|
||||
'${localizations.hello("World")}',
|
||||
'${localizations.greeting("Hello", "World")}',
|
||||
'${localizations.helloWorldOn(DateTime(1960))}',
|
||||
'${localizations.helloOn("world argument", DateTime(1960), DateTime(1960))}',
|
||||
'${localizations.helloWorldDuring(DateTime(1960), DateTime(2020))}',
|
||||
'${localizations.helloFor(123)}',
|
||||
'${localizations.helloCost("price", 123)}',
|
||||
'${localizations.helloWorlds(0)}',
|
||||
'${localizations.helloWorlds(1)}',
|
||||
'${localizations.helloWorlds(2)}',
|
||||
'${localizations.helloAdjectiveWorlds(0, "new")}',
|
||||
'${localizations.helloAdjectiveWorlds(1, "new")}',
|
||||
'${localizations.helloAdjectiveWorlds(2, "new")}',
|
||||
'${localizations.helloWorldsOn(0, DateTime(1960))}',
|
||||
'${localizations.helloWorldsOn(1, DateTime(1960))}',
|
||||
'${localizations.helloWorldsOn(2, DateTime(1960))}',
|
||||
'${localizations.helloWorldPopulation(0, 100)}',
|
||||
'${localizations.helloWorldPopulation(1, 101)}',
|
||||
'${localizations.helloWorldPopulation(2, 102)}',
|
||||
'${localizations.helloWorldsInterpolation(123, "Hello", "World")}',
|
||||
'${localizations.singleQuote}',
|
||||
'${localizations.doubleQuote}',
|
||||
]);
|
||||
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');
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user