mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-23 06:38:35 +02:00
Cw 483 add tagalog and filipino localizations (#1086)
* CW-483 Add "Add new language Script" * CW-483 Add Filipino Language
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'utils/translation/arb_file_utils.dart';
|
||||
import 'utils/translation/translation_constants.dart';
|
||||
import 'utils/translation/translation_utils.dart';
|
||||
|
||||
void main(List<String> args) async {
|
||||
if (args.length != 1) {
|
||||
throw Exception(
|
||||
'Insufficient arguments!\n\nTry to run `./translation_add_lang.dart langCode`');
|
||||
}
|
||||
|
||||
final targetLang = args.first;
|
||||
|
||||
final fileName = getArbFileName(defaultLang);
|
||||
final file = File(fileName);
|
||||
final arbObj = readArbFile(file);
|
||||
|
||||
final targetFileName = getArbFileName(targetLang);
|
||||
final targetKeys = arbObj.keys;
|
||||
|
||||
final targetFile = File(targetFileName);
|
||||
targetFile.createSync(exclusive: true);
|
||||
targetFile.writeAsStringSync("{}");
|
||||
|
||||
final translations = Map<String, String>();
|
||||
for (var targetKey in targetKeys) {
|
||||
final srcString = arbObj[targetKey] as String;
|
||||
final translation = await getTranslation(srcString, targetLang);
|
||||
|
||||
translations[targetKey] = translation;
|
||||
}
|
||||
|
||||
appendStringsToArbFile(targetFileName, translations);
|
||||
print("Success! Please add your Language Code to lib/entities/language_service.dart");
|
||||
}
|
||||
@@ -17,7 +17,8 @@ void appendStringToArbFile(String fileName, String name, String text) {
|
||||
.replaceAll('","', '",\n "')
|
||||
.replaceAll('{"', '{\n "')
|
||||
.replaceAll('"}', '"\n}')
|
||||
.replaceAll('":"', '": "');
|
||||
.replaceAll('":"', '": "')
|
||||
.replaceAll('\$ {', '\${');
|
||||
|
||||
file.writeAsStringSync(outputContent);
|
||||
}
|
||||
@@ -33,7 +34,8 @@ void appendStringsToArbFile(String fileName, Map<String, String> strings) {
|
||||
.replaceAll('","', '",\n "')
|
||||
.replaceAll('{"', '{\n "')
|
||||
.replaceAll('"}', '"\n}')
|
||||
.replaceAll('":"', '": "');
|
||||
.replaceAll('":"', '": "')
|
||||
.replaceAll('\$ {', '\${');
|
||||
|
||||
file.writeAsStringSync(outputContent);
|
||||
}
|
||||
|
||||
@@ -18,20 +18,28 @@ Future<void> appendTranslations(String lang, Map<String, String> defaults) async
|
||||
|
||||
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<String> getTranslation(String text, String lang) async {
|
||||
if (lang == defaultLang) return text;
|
||||
return (await translator.translate(text, from: defaultLang, to: lang)).text;
|
||||
}
|
||||
|
||||
final regExp = RegExp(r'{(.*?)}');
|
||||
final placeholder =
|
||||
regExp.allMatches(text).map((e) => text.substring(e.start, e.end)).toList().asMap();
|
||||
|
||||
var translation = (await translator.translate(text, from: defaultLang, to: lang)).text;
|
||||
|
||||
placeholder.forEach((index, value) {
|
||||
final translatedPlaceholder = regExp.allMatches(translation).toList()[index];
|
||||
translation =
|
||||
translation.replaceRange(translatedPlaceholder.start, translatedPlaceholder.end, value);
|
||||
});
|
||||
|
||||
return translation;
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ String normalizeKeyName(String key) {
|
||||
}
|
||||
|
||||
String generateConst(String name, Map<String, dynamic> config) =>
|
||||
'const $name = \'${config["$name"]}\';\n';
|
||||
'const $name = \'${config["$name"]}\';\n';
|
||||
|
||||
Reference in New Issue
Block a user