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
a1a096e3
Unverified
Commit
a1a096e3
authored
Nov 06, 2020
by
Shi-Hao Hong
Committed by
GitHub
Nov 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[gen-l10n] Fix untranslated messages (#68553)
parent
dd8820bc
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
218 additions
and
93 deletions
+218
-93
gen_l10n.dart
dev/tools/localization/bin/gen_l10n.dart
+0
-29
localizations.dart
...ter_tools/lib/src/build_system/targets/localizations.dart
+2
-5
generate_localizations.dart
...lutter_tools/lib/src/commands/generate_localizations.dart
+2
-2
gen_l10n.dart
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
+40
-20
localizations_test.dart
...eneral.shard/build_system/targets/localizations_test.dart
+2
-2
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+171
-34
resident_runner_test.dart
...lutter_tools/test/general.shard/resident_runner_test.dart
+1
-1
No files found.
dev/tools/localization/bin/gen_l10n.dart
deleted
100644 → 0
View file @
dd8820bc
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:io'
;
/// Runs `flutter generate_localizations with arguments passed in.
///
/// This script exists as a legacy entrypoint, since existing users of
/// gen_l10n tool used to call
/// `dart ${FLUTTER}/dev/tools/localizations/bin/gen_l10n.dart <options>` to
/// generate their Flutter project's localizations resources.
///
/// Now, the appropriate way to use this tool is to either define an `l10n.yaml`
/// file in the Flutter project repository, or call
/// `flutter generate_localizations <options>`, since the code has moved
/// into `flutter_tools`.
Future
<
void
>
main
(
List
<
String
>
rawArgs
)
async
{
final
ProcessResult
result
=
await
Process
.
run
(
'flutter'
,
<
String
>[
'generate_localizations'
,
...
rawArgs
,
],
);
stdout
.
write
(
result
.
stdout
);
stderr
.
write
(
result
.
stderr
);
}
packages/flutter_tools/lib/src/build_system/targets/localizations.dart
View file @
a1a096e3
...
@@ -62,13 +62,10 @@ void generateLocalizations({
...
@@ -62,13 +62,10 @@ void generateLocalizations({
useDeferredLoading:
options
.
deferredLoading
??
false
,
useDeferredLoading:
options
.
deferredLoading
??
false
,
useSyntheticPackage:
options
.
useSyntheticPackage
??
true
,
useSyntheticPackage:
options
.
useSyntheticPackage
??
true
,
areResourceAttributesRequired:
options
.
areResourceAttributesRequired
??
false
,
areResourceAttributesRequired:
options
.
areResourceAttributesRequired
??
false
,
untranslatedMessagesFile:
options
?.
untranslatedMessagesFile
?.
toFilePath
(),
)
)
..
loadResources
()
..
loadResources
()
..
writeOutputFiles
()
..
writeOutputFiles
(
logger
);
..
outputUnimplementedMessages
(
options
?.
untranslatedMessagesFile
?.
toFilePath
(),
logger
,
);
}
on
L10nException
catch
(
e
)
{
}
on
L10nException
catch
(
e
)
{
logger
.
printError
(
e
.
message
);
logger
.
printError
(
e
.
message
);
throw
Exception
();
throw
Exception
();
...
...
packages/flutter_tools/lib/src/commands/generate_localizations.dart
View file @
a1a096e3
...
@@ -206,10 +206,10 @@ class GenerateLocalizationsCommand extends FlutterCommand {
...
@@ -206,10 +206,10 @@ class GenerateLocalizationsCommand extends FlutterCommand {
useSyntheticPackage:
useSyntheticPackage
,
useSyntheticPackage:
useSyntheticPackage
,
projectPathString:
projectPathString
,
projectPathString:
projectPathString
,
areResourceAttributesRequired:
areResourceAttributesRequired
,
areResourceAttributesRequired:
areResourceAttributesRequired
,
untranslatedMessagesFile:
untranslatedMessagesFile
,
)
)
..
loadResources
()
..
loadResources
()
..
writeOutputFiles
()
..
writeOutputFiles
(
globals
.
logger
);
..
outputUnimplementedMessages
(
untranslatedMessagesFile
,
globals
.
logger
);
}
on
L10nException
catch
(
e
)
{
}
on
L10nException
catch
(
e
)
{
throwToolExit
(
e
.
message
);
throwToolExit
(
e
.
message
);
}
}
...
...
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
View file @
a1a096e3
...
@@ -520,6 +520,10 @@ class LocalizationsGenerator {
...
@@ -520,6 +520,10 @@ class LocalizationsGenerator {
/// classes.
/// classes.
String
_generatedLocalizationsFile
;
String
_generatedLocalizationsFile
;
/// A generated file that will contain the list of messages for each locale
/// that do not have a translation yet.
File
_untranslatedMessagesFile
;
/// The file that contains the list of inputs and outputs for generating
/// The file that contains the list of inputs and outputs for generating
/// localizations.
/// localizations.
File
_inputsAndOutputsListFile
;
File
_inputsAndOutputsListFile
;
...
@@ -554,6 +558,7 @@ class LocalizationsGenerator {
...
@@ -554,6 +558,7 @@ class LocalizationsGenerator {
bool
useSyntheticPackage
=
true
,
bool
useSyntheticPackage
=
true
,
String
projectPathString
,
String
projectPathString
,
bool
areResourceAttributesRequired
=
false
,
bool
areResourceAttributesRequired
=
false
,
String
untranslatedMessagesFile
,
})
{
})
{
_useSyntheticPackage
=
useSyntheticPackage
;
_useSyntheticPackage
=
useSyntheticPackage
;
setProjectDir
(
projectPathString
);
setProjectDir
(
projectPathString
);
...
@@ -564,6 +569,7 @@ class LocalizationsGenerator {
...
@@ -564,6 +569,7 @@ class LocalizationsGenerator {
setPreferredSupportedLocales
(
preferredSupportedLocale
);
setPreferredSupportedLocales
(
preferredSupportedLocale
);
_setHeader
(
headerString
,
headerFile
);
_setHeader
(
headerString
,
headerFile
);
_setUseDeferredLoading
(
useDeferredLoading
);
_setUseDeferredLoading
(
useDeferredLoading
);
_setUntranslatedMessagesFile
(
untranslatedMessagesFile
);
className
=
classNameString
;
className
=
classNameString
;
_setInputsAndOutputsListFile
(
inputsAndOutputsListPath
);
_setInputsAndOutputsListFile
(
inputsAndOutputsListPath
);
_areResourceAttributesRequired
=
areResourceAttributesRequired
;
_areResourceAttributesRequired
=
areResourceAttributesRequired
;
...
@@ -763,6 +769,16 @@ class LocalizationsGenerator {
...
@@ -763,6 +769,16 @@ class LocalizationsGenerator {
_useDeferredLoading
=
useDeferredLoading
;
_useDeferredLoading
=
useDeferredLoading
;
}
}
void
_setUntranslatedMessagesFile
(
String
untranslatedMessagesFileString
)
{
if
(
untranslatedMessagesFileString
==
null
||
untranslatedMessagesFileString
.
isEmpty
)
{
return
;
}
_untranslatedMessagesFile
=
_fs
.
file
(
globals
.
fs
.
path
.
join
(
untranslatedMessagesFileString
),
);
}
void
_setInputsAndOutputsListFile
(
String
inputsAndOutputsListPath
)
{
void
_setInputsAndOutputsListFile
(
String
inputsAndOutputsListPath
)
{
if
(
inputsAndOutputsListPath
==
null
)
{
if
(
inputsAndOutputsListPath
==
null
)
{
return
;
return
;
...
@@ -1017,7 +1033,7 @@ class LocalizationsGenerator {
...
@@ -1017,7 +1033,7 @@ class LocalizationsGenerator {
.
replaceAll
(
'@(delegateClass)'
,
delegateClass
);
.
replaceAll
(
'@(delegateClass)'
,
delegateClass
);
}
}
void
writeOutputFiles
()
{
void
writeOutputFiles
(
Logger
logger
)
{
// First, generate the string contents of all necessary files.
// First, generate the string contents of all necessary files.
_generateCode
();
_generateCode
();
...
@@ -1054,6 +1070,20 @@ class LocalizationsGenerator {
...
@@ -1054,6 +1070,20 @@ class LocalizationsGenerator {
});
});
baseOutputFile
.
writeAsStringSync
(
_generatedLocalizationsFile
);
baseOutputFile
.
writeAsStringSync
(
_generatedLocalizationsFile
);
if
(
_untranslatedMessagesFile
!=
null
)
{
_generateUntranslatedMessagesFile
(
logger
);
}
else
if
(
_unimplementedMessages
.
isNotEmpty
)
{
_unimplementedMessages
.
forEach
((
LocaleInfo
locale
,
List
<
String
>
messages
)
{
logger
.
printStatus
(
'"
$locale
":
${messages.length}
untranslated message(s).'
);
});
logger
.
printStatus
(
'To see a detailed report, use the --untranslated-messages-file
\n
'
'option in the tool to generate a JSON format file containing
\n
'
'all messages that need to be translated.'
);
}
if
(
_inputsAndOutputsListFile
!=
null
)
{
if
(
_inputsAndOutputsListFile
!=
null
)
{
_outputFileList
.
add
(
baseOutputFile
.
absolute
.
path
);
_outputFileList
.
add
(
baseOutputFile
.
absolute
.
path
);
...
@@ -1071,34 +1101,21 @@ class LocalizationsGenerator {
...
@@ -1071,34 +1101,21 @@ class LocalizationsGenerator {
}
}
}
}
void
outputUnimplementedMessages
(
String
untranslatedMessagesFile
,
Logger
logger
)
{
void
_generateUntranslatedMessagesFile
(
Logger
logger
)
{
if
(
logger
==
null
)
{
if
(
logger
==
null
)
{
throw
L10nException
(
throw
L10nException
(
'Logger must be defined when generating untranslated messages file.'
'Logger must be defined when generating untranslated messages file.'
);
);
}
}
if
(
untranslatedMessagesFile
==
null
||
untranslatedMessagesFile
==
''
)
{
_unimplementedMessages
.
forEach
((
LocaleInfo
locale
,
List
<
String
>
messages
)
{
logger
.
printStatus
(
'"
$locale
":
${messages.length}
untranslated message(s).'
);
});
logger
.
printStatus
(
'To see a detailed report, use the --untranslated-messages-file
\n
'
'option in the tool to generate a JSON format file containing
\n
'
'all messages that need to be translated.'
);
}
else
{
_writeUnimplementedMessagesFile
(
untranslatedMessagesFile
);
}
}
void
_writeUnimplementedMessagesFile
(
String
untranslatedMessagesFile
)
{
if
(
_unimplementedMessages
.
isEmpty
)
{
if
(
_unimplementedMessages
.
isEmpty
)
{
_untranslatedMessagesFile
.
writeAsStringSync
(
'{}'
);
if
(
_inputsAndOutputsListFile
!=
null
)
{
_outputFileList
.
add
(
_untranslatedMessagesFile
.
absolute
.
path
);
}
return
;
return
;
}
}
final
File
unimplementedMessageTranslationsFile
=
_fs
.
file
(
untranslatedMessagesFile
);
String
resultingFile
=
'{
\n
'
;
String
resultingFile
=
'{
\n
'
;
int
count
=
0
;
int
count
=
0
;
final
int
numberOfLocales
=
_unimplementedMessages
.
length
;
final
int
numberOfLocales
=
_unimplementedMessages
.
length
;
...
@@ -1122,6 +1139,9 @@ class LocalizationsGenerator {
...
@@ -1122,6 +1139,9 @@ class LocalizationsGenerator {
});
});
resultingFile
+=
'}
\n
'
;
resultingFile
+=
'}
\n
'
;
unimplementedMessageTranslationsFile
.
writeAsStringSync
(
resultingFile
);
_untranslatedMessagesFile
.
writeAsStringSync
(
resultingFile
);
if
(
_inputsAndOutputsListFile
!=
null
)
{
_outputFileList
.
add
(
_untranslatedMessagesFile
.
absolute
.
path
);
}
}
}
}
}
packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart
View file @
a1a096e3
...
@@ -66,11 +66,11 @@ void main() {
...
@@ -66,11 +66,11 @@ void main() {
useSyntheticPackage:
false
,
useSyntheticPackage:
false
,
projectPathString:
'/'
,
projectPathString:
'/'
,
areResourceAttributesRequired:
true
,
areResourceAttributesRequired:
true
,
untranslatedMessagesFile:
'untranslated'
,
),
),
).
called
(
1
);
).
called
(
1
);
verify
(
mockLocalizationsGenerator
.
loadResources
()).
called
(
1
);
verify
(
mockLocalizationsGenerator
.
loadResources
()).
called
(
1
);
verify
(
mockLocalizationsGenerator
.
writeOutputFiles
()).
called
(
1
);
verify
(
mockLocalizationsGenerator
.
writeOutputFiles
(
logger
)).
called
(
1
);
verify
(
mockLocalizationsGenerator
.
outputUnimplementedMessages
(
'untranslated'
,
logger
)).
called
(
1
);
});
});
testUsingContext
(
'generateLocalizations throws exception on missing flutter: generate: true flag'
,
()
async
{
testUsingContext
(
'generateLocalizations throws exception on missing flutter: generate: true flag'
,
()
async
{
...
...
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
a1a096e3
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/resident_runner_test.dart
View file @
a1a096e3
...
@@ -1444,7 +1444,7 @@ void main() {
...
@@ -1444,7 +1444,7 @@ void main() {
await
residentRunner
.
runSourceGenerators
();
await
residentRunner
.
runSourceGenerators
();
expect
(
testLogger
.
errorText
,
isEmpty
);
expect
(
testLogger
.
errorText
,
isEmpty
);
expect
(
testLogger
.
statusText
,
contains
(
'use the --untranslated-messages-file'
)
);
expect
(
testLogger
.
statusText
,
isEmpty
);
}));
}));
testUsingContext
(
'ResidentRunner can run source generation - generation fails'
,
()
=>
testbed
.
run
(()
async
{
testUsingContext
(
'ResidentRunner can run source generation - generation fails'
,
()
=>
testbed
.
run
(()
async
{
...
...
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