mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[gen-l10n] Fix untranslated messages (#68553)
This commit is contained in:
parent
dd8820bcc1
commit
a1a096e35a
@ -1,29 +0,0 @@
|
|||||||
// 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);
|
|
||||||
}
|
|
@ -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();
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
_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 {
|
|||||||
.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 {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|||||||
});
|
});
|
||||||
|
|
||||||
resultingFile += '}\n';
|
resultingFile += '}\n';
|
||||||
unimplementedMessageTranslationsFile.writeAsStringSync(resultingFile);
|
_untranslatedMessagesFile.writeAsStringSync(resultingFile);
|
||||||
|
if (_inputsAndOutputsListFile != null) {
|
||||||
|
_outputFileList.add(_untranslatedMessagesFile.absolute.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -48,6 +48,11 @@ const String singleEsMessageArbFileString = '''
|
|||||||
{
|
{
|
||||||
"title": "Título"
|
"title": "Título"
|
||||||
}''';
|
}''';
|
||||||
|
const String twoEsMessageArbFileString = '''
|
||||||
|
{
|
||||||
|
"title": "Título",
|
||||||
|
"subtitle": "Subtitular"
|
||||||
|
}''';
|
||||||
const String singleZhMessageArbFileString = '''
|
const String singleZhMessageArbFileString = '''
|
||||||
{
|
{
|
||||||
"title": "标题"
|
"title": "标题"
|
||||||
@ -232,7 +237,7 @@ void main() {
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
throw TestFailure('Unexpected failure during test setup: ${e.message}');
|
throw TestFailure('Unexpected failure during test setup: ${e.message}');
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
@ -428,7 +433,7 @@ void main() {
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
)
|
)
|
||||||
..loadResources()
|
..loadResources()
|
||||||
..writeOutputFiles();
|
..writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
fail('Generating output should not fail: \n${e.message}');
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
}
|
}
|
||||||
@ -465,7 +470,7 @@ void main() {
|
|||||||
fail('Using app_en_CA_foo.arb should fail as it is not a valid locale.');
|
fail('Using app_en_CA_foo.arb should fail as it is not a valid locale.');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('correctly creates an unimplemented messages file', () {
|
test('correctly creates an untranslated messages file (useSyntheticPackage = true)', () {
|
||||||
fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
|
fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
|
||||||
..createSync(recursive: true)
|
..createSync(recursive: true)
|
||||||
..childFile(defaultTemplateArbFileName).writeAsStringSync(twoMessageArbFileString)
|
..childFile(defaultTemplateArbFileName).writeAsStringSync(twoMessageArbFileString)
|
||||||
@ -481,13 +486,10 @@ void main() {
|
|||||||
templateArbFileName: defaultTemplateArbFileName,
|
templateArbFileName: defaultTemplateArbFileName,
|
||||||
outputFileString: defaultOutputFileString,
|
outputFileString: defaultOutputFileString,
|
||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
|
untranslatedMessagesFile: fs.path.join('lib', 'l10n', 'unimplemented_message_translations.json'),
|
||||||
)
|
)
|
||||||
..loadResources()
|
..loadResources()
|
||||||
..writeOutputFiles()
|
..writeOutputFiles(BufferLogger.test());
|
||||||
..outputUnimplementedMessages(
|
|
||||||
fs.path.join('lib', 'l10n', 'unimplemented_message_translations.json'),
|
|
||||||
BufferLogger.test(),
|
|
||||||
);
|
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
fail('Generating output should not fail: \n${e.message}');
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
}
|
}
|
||||||
@ -506,6 +508,139 @@ void main() {
|
|||||||
expect(unimplementedOutputString, contains('subtitle'));
|
expect(unimplementedOutputString, contains('subtitle'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('correctly creates an untranslated messages file (useSyntheticPackage = false)', () {
|
||||||
|
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,
|
||||||
|
outputPathString: defaultL10nPathString,
|
||||||
|
templateArbFileName: defaultTemplateArbFileName,
|
||||||
|
outputFileString: defaultOutputFileString,
|
||||||
|
classNameString: defaultClassNameString,
|
||||||
|
useSyntheticPackage: false,
|
||||||
|
untranslatedMessagesFile: fs.path.join('lib', 'l10n', 'unimplemented_message_translations.json'),
|
||||||
|
)
|
||||||
|
..loadResources()
|
||||||
|
..writeOutputFiles(BufferLogger.test());
|
||||||
|
} on L10nException catch (e) {
|
||||||
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
|
}
|
||||||
|
|
||||||
|
final File unimplementedOutputFile = fs.file(
|
||||||
|
fs.path.join('lib', 'l10n', 'unimplemented_message_translations.json'),
|
||||||
|
);
|
||||||
|
final String unimplementedOutputString = unimplementedOutputFile.readAsStringSync();
|
||||||
|
try {
|
||||||
|
// Since ARB file is essentially JSON, decoding it should not fail.
|
||||||
|
json.decode(unimplementedOutputString);
|
||||||
|
} on Exception {
|
||||||
|
fail('Parsing arb file should not fail');
|
||||||
|
}
|
||||||
|
expect(unimplementedOutputString, contains('es'));
|
||||||
|
expect(unimplementedOutputString, contains('subtitle'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'untranslated messages suggestion is printed when translation is missing',
|
||||||
|
() {
|
||||||
|
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,
|
||||||
|
outputPathString: defaultL10nPathString,
|
||||||
|
templateArbFileName: defaultTemplateArbFileName,
|
||||||
|
outputFileString: defaultOutputFileString,
|
||||||
|
classNameString: defaultClassNameString,
|
||||||
|
)
|
||||||
|
..loadResources()
|
||||||
|
..writeOutputFiles(testLogger);
|
||||||
|
} 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'));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'unimplemented messages suggestion is not printed when all messages '
|
||||||
|
'are fully translated',
|
||||||
|
() {
|
||||||
|
final BufferLogger testLogger = BufferLogger.test();
|
||||||
|
fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
|
||||||
|
..createSync(recursive: true)
|
||||||
|
..childFile(defaultTemplateArbFileName).writeAsStringSync(twoMessageArbFileString)
|
||||||
|
..childFile(esArbFileName).writeAsStringSync(twoMessageArbFileString);
|
||||||
|
|
||||||
|
LocalizationsGenerator generator;
|
||||||
|
try {
|
||||||
|
generator = LocalizationsGenerator(fs);
|
||||||
|
generator
|
||||||
|
..initialize(
|
||||||
|
inputPathString: defaultL10nPathString,
|
||||||
|
outputPathString: defaultL10nPathString,
|
||||||
|
templateArbFileName: defaultTemplateArbFileName,
|
||||||
|
outputFileString: defaultOutputFileString,
|
||||||
|
classNameString: defaultClassNameString,
|
||||||
|
)
|
||||||
|
..loadResources()
|
||||||
|
..writeOutputFiles(testLogger);
|
||||||
|
} on L10nException catch (e) {
|
||||||
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(testLogger.statusText, '');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('untranslated messages file included in generated JSON list of outputs', () {
|
||||||
|
_standardFlutterDirectoryL10nSetup(fs);
|
||||||
|
|
||||||
|
LocalizationsGenerator generator;
|
||||||
|
try {
|
||||||
|
generator = LocalizationsGenerator(fs);
|
||||||
|
generator
|
||||||
|
..initialize(
|
||||||
|
inputPathString: defaultL10nPathString,
|
||||||
|
templateArbFileName: defaultTemplateArbFileName,
|
||||||
|
outputFileString: defaultOutputFileString,
|
||||||
|
classNameString: defaultClassNameString,
|
||||||
|
inputsAndOutputsListPath: syntheticL10nPackagePath,
|
||||||
|
untranslatedMessagesFile: fs.path.join('lib', 'l10n', 'unimplemented_message_translations.json'),
|
||||||
|
)
|
||||||
|
..loadResources()
|
||||||
|
..writeOutputFiles(BufferLogger.test());
|
||||||
|
} on L10nException catch (e) {
|
||||||
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
|
}
|
||||||
|
|
||||||
|
final File inputsAndOutputsList = fs.file(
|
||||||
|
fs.path.join(syntheticL10nPackagePath, 'gen_l10n_inputs_and_outputs.json'),
|
||||||
|
);
|
||||||
|
expect(inputsAndOutputsList.existsSync(), isTrue);
|
||||||
|
final Map<String, dynamic> jsonResult = json.decode(
|
||||||
|
inputsAndOutputsList.readAsStringSync(),
|
||||||
|
) as Map<String, dynamic>;
|
||||||
|
expect(jsonResult.containsKey('outputs'), isTrue);
|
||||||
|
final List<dynamic> outputList = jsonResult['outputs'] as List<dynamic>;
|
||||||
|
expect(outputList, contains(contains('unimplemented_message_translations.json')));
|
||||||
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'uses inputPathString as outputPathString when the outputPathString is '
|
'uses inputPathString as outputPathString when the outputPathString is '
|
||||||
'null while not using the synthetic package option',
|
'null while not using the synthetic package option',
|
||||||
@ -524,7 +659,7 @@ void main() {
|
|||||||
useSyntheticPackage: false,
|
useSyntheticPackage: false,
|
||||||
)
|
)
|
||||||
..loadResources()
|
..loadResources()
|
||||||
..writeOutputFiles();
|
..writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
fail('Generating output should not fail: \n${e.message}');
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
}
|
}
|
||||||
@ -567,7 +702,7 @@ void main() {
|
|||||||
useSyntheticPackage: false,
|
useSyntheticPackage: false,
|
||||||
)
|
)
|
||||||
..loadResources()
|
..loadResources()
|
||||||
..writeOutputFiles();
|
..writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
fail('Generating output should not fail: \n${e.message}');
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
}
|
}
|
||||||
@ -599,7 +734,7 @@ void main() {
|
|||||||
useSyntheticPackage: false,
|
useSyntheticPackage: false,
|
||||||
)
|
)
|
||||||
..loadResources()
|
..loadResources()
|
||||||
..writeOutputFiles();
|
..writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
fail('Generating output should not fail: \n${e.message}');
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
}
|
}
|
||||||
@ -627,7 +762,7 @@ void main() {
|
|||||||
inputsAndOutputsListPath: syntheticL10nPackagePath,
|
inputsAndOutputsListPath: syntheticL10nPackagePath,
|
||||||
)
|
)
|
||||||
..loadResources()
|
..loadResources()
|
||||||
..writeOutputFiles();
|
..writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
fail('Generating output should not fail: \n${e.message}');
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
}
|
}
|
||||||
@ -1074,6 +1209,7 @@ void main() {
|
|||||||
test('message without placeholders - should generate code comment with description and template message translation', () {
|
test('message without placeholders - should generate code comment with description and template message translation', () {
|
||||||
_standardFlutterDirectoryL10nSetup(fs);
|
_standardFlutterDirectoryL10nSetup(fs);
|
||||||
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
||||||
|
final BufferLogger testLogger = BufferLogger.test();
|
||||||
try {
|
try {
|
||||||
generator.initialize(
|
generator.initialize(
|
||||||
inputPathString: defaultL10nPathString,
|
inputPathString: defaultL10nPathString,
|
||||||
@ -1083,7 +1219,7 @@ void main() {
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(testLogger);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
fail('Generating output files should not fail: $e');
|
fail('Generating output files should not fail: $e');
|
||||||
}
|
}
|
||||||
@ -1116,9 +1252,9 @@ void main() {
|
|||||||
l10nDirectory.childFile(esArbFileName)
|
l10nDirectory.childFile(esArbFileName)
|
||||||
.writeAsStringSync(singleEsMessageArbFileString);
|
.writeAsStringSync(singleEsMessageArbFileString);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
||||||
|
final BufferLogger testLogger = BufferLogger.test();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
generator.initialize(
|
generator.initialize(
|
||||||
inputPathString: defaultL10nPathString,
|
inputPathString: defaultL10nPathString,
|
||||||
@ -1128,7 +1264,7 @@ void main() {
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(testLogger);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
fail('Generating output files should not fail: $e');
|
fail('Generating output files should not fail: $e');
|
||||||
}
|
}
|
||||||
@ -1171,6 +1307,7 @@ void main() {
|
|||||||
}''');
|
}''');
|
||||||
|
|
||||||
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
||||||
|
final BufferLogger testLogger = BufferLogger.test();
|
||||||
try {
|
try {
|
||||||
generator.initialize(
|
generator.initialize(
|
||||||
inputPathString: defaultL10nPathString,
|
inputPathString: defaultL10nPathString,
|
||||||
@ -1180,7 +1317,7 @@ void main() {
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(testLogger);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
final L10nException exception = e as L10nException;
|
final L10nException exception = e as L10nException;
|
||||||
print(exception.message);
|
print(exception.message);
|
||||||
@ -1220,7 +1357,7 @@ void main() {
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
fail('Generating output files should not fail: $e');
|
fail('Generating output files should not fail: $e');
|
||||||
}
|
}
|
||||||
@ -1253,7 +1390,7 @@ void main() {
|
|||||||
preferredSupportedLocale: preferredSupportedLocale,
|
preferredSupportedLocale: preferredSupportedLocale,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
fail('Generating output files should not fail: $e');
|
fail('Generating output files should not fail: $e');
|
||||||
}
|
}
|
||||||
@ -1283,7 +1420,7 @@ import 'output-localization-file_zh.dart';
|
|||||||
useDeferredLoading: true,
|
useDeferredLoading: true,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
fail('Generating output files should not fail: $e');
|
fail('Generating output files should not fail: $e');
|
||||||
}
|
}
|
||||||
@ -1328,7 +1465,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('asdf'));
|
expect(e.message, contains('asdf'));
|
||||||
expect(e.message, contains('springStartDate'));
|
expect(e.message, contains('springStartDate'));
|
||||||
@ -1367,7 +1504,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('the "format" attribute needs to be set'));
|
expect(e.message, contains('the "format" attribute needs to be set'));
|
||||||
return;
|
return;
|
||||||
@ -1405,7 +1542,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('asdf'));
|
expect(e.message, contains('asdf'));
|
||||||
expect(e.message, contains('progress'));
|
expect(e.message, contains('progress'));
|
||||||
@ -1442,7 +1579,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('Check to see if the plural message is in the proper ICU syntax format'));
|
expect(e.message, contains('Check to see if the plural message is in the proper ICU syntax format'));
|
||||||
return;
|
return;
|
||||||
@ -1475,7 +1612,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('Check to see if the plural message is in the proper ICU syntax format'));
|
expect(e.message, contains('Check to see if the plural message is in the proper ICU syntax format'));
|
||||||
return;
|
return;
|
||||||
@ -1504,7 +1641,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('Resource attribute "@helloWorlds" was not found'));
|
expect(e.message, contains('Resource attribute "@helloWorlds" was not found'));
|
||||||
return;
|
return;
|
||||||
@ -1536,7 +1673,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('is not properly formatted'));
|
expect(e.message, contains('is not properly formatted'));
|
||||||
expect(e.message, contains('Ensure that it is a map with string valued keys'));
|
expect(e.message, contains('Ensure that it is a map with string valued keys'));
|
||||||
@ -1572,7 +1709,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('app_en.arb'));
|
expect(e.message, contains('app_en.arb'));
|
||||||
expect(e.message, contains('FormatException'));
|
expect(e.message, contains('FormatException'));
|
||||||
@ -1608,7 +1745,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
areResourceAttributesRequired: true,
|
areResourceAttributesRequired: true,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('Resource attribute "@title" was not found'));
|
expect(e.message, contains('Resource attribute "@title" was not found'));
|
||||||
return;
|
return;
|
||||||
@ -1644,7 +1781,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('Invalid ARB resource name'));
|
expect(e.message, contains('Invalid ARB resource name'));
|
||||||
return;
|
return;
|
||||||
@ -1676,7 +1813,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('Invalid ARB resource name'));
|
expect(e.message, contains('Invalid ARB resource name'));
|
||||||
return;
|
return;
|
||||||
@ -1707,7 +1844,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
);
|
);
|
||||||
generator.loadResources();
|
generator.loadResources();
|
||||||
generator.writeOutputFiles();
|
generator.writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
expect(e.message, contains('Invalid ARB resource name'));
|
expect(e.message, contains('Invalid ARB resource name'));
|
||||||
return;
|
return;
|
||||||
@ -1731,7 +1868,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
)
|
)
|
||||||
..loadResources()
|
..loadResources()
|
||||||
..writeOutputFiles();
|
..writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
fail('Generating output should not fail: \n${e.message}');
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
}
|
}
|
||||||
@ -1767,7 +1904,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
classNameString: defaultClassNameString,
|
classNameString: defaultClassNameString,
|
||||||
)
|
)
|
||||||
..loadResources()
|
..loadResources()
|
||||||
..writeOutputFiles();
|
..writeOutputFiles(BufferLogger.test());
|
||||||
} on L10nException catch (e) {
|
} on L10nException catch (e) {
|
||||||
fail('Generating output should not fail: \n${e.message}');
|
fail('Generating output should not fail: \n${e.message}');
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user