import 'package:translator/translator.dart'; import 'arb_file_utils.dart'; import 'translation_constants.dart'; final translator = GoogleTranslator(); Future appendTranslation(String lang, String key, String text) async { final fileName = getArbFileName(lang); final translation = await getTranslation(text, lang); appendStringToArbFile(fileName, key, translation); } Future appendTranslations(String lang, Map defaults) async { final fileName = getArbFileName(lang); final translations = {}; for (var key in defaults.keys) { final value = defaults[key]!; if (value.contains("{")) continue; final translation = await getTranslation(value, lang); translations[key] = translation; } print(translations); appendStringsToArbFile(fileName, translations); } Future getTranslation(String text, String lang) async { if (lang == defaultLang) return text; return (await translator.translate(text, from: defaultLang, to: lang)).text; }