forked from firka/flutter
🔥 Do not format the messages file for gen-l10n (#119596)
* 🔥 Do not format the messages file * ✅ Add test * ✅ Add the link to the test * ✅ Respect the path separator from the file system * ✅ Add the untranslated messages file existence test
This commit is contained in:
@@ -223,7 +223,8 @@ class GenerateLocalizationsCommand extends FlutterCommand {
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
List<String> outputFileList;
|
||||
final List<String> outputFileList;
|
||||
File? untranslatedMessagesFile;
|
||||
|
||||
bool format = boolArg('format') ?? false;
|
||||
|
||||
@@ -238,19 +239,21 @@ class GenerateLocalizationsCommand extends FlutterCommand {
|
||||
'To use the command line arguments, delete the l10n.yaml file in the '
|
||||
'Flutter project.\n\n'
|
||||
);
|
||||
outputFileList = generateLocalizations(
|
||||
final LocalizationsGenerator generator = generateLocalizations(
|
||||
logger: _logger,
|
||||
options: options,
|
||||
projectDir: _fileSystem.currentDirectory,
|
||||
fileSystem: _fileSystem,
|
||||
).outputFileList;
|
||||
);
|
||||
outputFileList = generator.outputFileList;
|
||||
untranslatedMessagesFile = generator.untranslatedMessagesFile;
|
||||
format = format || options.format;
|
||||
} else {
|
||||
final String inputPathString = stringArgDeprecated('arb-dir')!; // Has default value, cannot be null.
|
||||
final String? outputPathString = stringArgDeprecated('output-dir');
|
||||
final String outputFileString = stringArgDeprecated('output-localization-file')!; // Has default value, cannot be null.
|
||||
final String templateArbFileName = stringArgDeprecated('template-arb-file')!; // Has default value, cannot be null.
|
||||
final String? untranslatedMessagesFile = stringArgDeprecated('untranslated-messages-file');
|
||||
final String? untranslatedMessagesFilePath = stringArgDeprecated('untranslated-messages-file');
|
||||
final String classNameString = stringArgDeprecated('output-class')!; // Has default value, cannot be null.
|
||||
final List<String> preferredSupportedLocales = stringsArg('preferred-supported-locales');
|
||||
final String? headerString = stringArgDeprecated('header');
|
||||
@@ -267,7 +270,7 @@ class GenerateLocalizationsCommand extends FlutterCommand {
|
||||
precacheLanguageAndRegionTags();
|
||||
|
||||
try {
|
||||
outputFileList = (LocalizationsGenerator(
|
||||
final LocalizationsGenerator generator = LocalizationsGenerator(
|
||||
fileSystem: _fileSystem,
|
||||
inputPathString: inputPathString,
|
||||
outputPathString: outputPathString,
|
||||
@@ -282,15 +285,16 @@ class GenerateLocalizationsCommand extends FlutterCommand {
|
||||
useSyntheticPackage: useSyntheticPackage,
|
||||
projectPathString: projectPathString,
|
||||
areResourceAttributesRequired: areResourceAttributesRequired,
|
||||
untranslatedMessagesFile: untranslatedMessagesFile,
|
||||
untranslatedMessagesFile: untranslatedMessagesFilePath,
|
||||
usesNullableGetter: usesNullableGetter,
|
||||
useEscaping: useEscaping,
|
||||
logger: _logger,
|
||||
suppressWarnings: suppressWarnings,
|
||||
)
|
||||
..loadResources()
|
||||
..writeOutputFiles())
|
||||
.outputFileList;
|
||||
..writeOutputFiles();
|
||||
outputFileList = generator.outputFileList;
|
||||
untranslatedMessagesFile = generator.untranslatedMessagesFile;
|
||||
} on L10nException catch (e) {
|
||||
throwToolExit(e.message);
|
||||
}
|
||||
@@ -301,8 +305,16 @@ class GenerateLocalizationsCommand extends FlutterCommand {
|
||||
if (outputFileList.isEmpty) {
|
||||
return FlutterCommandResult.success();
|
||||
}
|
||||
final List<String> formatFileList = outputFileList.toList();
|
||||
if (untranslatedMessagesFile != null) {
|
||||
// Don't format the messages file using `dart format`.
|
||||
formatFileList.remove(untranslatedMessagesFile.absolute.path);
|
||||
}
|
||||
if (formatFileList.isEmpty) {
|
||||
return FlutterCommandResult.success();
|
||||
}
|
||||
final String dartBinary = _artifacts.getArtifactPath(Artifact.engineDartBinary);
|
||||
final List<String> command = <String>[dartBinary, 'format', ...outputFileList];
|
||||
final List<String> command = <String>[dartBinary, 'format', ...formatFileList];
|
||||
final ProcessResult result = await _processManager.run(command);
|
||||
if (result.exitCode != 0) {
|
||||
throwToolExit('Formatting failed: $result', exitCode: result.exitCode);
|
||||
|
||||
@@ -627,7 +627,6 @@ class LocalizationsGenerator {
|
||||
|
||||
/// A generated file that will contain the list of messages for each locale
|
||||
/// that do not have a translation yet.
|
||||
@visibleForTesting
|
||||
final File? untranslatedMessagesFile;
|
||||
|
||||
/// The file that contains the list of inputs and outputs for generating
|
||||
@@ -824,7 +823,7 @@ class LocalizationsGenerator {
|
||||
if (untranslatedMessagesFileString == null || untranslatedMessagesFileString.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
untranslatedMessagesFileString = untranslatedMessagesFileString.replaceAll(r'\', fileSystem.path.separator);
|
||||
return fileSystem.file(untranslatedMessagesFileString);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user