From f6dfe935d650991b98d68b3b4ef14a388908c371 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Thu, 7 Mar 2024 09:36:14 -0800 Subject: [PATCH] update translation script with force option --- tool/append_translation.dart | 11 ++++++----- tool/utils/translation/arb_file_utils.dart | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tool/append_translation.dart b/tool/append_translation.dart index ac114bf3c..8ba07cc40 100644 --- a/tool/append_translation.dart +++ b/tool/append_translation.dart @@ -3,13 +3,14 @@ import 'utils/translation/translation_constants.dart'; import 'utils/translation/translation_utils.dart'; void main(List 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 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...'); diff --git a/tool/utils/translation/arb_file_utils.dart b/tool/utils/translation/arb_file_utils.dart index b54dab423..284e64ddc 100644 --- a/tool/utils/translation/arb_file_utils.dart +++ b/tool/utils/translation/arb_file_utils.dart @@ -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; }