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
b4175e9b
Unverified
Commit
b4175e9b
authored
Apr 20, 2021
by
Jenn Magder
Committed by
GitHub
Apr 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor LocalizationsGenerator initialize instance method into factory (#80605)
parent
42f21fd7
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
574 additions
and
685 deletions
+574
-685
localizations.dart
...ter_tools/lib/src/build_system/targets/localizations.dart
+1
-1
generate_localizations.dart
...lutter_tools/lib/src/commands/generate_localizations.dart
+19
-21
gen_l10n.dart
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
+178
-162
localizations_test.dart
...eneral.shard/build_system/targets/localizations_test.dart
+0
-109
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+376
-392
No files found.
packages/flutter_tools/lib/src/build_system/targets/localizations.dart
View file @
b4175e9b
...
...
@@ -63,7 +63,7 @@ class GenerateLocalizationsTarget extends Target {
options:
options
,
projectDir:
environment
.
projectDir
,
dependenciesDir:
environment
.
buildDir
,
localizationsGenerator:
LocalizationsGenerator
(
environment
.
fileSystem
)
,
fileSystem:
environment
.
fileSystem
,
);
final
Map
<
String
,
Object
>
dependencies
=
json
.
decode
(
...
...
packages/flutter_tools/lib/src/commands/generate_localizations.dart
View file @
b4175e9b
...
...
@@ -212,7 +212,7 @@ class GenerateLocalizationsCommand extends FlutterCommand {
options:
options
,
projectDir:
_fileSystem
.
currentDirectory
,
dependenciesDir:
null
,
localizationsGenerator:
LocalizationsGenerator
(
_fileSystem
)
,
fileSystem:
_fileSystem
,
);
return
FlutterCommandResult
.
success
();
}
...
...
@@ -233,29 +233,27 @@ class GenerateLocalizationsCommand extends FlutterCommand {
final
bool
areResourceAttributesRequired
=
boolArg
(
'required-resource-attributes'
);
final
bool
usesNullableGetter
=
boolArg
(
'nullable-getter'
);
final
LocalizationsGenerator
localizationsGenerator
=
LocalizationsGenerator
(
_fileSystem
);
precacheLanguageAndRegionTags
();
try
{
localizationsGenerator
..
initialize
(
inputPathString:
inputPathString
,
outputPathString:
outputPathString
,
templateArbFileName:
templateArbFileName
,
outputFileString:
outputFileString
,
classNameString:
classNameString
,
preferredSupportedLocales:
preferredSupportedLocales
,
headerString:
headerString
,
headerFile:
headerFile
,
useDeferredLoading:
useDeferredLoading
,
inputsAndOutputsListPath:
inputsAndOutputsListPath
,
useSyntheticPackage:
useSyntheticPackage
,
projectPathString:
projectPathString
,
areResourceAttributesRequired:
areResourceAttributesRequired
,
untranslatedMessagesFile:
untranslatedMessagesFile
,
usesNullableGetter:
usesNullableGetter
,
)
LocalizationsGenerator
(
fileSystem:
_fileSystem
,
inputPathString:
inputPathString
,
outputPathString:
outputPathString
,
templateArbFileName:
templateArbFileName
,
outputFileString:
outputFileString
,
classNameString:
classNameString
,
preferredSupportedLocales:
preferredSupportedLocales
,
headerString:
headerString
,
headerFile:
headerFile
,
useDeferredLoading:
useDeferredLoading
,
inputsAndOutputsListPath:
inputsAndOutputsListPath
,
useSyntheticPackage:
useSyntheticPackage
,
projectPathString:
projectPathString
,
areResourceAttributesRequired:
areResourceAttributesRequired
,
untranslatedMessagesFile:
untranslatedMessagesFile
,
usesNullableGetter:
usesNullableGetter
,
)
..
loadResources
()
..
writeOutputFiles
(
_logger
);
}
on
L10nException
catch
(
e
)
{
...
...
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
View file @
b4175e9b
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart
View file @
b4175e9b
...
...
@@ -9,119 +9,12 @@ import 'package:flutter_tools/src/base/file_system.dart';
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/build_system/build_system.dart'
;
import
'package:flutter_tools/src/build_system/targets/localizations.dart'
;
import
'package:flutter_tools/src/localizations/gen_l10n.dart'
;
import
'package:flutter_tools/src/localizations/localizations_utils.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../../../src/common.dart'
;
import
'../../../src/fake_process_manager.dart'
;
void
main
(
)
{
// Verifies that values are correctly passed through the localizations
// target, but does not validate them beyond the serialized data type.
testWithoutContext
(
'generateLocalizations forwards arguments correctly'
,
()
async
{
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
Logger
logger
=
BufferLogger
.
test
();
final
Directory
flutterProjectDirectory
=
fileSystem
.
directory
(
fileSystem
.
path
.
join
(
'path'
,
'to'
,
'flutter_project'
))
..
createSync
(
recursive:
true
);
final
Directory
arbDirectory
=
flutterProjectDirectory
.
childDirectory
(
'arb'
)
..
createSync
();
arbDirectory
.
childFile
(
'foo.arb'
).
createSync
();
arbDirectory
.
childFile
(
'bar.arb'
).
createSync
();
final
LocalizationOptions
options
=
LocalizationOptions
(
header:
'HEADER'
,
headerFile:
Uri
.
file
(
'header'
),
arbDirectory:
Uri
.
file
(
'arb'
),
deferredLoading:
true
,
outputClass:
'Foo'
,
outputLocalizationsFile:
Uri
.
file
(
'bar'
),
outputDirectory:
Uri
.
directory
(
fileSystem
.
path
.
join
(
'lib'
,
'l10n'
)),
preferredSupportedLocales:
<
String
>[
'en_US'
],
templateArbFile:
Uri
.
file
(
'example.arb'
),
untranslatedMessagesFile:
Uri
.
file
(
'untranslated'
),
useSyntheticPackage:
false
,
areResourceAttributesRequired:
true
,
usesNullableGetter:
false
,
);
final
LocalizationsGenerator
mockLocalizationsGenerator
=
MockLocalizationsGenerator
();
generateLocalizations
(
localizationsGenerator:
mockLocalizationsGenerator
,
options:
options
,
logger:
logger
,
projectDir:
fileSystem
.
currentDirectory
,
dependenciesDir:
fileSystem
.
currentDirectory
,
);
verify
(
mockLocalizationsGenerator
.
initialize
(
inputPathString:
'arb'
,
outputPathString:
fileSystem
.
path
.
join
(
'lib'
,
'l10n/'
),
templateArbFileName:
'example.arb'
,
outputFileString:
'bar'
,
classNameString:
'Foo'
,
preferredSupportedLocales:
<
String
>[
'en_US'
],
headerString:
'HEADER'
,
headerFile:
'header'
,
useDeferredLoading:
true
,
inputsAndOutputsListPath:
'/'
,
useSyntheticPackage:
false
,
projectPathString:
'/'
,
areResourceAttributesRequired:
true
,
untranslatedMessagesFile:
'untranslated'
,
usesNullableGetter:
false
,
),
).
called
(
1
);
verify
(
mockLocalizationsGenerator
.
loadResources
()).
called
(
1
);
verify
(
mockLocalizationsGenerator
.
writeOutputFiles
(
logger
,
isFromYaml:
true
)).
called
(
1
);
});
testWithoutContext
(
'generateLocalizations throws exception on missing flutter: generate: true flag'
,
()
async
{
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
Directory
arbDirectory
=
fileSystem
.
directory
(
'arb'
)
..
createSync
();
arbDirectory
.
childFile
(
'foo.arb'
).
createSync
();
arbDirectory
.
childFile
(
'bar.arb'
).
createSync
();
// Missing flutter: generate: true should throw exception.
fileSystem
.
file
(
'pubspec.yaml'
).
writeAsStringSync
(
'''
flutter:
uses-material-design: true
'''
);
final
LocalizationOptions
options
=
LocalizationOptions
(
header:
'HEADER'
,
headerFile:
Uri
.
file
(
'header'
),
arbDirectory:
Uri
.
file
(
'arb'
),
deferredLoading:
true
,
outputClass:
'Foo'
,
outputLocalizationsFile:
Uri
.
file
(
'bar'
),
preferredSupportedLocales:
<
String
>[
'en_US'
],
templateArbFile:
Uri
.
file
(
'example.arb'
),
untranslatedMessagesFile:
Uri
.
file
(
'untranslated'
),
// Set synthetic package to true.
useSyntheticPackage:
true
,
);
final
LocalizationsGenerator
mockLocalizationsGenerator
=
MockLocalizationsGenerator
();
expect
(
()
=>
generateLocalizations
(
localizationsGenerator:
mockLocalizationsGenerator
,
options:
options
,
logger:
logger
,
projectDir:
fileSystem
.
currentDirectory
,
dependenciesDir:
fileSystem
.
currentDirectory
,
),
throwsToolExit
(
message:
'Attempted to generate localizations code without having the '
'flutter: generate flag turned on.'
,
),
);
});
testWithoutContext
(
'generateLocalizations is skipped if l10n.yaml does not exist.'
,
()
async
{
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
Environment
environment
=
Environment
.
test
(
...
...
@@ -207,5 +100,3 @@ use-deferred-loading: string
);
});
}
class
MockLocalizationsGenerator
extends
Mock
implements
LocalizationsGenerator
{}
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
b4175e9b
This diff is collapsed.
Click to expand it.
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