update translation script with force option

This commit is contained in:
Matthew Fosse 2024-03-07 09:36:14 -08:00
parent 32350b8ab2
commit f6dfe935d6
2 changed files with 9 additions and 8 deletions

View file

@ -3,13 +3,14 @@ import 'utils/translation/translation_constants.dart';
import 'utils/translation/translation_utils.dart';
void main(List<String> args) async {
if (args.length != 2) {
if (args.length < 2 || args.length > 3) {
throw Exception(
'Insufficient arguments!\n\nTry to run `./append_translation.dart greetings "Hello World!"`');
'Insufficient arguments!\n\nTry to run `./append_translation.dart greetings "Hello World!" [--force]`');
}
final name = args.first;
final text = args.last;
final name = args[0];
final text = args[1];
final force = args.length == 3 && args[2] == '--force';
print('Appending "$name": "$text"');
@ -18,7 +19,7 @@ void main(List<String> args) async {
final fileName = getArbFileName(lang);
final translation = await getTranslation(text, lang);
appendStringToArbFile(fileName, name, translation);
appendStringToArbFile(fileName, name, translation, force: force);
}
print('Alphabetizing all files...');

View file

@ -1,12 +1,12 @@
import 'dart:convert';
import 'dart:io';
void appendStringToArbFile(String fileName, String name, String text) {
void appendStringToArbFile(String fileName, String name, String text, {bool force = false}) {
final file = File(fileName);
final arbObj = readArbFile(file);
if (arbObj.containsKey(name)) {
print("String $name already exists in $fileName!");
if (arbObj.containsKey(name) && !force) {
print("String $name already exists in $fileName! Use --force to overwrite!");
return;
}