run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<int> run() async {
var raw = argResults!['data'] as String;
final file = File(raw);
if (file.existsSync()) {
raw = file.readAsStringSync();
}
final parsed = json.decode(raw);
if (parsed is! List) {
throw const FormatException('Expected JSON array for batch upsert.');
}
final list = TranslationLocalizationList();
for (final item in parsed) {
if (item is Map<String, dynamic>) {
final rawVariant = item['variant'] as String?;
final variant =
(rawVariant != null && rawVariant.isNotEmpty) ? rawVariant : null;
final loc = TranslationLocalization(
translationId: item['translationId'] as String? ??
item['translation_id'] as String? ??
'',
localeId: item['localeId'] as String? ??
item['locale_id'] as String? ??
'',
text: item['text'] as String? ?? '',
autoTranslate: item['autoTranslate'] as bool? ??
item['auto_translate'] as bool? ??
false,
);
if (variant != null) {
loc.variant = variant;
}
final itemId = item['id'] as String?;
if (itemId != null && itemId.isNotEmpty) {
loc.id = itemId;
}
list.localizations.add(loc);
}
}
final client = container.read(translationLocalizationServiceClientProvider);
final result = await client.upsertTranslationLocalizations(
list,
options: getCallOptions(requireUser: false),
);
printOutput(result);
return 0;
}