| 1 | import 'dart:io'; |
| 2 | |
| 3 | import './print_verbose_dummy.dart'; |
| 4 | |
| 5 | import 'utils/translation/arb_file_utils.dart'; |
| 6 | import 'utils/translation/translation_constants.dart'; |
| 7 | import 'utils/translation/translation_utils.dart'; |
| 8 | |
| 9 | void main(List<String> args) async { |
| 10 | if (args.length != 1) { |
| 11 | throw Exception('Insufficient arguments!\n\nTry to run `./translation_add_lang.dart langCode`'); |
| 12 | } |
| 13 | |
| 14 | final targetLang = args.first; |
| 15 | |
| 16 | final fileName = getArbFileName(defaultLang); |
| 17 | final file = File(fileName); |
| 18 | final arbObj = readArbFile(file); |
| 19 | |
| 20 | final targetFileName = getArbFileName(targetLang); |
| 21 | final targetKeys = arbObj.keys; |
| 22 | |
| 23 | final targetFile = File(targetFileName); |
| 24 | targetFile.createSync(exclusive: true); |
| 25 | targetFile.writeAsStringSync("{}"); |
| 26 | |
| 27 | final translations = Map<String, String>(); |
| 28 | for (var targetKey in targetKeys) { |
| 29 | final srcString = arbObj[targetKey] as String; |
| 30 | final translation = await getTranslation(srcString, targetLang); |
| 31 | |
| 32 | translations[targetKey] = translation; |
| 33 | } |
| 34 | |
| 35 | appendStringsToArbFile(targetFileName, translations); |
| 36 | print("Success! Please add your Language Code to lib/entities/language_service.dart"); |
| 37 | } |