generateRootTranslations function
Future<void>
generateRootTranslations(
{ - required String rootPath,
- required String outputFolder,
- required String templateArbFile,
- required bool nullableGetter,
})
Implementation
Future<void> generateRootTranslations({
required String rootPath,
required String outputFolder,
required String templateArbFile,
required bool nullableGetter,
}) async {
var errors = <String>[];
final outputPath = path.normalize('$rootPath/$outputFolder');
final rootPathDir = path.normalize('$rootPath/l10n');
try {
if (await Directory(rootPathDir).exists()) {
print('π Generating translations for root folder');
await checkLocalizationKeys(rootPathDir, templateArbFile);
String flutterPath = await findFlutterExecutable();
ProcessResult result = await Process.run(flutterPath, [
'gen-l10n',
'--arb-dir',
rootPathDir,
'--output-dir',
outputPath,
'--no-synthetic-package',
'--output-class',
'RootLocalizations',
'--template-arb-file',
templateArbFile,
'--output-localization-file',
'root_localizations.dart',
if (!nullableGetter) '--no-nullable-getter'
]);
if (result.stdout.toString().isEmpty &&
result.stderr.toString().isEmpty) {
print('β
Generated translations for root folder');
return;
}
if (result.stdout.toString().isNotEmpty) print(result.stdout);
if (result.stderr.toString().isNotEmpty) print(result.stderr);
throw Exception(
'β Failed to generate translations for root folder: ${result.stderr.toString()} ${result.stdout}');
} else {
print(
'βΆβΆ Skipped translations for root folder because no translations where found in the specified path');
}
} on KeyNotFoundException catch (e) {
errors.add(e.toString());
print(
'β Failed to generate translations because some keys were missing in the files');
} catch (e) {
errors.add(e.toString());
print(e);
print('β Failed to generate translations for root folder');
}
if (errors.isNotEmpty) {
throw Exception(errors.join('\n'));
}
}