mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-25 05:58:42 +01:00
CW-228 Auto generate monero subaddress (#902)
* Add UI and setting logic for subaddresses * Enable auto generate subaddresses * Rename variable * Add comment to unused code * Fix issue with initial state change * Fix observable for isAppSecure * Filter sub account contacts * Fix select account use unused address * Use add address if last address is unused * Fix auto generate wallet issues * Fix button color * Add translation and refactored naming * Fix PR review * Remove unused code * Remove unused overrides in electrum * Fix address info null check * CW-228 Fix ContactListViewModel condition * CW-228 Fix Account Tile; Rework updateAddressesInBox; Fix _getAllUnusedAddresses * CW-228 Fix unintentional address_page.dart regression * CW-228 Fix Merge Conflicts * CW-228 Add more translation Tools * CW-228 More merge conflict fixes * CW-228 Fix Merge Conflicts * CW-228 Auto Translation improvements * CW-228 Resolve requested Changes --------- Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com>
This commit is contained in:
co-authored by
Konstantin Ullrich
parent
9999816850
commit
fff5a1c419
@@ -1,15 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:translator/translator.dart';
|
||||
|
||||
const defaultLang = "en";
|
||||
const langs = [
|
||||
"ar", "bg", "cs", "de", "en", "es", "fr", "ha", "hi", "hr", "id", "it",
|
||||
"ja", "ko", "my", "nl", "pl", "pt", "ru", "th", "tr", "uk", "ur", "yo",
|
||||
"zh-cn" // zh, but Google Translate uses zh-cn for Chinese (Simplified)
|
||||
];
|
||||
final translator = GoogleTranslator();
|
||||
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 != 2) {
|
||||
@@ -23,44 +14,9 @@ void main(List<String> args) async {
|
||||
print('Appending "$name": "$text"');
|
||||
|
||||
for (var lang in langs) {
|
||||
final fileName = getFileName(lang);
|
||||
final fileName = getArbFileName(lang);
|
||||
final translation = await getTranslation(text, lang);
|
||||
|
||||
appendArbFile(fileName, name, translation);
|
||||
appendStringToArbFile(fileName, name, translation);
|
||||
}
|
||||
}
|
||||
|
||||
void appendArbFile(String fileName, String name, String text) {
|
||||
final file = File(fileName);
|
||||
final inputContent = file.readAsStringSync();
|
||||
final arbObj = json.decode(inputContent) as Map<String, dynamic>;
|
||||
|
||||
if (arbObj.containsKey(name)) {
|
||||
print("String $name already exists in $fileName!");
|
||||
return;
|
||||
}
|
||||
|
||||
arbObj.addAll({name: text});
|
||||
|
||||
final outputContent = json
|
||||
.encode(arbObj)
|
||||
.replaceAll('","', '",\n "')
|
||||
.replaceAll('{"', '{\n "')
|
||||
.replaceAll('"}', '"\n}')
|
||||
.replaceAll('":"', '": "');
|
||||
|
||||
file.writeAsStringSync(outputContent);
|
||||
}
|
||||
|
||||
|
||||
Future<String> getTranslation(String text, String lang) async {
|
||||
if (lang == defaultLang) return text;
|
||||
return (await translator.translate(text, from: defaultLang, to: lang)).text;
|
||||
}
|
||||
|
||||
String getFileName(String lang) {
|
||||
final shortLang = lang
|
||||
.split("-")
|
||||
.first;
|
||||
return "./res/values/strings_$shortLang.arb";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
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 {
|
||||
print('Checking Consistency of all arb-files. Default: $defaultLang');
|
||||
|
||||
final doFix = args.contains("--fix");
|
||||
|
||||
if (doFix)
|
||||
print('Auto fixing enabled!\n');
|
||||
else
|
||||
print('Auto fixing disabled!\nRun with arg "--fix" to enable autofix\n');
|
||||
|
||||
final fileName = getArbFileName(defaultLang);
|
||||
final file = File(fileName);
|
||||
final arbObj = readArbFile(file);
|
||||
|
||||
for (var lang in langs) {
|
||||
final fileName = getArbFileName(lang);
|
||||
final missingKeys = getMissingKeysInArbFile(fileName, arbObj.keys);
|
||||
if (missingKeys.isNotEmpty) {
|
||||
final missingDefaults = <String, String>{};
|
||||
|
||||
missingKeys.forEach((key) {
|
||||
print('Missing in "$lang": "$key"');
|
||||
if (doFix)
|
||||
missingDefaults[key] = arbObj[key] as String;
|
||||
});
|
||||
|
||||
if (missingDefaults.isNotEmpty)
|
||||
await appendTranslations(lang, missingDefaults);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
void appendStringToArbFile(String fileName, String name, String text) {
|
||||
final file = File(fileName);
|
||||
final arbObj = readArbFile(file);
|
||||
|
||||
if (arbObj.containsKey(name)) {
|
||||
print("String $name already exists in $fileName!");
|
||||
return;
|
||||
}
|
||||
|
||||
arbObj.addAll({name: text});
|
||||
|
||||
final outputContent = json
|
||||
.encode(arbObj)
|
||||
.replaceAll('","', '",\n "')
|
||||
.replaceAll('{"', '{\n "')
|
||||
.replaceAll('"}', '"\n}')
|
||||
.replaceAll('":"', '": "');
|
||||
|
||||
file.writeAsStringSync(outputContent);
|
||||
}
|
||||
|
||||
void appendStringsToArbFile(String fileName, Map<String, String> strings) {
|
||||
final file = File(fileName);
|
||||
final arbObj = readArbFile(file);
|
||||
|
||||
arbObj.addAll(strings);
|
||||
|
||||
final outputContent = json
|
||||
.encode(arbObj)
|
||||
.replaceAll('","', '",\n "')
|
||||
.replaceAll('{"', '{\n "')
|
||||
.replaceAll('"}', '"\n}')
|
||||
.replaceAll('":"', '": "');
|
||||
|
||||
file.writeAsStringSync(outputContent);
|
||||
}
|
||||
|
||||
Map<String, dynamic> readArbFile(File file) {
|
||||
final inputContent = file.readAsStringSync();
|
||||
|
||||
return json.decode(inputContent) as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
String getArbFileName(String lang) {
|
||||
final shortLang = lang
|
||||
.split("-")
|
||||
.first;
|
||||
return "./res/values/strings_$shortLang.arb";
|
||||
}
|
||||
|
||||
List<String> getMissingKeysInArbFile(String fileName, Iterable<String> langKeys) {
|
||||
final file = File(fileName);
|
||||
final arbObj = readArbFile(file);
|
||||
final results = <String>[];
|
||||
|
||||
for (var langKey in langKeys) {
|
||||
if (!arbObj.containsKey(langKey)) {
|
||||
results.add(langKey);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const defaultLang = "en";
|
||||
const langs = [
|
||||
"ar", "bg", "cs", "de", "en", "es", "fr", "ha", "hi", "hr", "id", "it",
|
||||
"ja", "ko", "my", "nl", "pl", "pt", "ru", "th", "tr", "uk", "ur", "yo",
|
||||
"zh-cn" // zh, but Google Translate uses zh-cn for Chinese (Simplified)
|
||||
];
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:translator/translator.dart';
|
||||
|
||||
import 'arb_file_utils.dart';
|
||||
import 'translation_constants.dart';
|
||||
|
||||
final translator = GoogleTranslator();
|
||||
|
||||
Future<void> appendTranslation(String lang, String key, String text) async {
|
||||
final fileName = getArbFileName(lang);
|
||||
final translation = await getTranslation(text, lang);
|
||||
|
||||
appendStringToArbFile(fileName, key, translation);
|
||||
}
|
||||
|
||||
Future<void> appendTranslations(String lang, Map<String, String> defaults) async {
|
||||
final fileName = getArbFileName(lang);
|
||||
final translations = <String, String>{};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user