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
9077a5c6
Unverified
Commit
9077a5c6
authored
Apr 01, 2021
by
Shi-Hao Hong
Committed by
GitHub
Apr 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[gen-l10n] Remove more ignores, conditionally generate some code (#78975)
parent
04ebce92
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
3 deletions
+59
-3
gen_l10n.dart
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
+1
-0
gen_l10n_templates.dart
...utter_tools/lib/src/localizations/gen_l10n_templates.dart
+1
-3
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+57
-0
No files found.
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
View file @
9077a5c6
...
...
@@ -1169,6 +1169,7 @@ class LocalizationsGenerator {
.
replaceAll
(
'@(supportedLanguageCodes)'
,
supportedLanguageCodes
.
join
(
', '
))
.
replaceAll
(
'@(messageClassImports)'
,
sortedClassImports
.
join
(
'
\n
'
))
.
replaceAll
(
'@(delegateClass)'
,
delegateClass
)
.
replaceAll
(
'@(requiresFoundationImport)'
,
_useDeferredLoading
?
''
:
"import 'package:flutter/foundation.dart';"
)
.
replaceAll
(
'@(requiresIntlImport)'
,
_containsPluralMessage
()
?
"import 'package:intl/intl.dart' as intl;"
:
''
)
.
replaceAll
(
'@(canBeNullable)'
,
_usesNullableGetter
?
'?'
:
''
)
.
replaceAll
(
'@(needsNullCheck)'
,
_usesNullableGetter
?
''
:
'!'
);
...
...
packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart
View file @
9077a5c6
...
...
@@ -12,8 +12,7 @@ const String fileTemplate = '''
@
(
header
)
import
'dart:async'
;
// ignore: unused_import
import
'package:flutter/foundation.dart'
;
@
(
requiresFoundationImport
)
import
'package:flutter/widgets.dart'
;
import
'package:flutter_localizations/flutter_localizations.dart'
;
import
'package:intl/intl.dart'
as
intl
;
...
...
@@ -74,7 +73,6 @@ import 'package:intl/intl.dart' as intl;
abstract
class
@(
class
)
{
@
(
class
)(
String
locale
)
:
localeName
=
intl
.
Intl
.
canonicalizedLocale
(
locale
.
toString
());
// ignore: unused_field
final
String
localeName
;
static
@
(
class
)@(
canBeNullable
)
of
(
BuildContext
context
)
{
...
...
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
9077a5c6
...
...
@@ -57,6 +57,9 @@ const String singleZhMessageArbFileString = '''
const
String
intlImportDartCode
=
'''
import '
package:
intl
/
intl
.
dart
' as intl;
'''
;
const
String
foundationImportDartCode
=
'''
import '
package:
flutter
/
foundation
.
dart
';
'''
;
void
_standardFlutterDirectoryL10nSetup
(
FileSystem
fs
)
{
final
Directory
l10nDirectory
=
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)
...
...
@@ -1882,6 +1885,60 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
expect
(
localizationsFile
,
contains
(
intlImportDartCode
));
});
testUsingContext
(
'foundation package import should be omitted from file template when deferred loading = true'
,
()
{
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)..
createSync
(
recursive:
true
)
..
childFile
(
defaultTemplateArbFileName
).
writeAsStringSync
(
singleMessageArbFileString
)
..
childFile
(
'app_es.arb'
).
writeAsStringSync
(
singleEsMessageArbFileString
);
final
LocalizationsGenerator
generator
=
LocalizationsGenerator
(
fs
);
try
{
generator
.
initialize
(
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
defaultOutputFileString
,
classNameString:
defaultClassNameString
,
useDeferredLoading:
true
,
);
generator
.
loadResources
();
generator
.
writeOutputFiles
(
BufferLogger
.
test
());
}
on
Exception
catch
(
e
)
{
fail
(
'Generating output files should not fail:
$e
'
);
}
final
String
localizationsFile
=
fs
.
file
(
fs
.
path
.
join
(
syntheticL10nPackagePath
,
'output-localization-file.dart'
),
).
readAsStringSync
();
expect
(
localizationsFile
,
isNot
(
contains
(
foundationImportDartCode
)));
});
testUsingContext
(
'foundation package import should be kept in file template when deferred loading = false'
,
()
{
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)..
createSync
(
recursive:
true
)
..
childFile
(
defaultTemplateArbFileName
).
writeAsStringSync
(
singleMessageArbFileString
)
..
childFile
(
'app_es.arb'
).
writeAsStringSync
(
singleEsMessageArbFileString
);
final
LocalizationsGenerator
generator
=
LocalizationsGenerator
(
fs
);
try
{
generator
.
initialize
(
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
defaultOutputFileString
,
classNameString:
defaultClassNameString
,
useDeferredLoading:
false
,
);
generator
.
loadResources
();
generator
.
writeOutputFiles
(
BufferLogger
.
test
());
}
on
Exception
catch
(
e
)
{
fail
(
'Generating output files should not fail:
$e
'
);
}
final
String
localizationsFile
=
fs
.
file
(
fs
.
path
.
join
(
syntheticL10nPackagePath
,
'output-localization-file.dart'
),
).
readAsStringSync
();
expect
(
localizationsFile
,
contains
(
foundationImportDartCode
));
});
testUsingContext
(
'check for string interpolation rules'
,
()
{
const
String
enArbCheckList
=
'''
{
...
...
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