doRun method
Implementation
@override
Future<int> doRun() async {
final args = argResults!;
final runDirPath = path.current;
final config = findConfigAndSetWorkingDir();
final l10nConfig = config.l10n;
final target = args[_argTo] as String;
final locale = args[_argLocale] as String?;
final name = (args[_argName] as String?)?.trim();
final locales = locale != null && locale.isNotEmpty
? [locale]
: await getLocales(l10nConfig);
if (locales.isEmpty) {
return success(
message: 'No locales found. Check ${l10nConfig.xmlOutputDir} folder');
}
printVerbose('Import for locales: ${locales.join(', ')}.');
if (name != null) printVerbose('Import file <$name>');
final dirs = {path.current, runDirPath};
try {
final int res;
switch (target) {
case _targetArb:
res = await _importToArb(l10nConfig, locales);
break;
case _targetAndroid:
res = await _importToAndroid(l10nConfig, locales, dirs);
break;
case _targetIos:
res = await _importToIos(l10nConfig, locales, dirs);
break;
case _targetJson:
res = await _importToJson(l10nConfig, locales, name);
break;
case _targetGoogleDocs:
// TODO: parameter for filename
res = await _importToGoogleDocs(l10nConfig, 'screenshot1', locales);
break;
default:
res = error(1, message: 'Unknown target: $target');
}
return res;
} on RunException catch (e) {
return errorBy(e, title: 'Import failed.');
}
}