Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
94ca7b4a
Unverified
Commit
94ca7b4a
authored
Nov 18, 2020
by
Shi-Hao Hong
Committed by
GitHub
Nov 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[gen-l10n] NNBD generated code (#70415)
* NNBD gen-l10n generated code
parent
d8167b90
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
34 deletions
+55
-34
pub.dart
packages/flutter_tools/lib/src/dart/pub.dart
+1
-1
gen_l10n_templates.dart
...utter_tools/lib/src/localizations/gen_l10n_templates.dart
+17
-7
gen_l10n_project.dart
...ls/test/integration.shard/test_data/gen_l10n_project.dart
+37
-26
No files found.
packages/flutter_tools/lib/src/dart/pub.dart
View file @
94ca7b4a
...
...
@@ -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
;
}
...
...
packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart
View file @
94ca7b4a
...
...
@@ -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 = '''
...
...
packages/flutter_tools/test/integration.shard/test_data/gen_l10n_project.dart
View file @
94ca7b4a
...
...
@@ -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
)}
',
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment