Unverified Commit 4d663472 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

[gen_l10n] Improve status message when untranslated messages are still present (#72944)

parent 14cbd6d7
......@@ -66,7 +66,7 @@ void generateLocalizations({
untranslatedMessagesFile: options?.untranslatedMessagesFile?.toFilePath(),
)
..loadResources()
..writeOutputFiles(logger);
..writeOutputFiles(logger, isFromYaml: true);
} on L10nException catch (e) {
logger.printError(e.message);
throw Exception();
......
......@@ -1033,7 +1033,7 @@ class LocalizationsGenerator {
.replaceAll('@(delegateClass)', delegateClass);
}
void writeOutputFiles(Logger logger) {
void writeOutputFiles(Logger logger, { bool isFromYaml = false }) {
// First, generate the string contents of all necessary files.
_generateCode();
......@@ -1077,10 +1077,25 @@ class LocalizationsGenerator {
_unimplementedMessages.forEach((LocaleInfo locale, List<String> messages) {
logger.printStatus('"$locale": ${messages.length} untranslated message(s).');
});
if (isFromYaml) {
logger.printStatus(
'To see a detailed report, use the untranslated-messages-file \n'
'option in the l10n.yaml file:\n'
'untranslated-messages-file: desiredFileName.txt\n'
'<other option>: <other selection> \n\n'
);
} else {
logger.printStatus(
'To see a detailed report, use the --untranslated-messages-file \n'
'option in the flutter gen-l10n tool:\n'
'flutter gen-l10n --untranslated-messages-file=desiredFileName.txt\n'
'<other options> \n\n'
);
}
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.'
'This will generate a JSON format file containing all messages that \n'
'need to be translated.'
);
}
......
......@@ -70,7 +70,7 @@ void main() {
),
).called(1);
verify(mockLocalizationsGenerator.loadResources()).called(1);
verify(mockLocalizationsGenerator.writeOutputFiles(logger)).called(1);
verify(mockLocalizationsGenerator.writeOutputFiles(logger, isFromYaml: true)).called(1);
});
testUsingContext('generateLocalizations throws exception on missing flutter: generate: true flag', () async {
......
......@@ -548,7 +548,8 @@ void main() {
});
test(
'untranslated messages suggestion is printed when translation is missing',
'untranslated messages suggestion is printed when translation is missing: '
'command line message',
() {
final BufferLogger testLogger = BufferLogger.test();
fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
......@@ -566,6 +567,7 @@ void main() {
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
useSyntheticPackage: false,
)
..loadResources()
..writeOutputFiles(testLogger);
......@@ -573,7 +575,51 @@ void main() {
fail('Generating output should not fail: \n${e.message}');
}
expect(testLogger.statusText, contains('To see a detailed report, use the --untranslated-messages-file'));
expect(
testLogger.statusText,
contains('To see a detailed report, use the --untranslated-messages-file'),
);
expect(
testLogger.statusText,
contains('flutter gen-l10n --untranslated-messages-file=desiredFileName.txt'),
);
},
);
test(
'untranslated messages suggestion is printed when translation is missing: '
'l10n.yaml message',
() {
final BufferLogger testLogger = BufferLogger.test();
fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true)
..childFile(defaultTemplateArbFileName).writeAsStringSync(twoMessageArbFileString)
..childFile(esArbFileName).writeAsStringSync(singleEsMessageArbFileString);
LocalizationsGenerator generator;
try {
generator = LocalizationsGenerator(fs);
generator
..initialize(
inputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
)
..loadResources()
..writeOutputFiles(testLogger, isFromYaml: true);
} on L10nException catch (e) {
fail('Generating output should not fail: \n${e.message}');
}
expect(
testLogger.statusText,
contains('To see a detailed report, use the untranslated-messages-file'),
);
expect(
testLogger.statusText,
contains('untranslated-messages-file: desiredFileName.txt'),
);
},
);
......
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