run method

  1. @override
Future<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() async {
  final text = argResults!['text'] as String;
  final srcLocale = argResults!['source-locale'] as String;
  final targetLocale = argResults!['target-locale'] as String;
  final pId = resolvedProjectId ?? '';
  final tLocId = argResults?['translation-loc-id'] as String? ?? '';
  final vLocId = argResults?['variable-loc-id'] as String? ?? '';
  final fieldName = argResults?['field-name'] as String? ?? '';

  final req = TextTranslate(
    sourceLocaleId: srcLocale,
    targetLocaleId: targetLocale,
    text: text,
  );
  if (pId.isNotEmpty) req.projectId = pId;
  if (tLocId.isNotEmpty) req.translationLocalizationId = tLocId;
  if (vLocId.isNotEmpty) req.variableLocalizationId = vLocId;
  if (fieldName.isNotEmpty) req.fieldName = fieldName;

  final client = container.read(translateServiceClientProvider);
  final result = await client.translate(
    req,
    options: getCallOptions(requireUser: false),
  );
  printOutput(result);
  return 0;
}