diff --git a/packages/flutter_tools/lib/src/build_system/targets/localizations.dart b/packages/flutter_tools/lib/src/build_system/targets/localizations.dart index ac6ee45507..e8258268e0 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/localizations.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/localizations.dart @@ -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(); diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart index f12032016e..d7a20eb459 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart @@ -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 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' + ': \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' + ' \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.' ); } diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart index f71cd692d1..83e356781e 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart @@ -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 { diff --git a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart index 22b58ed7a9..1672d6eca9 100644 --- a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart @@ -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'), + ); }, );