Unverified Commit 94ca7b4a authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

[gen-l10n] NNBD generated code (#70415)

* NNBD gen-l10n generated code
parent d8167b90
......@@ -455,7 +455,7 @@ class _DefaultPub implements Pub {
if (!generateSyntheticPackage) {
return;
}
final Package flutterGen = Package('flutter_gen', generatedDirectory.uri, languageVersion: LanguageVersion(2, 8));
final Package flutterGen = Package('flutter_gen', generatedDirectory.uri, languageVersion: LanguageVersion(2, 12));
if (packageConfig.packages.any((Package package) => package.name == 'flutter_gen')) {
return;
}
......
......@@ -47,7 +47,7 @@ import 'package:intl/intl.dart' as intl;
/// # Internationalization support.
/// flutter_localizations:
/// sdk: flutter
/// intl: 0.17.0-nullsafety.2
/// intl: ^0.17.0-nullsafety.2
///
/// # rest of dependencies
/// ```
......@@ -72,12 +72,12 @@ import 'package:intl/intl.dart' as intl;
/// be consistent with the languages listed in the @(class).supportedLocales
/// property.
abstract class @(class) {
@(class)(String locale) : assert(locale != null), localeName = intl.Intl.canonicalizedLocale(locale.toString());
@(class)(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
// ignore: unused_field
final String localeName;
static @(class) of(BuildContext context) {
static @(class)? of(BuildContext context) {
return Localizations.of<@(class)>(context, @(class));
}
......@@ -222,15 +222,25 @@ const String loadBodyDeferredLoadingTemplate = '''return @(lookupName)(locale);'
const String lookupFunctionTemplate = r'''
@(class) @(lookupName)(Locale locale) {
@(lookupBody)
assert(false, '@(class).delegate failed to load unsupported locale "$locale"');
return null;
throw FlutterError(
'@(class).delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.'
);
}''';
const String lookupFunctionDeferredLoadingTemplate = r'''
Future<@(class)> @(lookupName)(Locale locale) {
@(lookupBody)
assert(false, '@(class).delegate failed to load unsupported locale "$locale"');
return null;
throw FlutterError(
'@(class).delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.'
);
}''';
const String lookupBodyTemplate = '''
......
......@@ -35,7 +35,7 @@ class GenL10nProject extends Project {
final String pubspec = '''
name: test
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
dependencies:
flutter:
......@@ -47,17 +47,22 @@ dependencies:
@override
final String main = r'''
// @dart = 2.8
// generated localizations do not support null safety.
import 'package:flutter/material.dart';
import 'l10n/app_localizations.dart';
class LocaleBuilder extends StatelessWidget {
const LocaleBuilder({ Key key, this.locale, this.test, this.callback }) : super(key: key);
final Locale locale;
final String test;
const LocaleBuilder({
Key? key,
this.locale,
this.test,
required 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,
......@@ -71,9 +76,15 @@ class LocaleBuilder extends StatelessWidget {
}
class ResultBuilder extends StatelessWidget {
const ResultBuilder({ Key key, this.test, this.callback }) : super(key: key);
final String test;
const ResultBuilder({
Key? key,
this.test,
required this.callback,
}) : super(key: key);
final String? test;
final void Function (BuildContext context) callback;
@override build(BuildContext context) {
return Builder(
builder: (BuildContext context) {
......@@ -102,8 +113,8 @@ class Home extends StatelessWidget {
int n = 0;
for (Locale locale in AppLocalizations.supportedLocales) {
String languageCode = locale.languageCode;
String countryCode = locale.countryCode;
String scriptCode = locale.scriptCode;
String? countryCode = locale.countryCode;
String? scriptCode = locale.scriptCode;
results.add('supportedLocales[$n]: languageCode: $languageCode, countryCode: $countryCode, scriptCode: $scriptCode');
n += 1;
}
......@@ -114,8 +125,8 @@ class Home extends StatelessWidget {
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"));
results.add(AppLocalizations.of(context)!.helloWorld);
results.add(AppLocalizations.of(context)!.hello("CA fallback World"));
},
),
LocaleBuilder(
......@@ -123,8 +134,8 @@ class Home extends StatelessWidget {
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"));
results.add(AppLocalizations.of(context)!.helloWorld);
results.add(AppLocalizations.of(context)!.hello("GB fallback World"));
},
),
LocaleBuilder(
......@@ -132,17 +143,17 @@ class Home extends StatelessWidget {
test: 'zh',
callback: (BuildContext context) {
results.add('--- zh ---');
results.add(AppLocalizations.of(context).helloWorld);
results.add(AppLocalizations.of(context).helloWorlds(0));
results.add(AppLocalizations.of(context).helloWorlds(1));
results.add(AppLocalizations.of(context).helloWorlds(2));
results.add(AppLocalizations.of(context)!.helloWorld);
results.add(AppLocalizations.of(context)!.helloWorlds(0));
results.add(AppLocalizations.of(context)!.helloWorlds(1));
results.add(AppLocalizations.of(context)!.helloWorlds(2));
// Should use the fallback language, in this case,
// "Hello 世界" should be displayed.
results.add(AppLocalizations.of(context).hello("世界"));
results.add(AppLocalizations.of(context)!.hello("世界"));
// helloCost is tested in 'zh' because 'es' currency format contains a
// non-breaking space character (U+00A0), which if removed,
// makes it hard to decipher why the test is failing.
results.add(AppLocalizations.of(context).helloCost("价钱", 123));
results.add(AppLocalizations.of(context)!.helloCost("价钱", 123));
},
),
LocaleBuilder(
......@@ -150,7 +161,7 @@ class Home extends StatelessWidget {
test: 'zh',
callback: (BuildContext context) {
results.add('--- scriptCode: zh_Hans ---');
results.add(AppLocalizations.of(context).helloWorld);
results.add(AppLocalizations.of(context)!.helloWorld);
},
),
LocaleBuilder(
......@@ -158,7 +169,7 @@ class Home extends StatelessWidget {
test: 'scriptCode - zh_Hant',
callback: (BuildContext context) {
results.add('--- scriptCode - zh_Hant ---');
results.add(AppLocalizations.of(context).helloWorld);
results.add(AppLocalizations.of(context)!.helloWorld);
},
),
LocaleBuilder(
......@@ -166,7 +177,7 @@ class Home extends StatelessWidget {
test: 'scriptCode - zh_TW_Hant',
callback: (BuildContext context) {
results.add('--- scriptCode - zh_Hant_TW ---');
results.add(AppLocalizations.of(context).helloWorld);
results.add(AppLocalizations.of(context)!.helloWorld);
},
),
LocaleBuilder(
......@@ -174,7 +185,7 @@ class Home extends StatelessWidget {
test: 'General formatting',
callback: (BuildContext context) {
results.add('--- General formatting tests ---');
final AppLocalizations localizations = AppLocalizations.of(context);
final AppLocalizations localizations = AppLocalizations.of(context)!;
results.addAll(<String>[
'${localizations.helloWorld}',
'${localizations.helloNewlineWorld}',
......@@ -213,7 +224,7 @@ class Home extends StatelessWidget {
test: '--- es ---',
callback: (BuildContext context) {
results.add('--- es ---');
final AppLocalizations localizations = AppLocalizations.of(context);
final AppLocalizations localizations = AppLocalizations.of(context)!;
results.addAll(<String>[
'${localizations.helloWorld}',
'${localizations.helloNewlineWorld}',
......@@ -254,7 +265,7 @@ class Home extends StatelessWidget {
test: 'countryCode - es_419',
callback: (BuildContext context) {
results.add('--- es_419 ---');
final AppLocalizations localizations = AppLocalizations.of(context);
final AppLocalizations localizations = AppLocalizations.of(context)!;
results.addAll([
'${localizations.helloWorld}',
'${localizations.helloWorlds(0)}',
......
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