mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
Merge pull request #1 from kotval/out_of_tree_issue
Localization Issues
This commit is contained in:
commit
fe5a93744f
4 changed files with 351 additions and 155 deletions
|
|
@ -3,8 +3,11 @@
|
||||||
"context_name": "App Loader",
|
"context_name": "App Loader",
|
||||||
"menu_name": {
|
"menu_name": {
|
||||||
"appmenu.app-loader": {
|
"appmenu.app-loader": {
|
||||||
"en": "App Loader",
|
"en": "App Loader",
|
||||||
"en-tts": "App Loader"
|
"en-tts": "App Loader",
|
||||||
|
"fr": "App Loader *EN*",
|
||||||
|
"ja": "App Loader *EN*",
|
||||||
|
"zh": "App Loader *EN*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"submenu": 2
|
"submenu": 2
|
||||||
|
|
@ -21,6 +24,19 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"chat-test": {
|
||||||
|
"context_name": "Chat UI test",
|
||||||
|
"menu_name": {
|
||||||
|
"appmenu.chat-test": {
|
||||||
|
"en": "Chat UI test",
|
||||||
|
"en-tts": "Chat UI test *EN*",
|
||||||
|
"fr": "Chat UI test *EN*",
|
||||||
|
"ja": "Chat UI test *EN*",
|
||||||
|
"zh": "Chat UI test *EN*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"submenu": 1
|
||||||
|
},
|
||||||
"hello": {
|
"hello": {
|
||||||
"context_name": "Hello World",
|
"context_name": "Hello World",
|
||||||
"menu_name": {
|
"menu_name": {
|
||||||
|
|
@ -33,6 +49,19 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"mtxchat": {
|
||||||
|
"context_name": "[matrix]",
|
||||||
|
"menu_name": {
|
||||||
|
"appmenu.mtxchat": {
|
||||||
|
"en": "[matrix]",
|
||||||
|
"en-tts": "[matrix] *EN*",
|
||||||
|
"fr": "[matrix] *EN*",
|
||||||
|
"ja": "[matrix] *EN*",
|
||||||
|
"zh": "[matrix] *EN*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"submenu": 1
|
||||||
|
},
|
||||||
"mtxcli": {
|
"mtxcli": {
|
||||||
"context_name": "Matrix cli",
|
"context_name": "Matrix cli",
|
||||||
"menu_name": {
|
"menu_name": {
|
||||||
|
|
@ -45,24 +74,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mtxchat": {
|
|
||||||
"context_name": "[matrix]",
|
|
||||||
"menu_name": {
|
|
||||||
"appmenu.mtxchat": {
|
|
||||||
"en": "[matrix]"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"submenu": 1
|
|
||||||
},
|
|
||||||
"chat-test": {
|
|
||||||
"context_name": "Chat UI test",
|
|
||||||
"menu_name": {
|
|
||||||
"appmenu.chat-test": {
|
|
||||||
"en": "Chat UI test"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"submenu": 1
|
|
||||||
},
|
|
||||||
"repl": {
|
"repl": {
|
||||||
"context_name": "repl demo app",
|
"context_name": "repl demo app",
|
||||||
"menu_name": {
|
"menu_name": {
|
||||||
|
|
@ -79,11 +90,27 @@
|
||||||
"context_name": "signal",
|
"context_name": "signal",
|
||||||
"menu_name": {
|
"menu_name": {
|
||||||
"appmenu.sigchat": {
|
"appmenu.sigchat": {
|
||||||
"en": "Signal"
|
"en": "Signal",
|
||||||
|
"en-tts": "Signal *EN*",
|
||||||
|
"fr": "Signal *EN*",
|
||||||
|
"ja": "Signal *EN*",
|
||||||
|
"zh": "Signal *EN*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"submenu": 1
|
"submenu": 1
|
||||||
},
|
},
|
||||||
|
"transientdisk": {
|
||||||
|
"context_name": "Transient USB disk",
|
||||||
|
"menu_name": {
|
||||||
|
"appmenu.transientdisk": {
|
||||||
|
"en": "Transient USB disk",
|
||||||
|
"en-tts": "Transient USB disk *EN*",
|
||||||
|
"fr": "Transient USB disk *EN*",
|
||||||
|
"ja": "Transient USB disk *EN*",
|
||||||
|
"zh": "Transient USB disk *EN*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"vault": {
|
"vault": {
|
||||||
"context_name": "Key Vault",
|
"context_name": "Key Vault",
|
||||||
"menu_name": {
|
"menu_name": {
|
||||||
|
|
@ -96,13 +123,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"submenu": 1
|
"submenu": 1
|
||||||
},
|
|
||||||
"transientdisk": {
|
|
||||||
"context_name": "Transient USB disk",
|
|
||||||
"menu_name": {
|
|
||||||
"appmenu.transientdisk": {
|
|
||||||
"en": "Transient USB disk"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,74 +1,128 @@
|
||||||
{
|
{
|
||||||
"tls.check_trust_prompt": {
|
"tls.check_trust_prompt": {
|
||||||
"en": "Please select trusted certificate authorities.",
|
"en": "Please select trusted certificate authorities.",
|
||||||
"en-tts": "Please select trusted certificate authorities."
|
"en-tts": "Please select trusted certificate authorities.",
|
||||||
|
"fr": "Please select trusted certificate authorities. *EN*",
|
||||||
|
"ja": "Please select trusted certificate authorities. *EN*",
|
||||||
|
"zh": "Please select trusted certificate authorities. *EN*"
|
||||||
|
},
|
||||||
|
"tls.cmd": {
|
||||||
|
"en": "net tls <sub-command>",
|
||||||
|
"en-tts": "net tls <sub-command>",
|
||||||
|
"fr": "net tls <sub-command> *EN*",
|
||||||
|
"ja": "net tls <sub-command> *EN*",
|
||||||
|
"zh": "net tls <sub-command> *EN*"
|
||||||
},
|
},
|
||||||
"tls.cmd_help": {
|
"tls.cmd_help": {
|
||||||
"en": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser.",
|
"en": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser.",
|
||||||
"en-tts": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser."
|
"en-tts": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser.",
|
||||||
},
|
"fr": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser. *EN*",
|
||||||
"tls.cmd": {
|
"ja": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser. *EN*",
|
||||||
"en": "net tls <sub-command>",
|
"zh": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser. *EN*"
|
||||||
"en-tts": "net tls <sub-command>"
|
|
||||||
},
|
},
|
||||||
"tls.deleteall_cmd": {
|
"tls.deleteall_cmd": {
|
||||||
"en": "delete ALL trusted Certificates",
|
"en": "delete ALL trusted Certificates",
|
||||||
"en-tts": "delete ALL trusted Certificates"
|
"en-tts": "delete ALL trusted Certificates",
|
||||||
|
"fr": "delete ALL trusted Certificates *EN*",
|
||||||
|
"ja": "delete ALL trusted Certificates *EN*",
|
||||||
|
"zh": "delete ALL trusted Certificates *EN*"
|
||||||
},
|
},
|
||||||
"tls.deleteall_done": {
|
"tls.deleteall_done": {
|
||||||
"en": "deleted Certificates",
|
"en": "deleted Certificates",
|
||||||
"en-tts": "deleted Certificates"
|
"en-tts": "deleted Certificates",
|
||||||
},
|
"fr": "deleted Certificates *EN*",
|
||||||
"tls.list_cmd": {
|
"ja": "deleted Certificates *EN*",
|
||||||
"en": "list trusted CA certificates",
|
"zh": "deleted Certificates *EN*"
|
||||||
"en-tts": "list trusted CA certificates"
|
|
||||||
},
|
|
||||||
"tls.mozilla_cmd": {
|
|
||||||
"en": "trust all Root CA's in webpki-roots",
|
|
||||||
"en-tts": "trust all Root CA's in webpki-roots"
|
|
||||||
},
|
|
||||||
"tls.mozilla_progress": {
|
|
||||||
"en": "trusting Mozilla Root CA's",
|
|
||||||
"en-tts": "trusting Mozilla Root CA's"
|
|
||||||
},
|
|
||||||
"tls.mozilla_done": {
|
|
||||||
"en": "trusted Root CA's",
|
|
||||||
"en-tts": "trusted Root CA's"
|
|
||||||
},
|
},
|
||||||
"tls.inspect_cmd": {
|
"tls.inspect_cmd": {
|
||||||
"en": "save host CA'a if trusted",
|
"en": "save host CA'a if trusted",
|
||||||
"en-tts": "save host CA'a if trusted"
|
"en-tts": "save host CA'a if trusted",
|
||||||
},
|
"fr": "save host CA'a if trusted *EN*",
|
||||||
"tls.inspect_fail_servername": {
|
"ja": "save host CA'a if trusted *EN*",
|
||||||
"en": "failed to create server name from",
|
"zh": "save host CA'a if trusted *EN*"
|
||||||
"en-tts": "failed to create server name from"
|
|
||||||
},
|
|
||||||
"tls.probe_invalid_certificate": {
|
|
||||||
"en": "Invalid certificate : ",
|
|
||||||
"en-tts": "Invalid certificate : "
|
|
||||||
},
|
|
||||||
"tls.probe_help_not_valid_yet": {
|
|
||||||
"en": "error maybe caused by an improperly set clock",
|
|
||||||
"en-tts": "error maybe caused by an improperly set clock"
|
|
||||||
},
|
},
|
||||||
"tls.inspect_done": {
|
"tls.inspect_done": {
|
||||||
"en": "trusted CA's",
|
"en": "trusted CA's",
|
||||||
"en-tts": "trusted CA's"
|
"en-tts": "trusted CA's",
|
||||||
|
"fr": "trusted CA's *EN*",
|
||||||
|
"ja": "trusted CA's *EN*",
|
||||||
|
"zh": "trusted CA's *EN*"
|
||||||
|
},
|
||||||
|
"tls.inspect_fail_servername": {
|
||||||
|
"en": "failed to create server name from",
|
||||||
|
"en-tts": "failed to create server name from",
|
||||||
|
"fr": "failed to create server name from *EN*",
|
||||||
|
"ja": "failed to create server name from *EN*",
|
||||||
|
"zh": "failed to create server name from *EN*"
|
||||||
|
},
|
||||||
|
"tls.list_cmd": {
|
||||||
|
"en": "list trusted CA certificates",
|
||||||
|
"en-tts": "list trusted CA certificates",
|
||||||
|
"fr": "list trusted CA certificates *EN*",
|
||||||
|
"ja": "list trusted CA certificates *EN*",
|
||||||
|
"zh": "list trusted CA certificates *EN*"
|
||||||
|
},
|
||||||
|
"tls.mozilla_cmd": {
|
||||||
|
"en": "trust all Root CA's in webpki-roots",
|
||||||
|
"en-tts": "trust all Root CA's in webpki-roots",
|
||||||
|
"fr": "trust all Root CA's in webpki-roots *EN*",
|
||||||
|
"ja": "trust all Root CA's in webpki-roots *EN*",
|
||||||
|
"zh": "trust all Root CA's in webpki-roots *EN*"
|
||||||
|
},
|
||||||
|
"tls.mozilla_done": {
|
||||||
|
"en": "trusted Root CA's",
|
||||||
|
"en-tts": "trusted Root CA's",
|
||||||
|
"fr": "trusted Root CA's *EN*",
|
||||||
|
"ja": "trusted Root CA's *EN*",
|
||||||
|
"zh": "trusted Root CA's *EN*"
|
||||||
|
},
|
||||||
|
"tls.mozilla_progress": {
|
||||||
|
"en": "trusting Mozilla Root CA's",
|
||||||
|
"en-tts": "trusting Mozilla Root CA's",
|
||||||
|
"fr": "trusting Mozilla Root CA's *EN*",
|
||||||
|
"ja": "trusting Mozilla Root CA's *EN*",
|
||||||
|
"zh": "trusting Mozilla Root CA's *EN*"
|
||||||
|
},
|
||||||
|
"tls.probe_help_not_valid_yet": {
|
||||||
|
"en": "error maybe caused by an improperly set clock",
|
||||||
|
"en-tts": "error maybe caused by an improperly set clock",
|
||||||
|
"fr": "error maybe caused by an improperly set clock *EN*",
|
||||||
|
"ja": "error maybe caused by an improperly set clock *EN*",
|
||||||
|
"zh": "error maybe caused by an improperly set clock *EN*"
|
||||||
|
},
|
||||||
|
"tls.probe_invalid_certificate": {
|
||||||
|
"en": "Invalid certificate : ",
|
||||||
|
"en-tts": "Invalid certificate : ",
|
||||||
|
"fr": "Invalid certificate : *EN*",
|
||||||
|
"ja": "Invalid certificate : *EN*",
|
||||||
|
"zh": "Invalid certificate : *EN*"
|
||||||
},
|
},
|
||||||
"tls.test_cmd": {
|
"tls.test_cmd": {
|
||||||
"en": "make tls connection to host",
|
"en": "make tls connection to host",
|
||||||
"en-tts": "make tls connection to host"
|
"en-tts": "make tls connection to host",
|
||||||
},
|
"fr": "make tls connection to host *EN*",
|
||||||
"tls.test_success_tcp": {
|
"ja": "make tls connection to host *EN*",
|
||||||
"en": "tcp connected\n",
|
"zh": "make tls connection to host *EN*"
|
||||||
"en-tts": "tcp connected"
|
|
||||||
},
|
|
||||||
"tls.test_success_get": {
|
|
||||||
"en": "tls accepted GET\n",
|
|
||||||
"en-tts": "tls accepted GET"
|
|
||||||
},
|
},
|
||||||
"tls.test_success_bytes": {
|
"tls.test_success_bytes": {
|
||||||
"en": "tls received bytes",
|
"en": "tls received bytes",
|
||||||
"en-tts": "tls received bytes"
|
"en-tts": "tls received bytes",
|
||||||
|
"fr": "tls received bytes *EN*",
|
||||||
|
"ja": "tls received bytes *EN*",
|
||||||
|
"zh": "tls received bytes *EN*"
|
||||||
|
},
|
||||||
|
"tls.test_success_get": {
|
||||||
|
"en": "tls accepted GET\n",
|
||||||
|
"en-tts": "tls accepted GET",
|
||||||
|
"fr": "tls accepted GET\n *EN*",
|
||||||
|
"ja": "tls accepted GET\n *EN*",
|
||||||
|
"zh": "tls accepted GET\n *EN*"
|
||||||
|
},
|
||||||
|
"tls.test_success_tcp": {
|
||||||
|
"en": "tcp connected\n",
|
||||||
|
"en-tts": "tcp connected",
|
||||||
|
"fr": "tcp connected\n *EN*",
|
||||||
|
"ja": "tcp connected\n *EN*",
|
||||||
|
"zh": "tcp connected\n *EN*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,16 +18,30 @@ type Locale = String;
|
||||||
type Value = String;
|
type Value = String;
|
||||||
type Translations = HashMap<Key, HashMap<Locale, Value>>;
|
type Translations = HashMap<Key, HashMap<Locale, Value>>;
|
||||||
|
|
||||||
|
macro_rules! build_debug {
|
||||||
|
($($tokens: tt)*) => {
|
||||||
|
println!("cargo:warning={}", format!($($tokens)*))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn read_locales() -> Translations {
|
fn read_locales() -> Translations {
|
||||||
let mut translations: Translations = HashMap::new();
|
let mut translations: Translations = HashMap::new();
|
||||||
|
|
||||||
let project_dir = project_root();
|
let mut project_dir = project_root();
|
||||||
let build_directory = project_dir.to_str().unwrap();
|
let build_directory = project_dir.to_str().unwrap();
|
||||||
let locales = format!("{}/**/i18n.json", build_directory);
|
let locales = format!("{}/**/i18n.json", build_directory);
|
||||||
println!("Reading {}", &locales);
|
build_debug!("Reading {}", &locales);
|
||||||
|
// TODO: once this works, get from external directory/location arguments from xtask script
|
||||||
for entry in glob(&locales).expect("Failed to read glob pattern") {
|
project_dir.pop(); //sibling directory
|
||||||
|
project_dir.push("sigchat");
|
||||||
|
let external_directory = project_dir.to_str().unwrap();
|
||||||
|
let external_locales = format!("{}/**/i18n.json", external_directory);
|
||||||
|
build_debug!("Reading external {}", &external_locales);
|
||||||
|
let paths = glob(&locales).expect("Failed to read glob pattern for in tree fiels");
|
||||||
|
let external_paths = glob(&external_locales).expect("Filed to read glob pattern for external files");
|
||||||
|
for entry in paths.chain(external_paths) {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
|
build_debug!("{:?}",entry);
|
||||||
println!("cargo:rerun-if-changed={}", entry.display());
|
println!("cargo:rerun-if-changed={}", entry.display());
|
||||||
let file = File::open(entry).expect("Failed to open the file");
|
let file = File::open(entry).expect("Failed to open the file");
|
||||||
let mut reader = std::io::BufReader::new(file);
|
let mut reader = std::io::BufReader::new(file);
|
||||||
|
|
|
||||||
|
|
@ -8,42 +8,72 @@ import os.path
|
||||||
import pwd
|
import pwd
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class Main(object):
|
|
||||||
|
|
||||||
|
class Main(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
parser = argparse.ArgumentParser(description="Xous i18n Helper")
|
parser = argparse.ArgumentParser(description="Xous i18n Helper")
|
||||||
parser.add_argument('-v', '--verbose',
|
parser.add_argument(
|
||||||
help='Prints details of each action',
|
"-v",
|
||||||
action='store_true', required=False)
|
"--verbose",
|
||||||
parser.add_argument('-l', '--list-languages',
|
help="Prints details of each action",
|
||||||
help='Lists current translations',
|
action="store_true",
|
||||||
action='store_true', required=False)
|
required=False,
|
||||||
parser.add_argument('-i', '--list-i18n-files',
|
)
|
||||||
help='Lists i18n files',
|
parser.add_argument(
|
||||||
action='store_true', required=False)
|
"-l",
|
||||||
parser.add_argument('-m', '--missing',
|
"--list-languages",
|
||||||
help='Shows missing translations',
|
help="Lists current translations",
|
||||||
action='store_true', required=False)
|
action="store_true",
|
||||||
parser.add_argument('-o', '--show-ok',
|
required=False,
|
||||||
help='Shows OK translations',
|
)
|
||||||
action='store_true', required=False)
|
parser.add_argument(
|
||||||
parser.add_argument('-n', '--new-lang',
|
"-i",
|
||||||
help='Add support for a new lang',
|
"--list-i18n-files",
|
||||||
required=False)
|
help="Lists i18n files",
|
||||||
parser.add_argument('-f', '--from-lang',
|
action="store_true",
|
||||||
help='Copy this existing lang for the new lang',
|
required=False,
|
||||||
required=False)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-m",
|
||||||
|
"--missing",
|
||||||
|
help="Shows missing translations",
|
||||||
|
action="store_true",
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--show-ok",
|
||||||
|
help="Shows OK translations",
|
||||||
|
action="store_true",
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-n", "--new-lang", help="Add support for a new lang", required=False
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-f",
|
||||||
|
"--from-lang",
|
||||||
|
help="Copy this existing lang for the new lang",
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-s",
|
||||||
|
"--stub",
|
||||||
|
help="fills in all missing translation with stub from EN",
|
||||||
|
action="store_true",
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
self.args = parser.parse_args()
|
self.args = parser.parse_args()
|
||||||
self.args.program = sys.argv[0]
|
self.args.program = sys.argv[0]
|
||||||
if self.args.program[0] != '/':
|
if self.args.program[0] != "/":
|
||||||
self.args.program = os.path.join(os.getcwd(), self.args.program)
|
self.args.program = os.path.join(os.getcwd(), self.args.program)
|
||||||
self.args.pdir = os.path.normpath(os.path.dirname(self.args.program))
|
self.args.pdir = os.path.normpath(os.path.dirname(self.args.program))
|
||||||
self.args.xousdir = os.path.normpath(os.path.dirname(self.args.pdir))
|
self.args.xousdir = os.path.normpath(os.path.dirname(self.args.pdir))
|
||||||
self.args.program = os.path.basename(self.args.program)
|
self.args.program = os.path.basename(self.args.program)
|
||||||
self.errfile = sys.stderr
|
self.errfile = sys.stderr
|
||||||
# if end of string matches ' *EN*' (or some other lang)
|
# if end of string matches ' *EN*' (or some other lang)
|
||||||
self.temp_regex = re.compile('^.* \*[a-zA-Z]{2}\*$')
|
self.temp_regex = re.compile("^.* \*[a-zA-Z]{2}\*$")
|
||||||
self.mt_regex = re.compile('^.* \*MT\*$')
|
self.mt_regex = re.compile("^.* \*MT\*$")
|
||||||
|
|
||||||
def out(self, *objects):
|
def out(self, *objects):
|
||||||
print(*objects)
|
print(*objects)
|
||||||
|
|
@ -56,15 +86,19 @@ class Main(object):
|
||||||
self.err(*objects)
|
self.err(*objects)
|
||||||
|
|
||||||
def get_languages(self):
|
def get_languages(self):
|
||||||
self.verr('-- get languages --')
|
self.verr("-- get languages --")
|
||||||
# services/root-keys/locales/i18n.json
|
# services/root-keys/locales/i18n.json
|
||||||
root_keys = os.path.join(self.args.xousdir, 'services', 'root-keys', 'locales', 'i18n.json')
|
root_keys = os.path.join(
|
||||||
|
self.args.xousdir, "services", "root-keys", "locales", "i18n.json"
|
||||||
|
)
|
||||||
if not os.path.exists(root_keys):
|
if not os.path.exists(root_keys):
|
||||||
self.err('cannot find: %s' % root_keys);
|
self.err("cannot find: %s" % root_keys)
|
||||||
return 1
|
return 1
|
||||||
# read keys in "rootkeys.backup_key":
|
# read keys in "rootkeys.backup_key":
|
||||||
essential = 'rootkeys.backup_key'
|
essential = "rootkeys.backup_key"
|
||||||
f = open(root_keys,)
|
f = open(
|
||||||
|
root_keys,
|
||||||
|
)
|
||||||
obj = json.load(f)
|
obj = json.load(f)
|
||||||
self.languages = []
|
self.languages = []
|
||||||
if essential in obj:
|
if essential in obj:
|
||||||
|
|
@ -76,34 +110,37 @@ class Main(object):
|
||||||
def list_languages(self):
|
def list_languages(self):
|
||||||
if self.get_languages() != 0:
|
if self.get_languages() != 0:
|
||||||
return 1
|
return 1
|
||||||
self.verr('-- list languages --')
|
self.verr("-- list languages --")
|
||||||
for lang in self.languages:
|
for lang in self.languages:
|
||||||
self.out(lang)
|
self.out(lang)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_i18n_files(self):
|
def get_i18n_files(self):
|
||||||
self.verr('-- get i18n files --')
|
self.verr("-- get i18n files --")
|
||||||
self.i18n_files = []
|
self.i18n_files = []
|
||||||
topdirs = ['apps', 'services']
|
topdirs = ["apps", "services", "libs"]
|
||||||
|
# TODO: use glob to replicate exactly how rust looks for them.
|
||||||
for top in topdirs:
|
for top in topdirs:
|
||||||
topdir = os.path.join(self.args.xousdir, top)
|
topdir = os.path.join(self.args.xousdir, top)
|
||||||
if os.path.exists(topdir):
|
if os.path.exists(topdir):
|
||||||
if top == 'apps':
|
if top == "apps":
|
||||||
manifest = os.path.join(topdir, 'manifest.json')
|
manifest = os.path.join(topdir, "manifest.json")
|
||||||
if os.path.exists(manifest):
|
if os.path.exists(manifest):
|
||||||
self.i18n_files.append(manifest[len(self.args.xousdir)+1:])
|
self.i18n_files.append(manifest[len(self.args.xousdir) + 1 :])
|
||||||
for thing in os.listdir(topdir):
|
for thing in os.listdir(topdir):
|
||||||
thingdir = os.path.join(topdir, thing)
|
thingdir = os.path.join(topdir, thing)
|
||||||
if os.path.isdir(thingdir):
|
if os.path.isdir(thingdir):
|
||||||
i18n_path = os.path.join(thingdir, 'locales', 'i18n.json')
|
i18n_path = os.path.join(thingdir, "locales", "i18n.json")
|
||||||
if os.path.exists(i18n_path):
|
if os.path.exists(i18n_path):
|
||||||
self.i18n_files.append(i18n_path[len(self.args.xousdir)+1:])
|
self.i18n_files.append(
|
||||||
|
i18n_path[len(self.args.xousdir) + 1 :]
|
||||||
|
)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def list_i18n_files(self):
|
def list_i18n_files(self):
|
||||||
if self.get_i18n_files() != 0:
|
if self.get_i18n_files() != 0:
|
||||||
return 1
|
return 1
|
||||||
self.verr('-- list i18n files --')
|
self.verr("-- list i18n files --")
|
||||||
for pathname in self.i18n_files:
|
for pathname in self.i18n_files:
|
||||||
self.out(pathname)
|
self.out(pathname)
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -113,36 +150,86 @@ class Main(object):
|
||||||
# other TAG
|
# other TAG
|
||||||
def show_missing(self, i18n, is_manifest):
|
def show_missing(self, i18n, is_manifest):
|
||||||
i18n_path = os.path.join(self.args.xousdir, i18n)
|
i18n_path = os.path.join(self.args.xousdir, i18n)
|
||||||
f = open(i18n_path,)
|
f = open(
|
||||||
|
i18n_path,
|
||||||
|
)
|
||||||
obj = json.load(f)
|
obj = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
jqpath = None
|
jqpath = None
|
||||||
translation = None
|
translation = None
|
||||||
for tag in obj.keys():
|
for tag in obj.keys():
|
||||||
if is_manifest:
|
if is_manifest:
|
||||||
appmenu = 'appmenu.' + tag
|
appmenu = "appmenu." + tag
|
||||||
jqpath = tag + '.menu_name.' + appmenu
|
jqpath = tag + ".menu_name." + appmenu
|
||||||
translation = obj[tag]['menu_name'][appmenu]
|
translation = obj[tag]["menu_name"][appmenu]
|
||||||
else:
|
else:
|
||||||
jqpath = tag
|
jqpath = tag
|
||||||
translation = obj[tag]
|
translation = obj[tag]
|
||||||
for lang in self.languages:
|
for lang in self.languages:
|
||||||
lang_path = jqpath + '.' + lang
|
lang_path = jqpath + "." + lang
|
||||||
status = 'OK'
|
status = "OK"
|
||||||
if lang in translation:
|
if lang in translation:
|
||||||
t = translation[lang]
|
t = translation[lang]
|
||||||
# to print translation
|
# to print translation
|
||||||
# print('%s\t%s\t%s' % (i18n, lang_path, t))
|
# print('%s\t%s\t%s' % (i18n, lang_path, t))
|
||||||
if t == '🔇':
|
if t == "🔇":
|
||||||
status = 'MISSING'
|
status = "MISSING"
|
||||||
elif self.mt_regex.fullmatch(t):
|
elif self.mt_regex.fullmatch(t):
|
||||||
status = 'MACHINE_TRANSLATION'
|
status = "MACHINE_TRANSLATION"
|
||||||
elif self.temp_regex.fullmatch(t):
|
elif self.temp_regex.fullmatch(t):
|
||||||
status = 'TEMPORARY'
|
status = "TEMPORARY"
|
||||||
else:
|
else:
|
||||||
status = 'ABSENT'
|
status = "ABSENT"
|
||||||
if self.args.show_ok or status != 'OK':
|
if self.args.show_ok or status != "OK":
|
||||||
print('%s\t%s\t%s' % (i18n, lang_path, status))
|
print("%s\t%s\t%s" % (i18n, lang_path, status))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# TODO: make a call to chatgipptiy to attempt a machine translation
|
||||||
|
def stub_missing(self, i18n, is_manifest):
|
||||||
|
i18n_path = os.path.join(self.args.xousdir, i18n)
|
||||||
|
f = open(
|
||||||
|
i18n_path,
|
||||||
|
)
|
||||||
|
obj = json.load(f)
|
||||||
|
f.close()
|
||||||
|
jqpath = None
|
||||||
|
translation = None
|
||||||
|
for tag in obj.keys():
|
||||||
|
if is_manifest:
|
||||||
|
appmenu = "appmenu." + tag
|
||||||
|
jqpath = tag + ".menu_name." + appmenu
|
||||||
|
translation = obj[tag]["menu_name"][appmenu]
|
||||||
|
else:
|
||||||
|
jqpath = tag
|
||||||
|
translation = obj[tag]
|
||||||
|
for lang in self.languages:
|
||||||
|
lang_path = jqpath + "." + lang
|
||||||
|
if not lang in translation:
|
||||||
|
stub = f"{translation['en']} *EN*"
|
||||||
|
print(f"In {i18n}, at {lang_path} with en stub: {stub}")
|
||||||
|
translation[lang] = stub
|
||||||
|
# blow 'em away. That's what git is for after all.
|
||||||
|
with open(i18n_path, "w") as f:
|
||||||
|
json.dump(
|
||||||
|
obj,
|
||||||
|
f,
|
||||||
|
ensure_ascii=False,
|
||||||
|
check_circular=False,
|
||||||
|
sort_keys=True,
|
||||||
|
indent=4,
|
||||||
|
)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def fill_missing_with_en_stub(self):
|
||||||
|
if self.get_languages() != 0:
|
||||||
|
return 1
|
||||||
|
if self.get_i18n_files() != 0:
|
||||||
|
return 1
|
||||||
|
self.verr("-- filling missing --")
|
||||||
|
for i18n in self.i18n_files:
|
||||||
|
is_manifest = os.path.basename(i18n) == "manifest.json"
|
||||||
|
if self.stub_missing(i18n, is_manifest) != 0:
|
||||||
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def missing(self):
|
def missing(self):
|
||||||
|
|
@ -150,9 +237,9 @@ class Main(object):
|
||||||
return 1
|
return 1
|
||||||
if self.get_i18n_files() != 0:
|
if self.get_i18n_files() != 0:
|
||||||
return 1
|
return 1
|
||||||
self.verr('-- missing --')
|
self.verr("-- missing --")
|
||||||
for i18n in self.i18n_files:
|
for i18n in self.i18n_files:
|
||||||
is_manifest = os.path.basename(i18n) == 'manifest.json'
|
is_manifest = os.path.basename(i18n) == "manifest.json"
|
||||||
if self.show_missing(i18n, is_manifest) != 0:
|
if self.show_missing(i18n, is_manifest) != 0:
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -162,38 +249,49 @@ class Main(object):
|
||||||
# other TAG
|
# other TAG
|
||||||
def add_new_lang(self, i18n, is_manifest):
|
def add_new_lang(self, i18n, is_manifest):
|
||||||
i18n_path = os.path.join(self.args.xousdir, i18n)
|
i18n_path = os.path.join(self.args.xousdir, i18n)
|
||||||
i18n_path_orig = i18n_path + '.orig'
|
i18n_path_orig = i18n_path + ".orig"
|
||||||
if not os.path.exists(i18n_path_orig):
|
if not os.path.exists(i18n_path_orig):
|
||||||
os.rename(i18n_path, i18n_path_orig)
|
os.rename(i18n_path, i18n_path_orig)
|
||||||
self.verr('adding "%s" to %s' % (self.args.new_lang, i18n))
|
self.verr('adding "%s" to %s' % (self.args.new_lang, i18n))
|
||||||
orig_file = open(i18n_path_orig,)
|
orig_file = open(
|
||||||
|
i18n_path_orig,
|
||||||
|
)
|
||||||
obj = json.load(orig_file)
|
obj = json.load(orig_file)
|
||||||
orig_file.close()
|
orig_file.close()
|
||||||
new_file = open(i18n_path,'w')
|
new_file = open(i18n_path, "w")
|
||||||
translation = None
|
translation = None
|
||||||
for tag in obj.keys():
|
for tag in obj.keys():
|
||||||
if is_manifest:
|
if is_manifest:
|
||||||
appmenu = 'appmenu.' + tag
|
appmenu = "appmenu." + tag
|
||||||
translation = obj[tag]['menu_name'][appmenu]
|
translation = obj[tag]["menu_name"][appmenu]
|
||||||
else:
|
else:
|
||||||
translation = obj[tag]
|
translation = obj[tag]
|
||||||
t_from = translation[self.args.from_lang]
|
t_from = translation[self.args.from_lang]
|
||||||
t_new = t_from
|
t_new = t_from
|
||||||
if t_from != '🔇':
|
if t_from != "🔇":
|
||||||
t_new += self.from_hint
|
t_new += self.from_hint
|
||||||
translation[self.args.new_lang] = t_new
|
translation[self.args.new_lang] = t_new
|
||||||
json.dump(obj, new_file, ensure_ascii=False, check_circular=False,
|
json.dump(
|
||||||
sort_keys=True, indent=4)
|
obj,
|
||||||
|
new_file,
|
||||||
|
ensure_ascii=False,
|
||||||
|
check_circular=False,
|
||||||
|
sort_keys=True,
|
||||||
|
indent=4,
|
||||||
|
)
|
||||||
new_file.close()
|
new_file.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def new_lang(self):
|
def new_lang(self):
|
||||||
if self.get_i18n_files() != 0:
|
if self.get_i18n_files() != 0:
|
||||||
return 1
|
return 1
|
||||||
self.from_hint = ' *%s*' % self.args.from_lang.upper()
|
self.from_hint = " *%s*" % self.args.from_lang.upper()
|
||||||
self.verr('-- adding new lang "%s" from "%s" by appending "%s" --' % (self.args.new_lang, self.args.from_lang, self.from_hint))
|
self.verr(
|
||||||
|
'-- adding new lang "%s" from "%s" by appending "%s" --'
|
||||||
|
% (self.args.new_lang, self.args.from_lang, self.from_hint)
|
||||||
|
)
|
||||||
for i18n in self.i18n_files:
|
for i18n in self.i18n_files:
|
||||||
is_manifest = os.path.basename(i18n) == 'manifest.json'
|
is_manifest = os.path.basename(i18n) == "manifest.json"
|
||||||
if self.add_new_lang(i18n, is_manifest) != 0:
|
if self.add_new_lang(i18n, is_manifest) != 0:
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -201,7 +299,7 @@ class Main(object):
|
||||||
def run(self):
|
def run(self):
|
||||||
rc = 0
|
rc = 0
|
||||||
if self.args.verbose:
|
if self.args.verbose:
|
||||||
self.err('verbose mode')
|
self.err("verbose mode")
|
||||||
self.err('xous dir: "%s"' % self.args.xousdir)
|
self.err('xous dir: "%s"' % self.args.xousdir)
|
||||||
self.err('program dir: "%s"' % self.args.pdir)
|
self.err('program dir: "%s"' % self.args.pdir)
|
||||||
self.err('program: "%s"' % self.args.program)
|
self.err('program: "%s"' % self.args.program)
|
||||||
|
|
@ -209,27 +307,38 @@ class Main(object):
|
||||||
if self.args.list_languages:
|
if self.args.list_languages:
|
||||||
rc = self.list_languages()
|
rc = self.list_languages()
|
||||||
elif self.args.list_i18n_files:
|
elif self.args.list_i18n_files:
|
||||||
rc = self.list_i18n_files()
|
rc = self.list_i18n_files()
|
||||||
elif self.args.missing:
|
elif self.args.missing:
|
||||||
rc = self.missing()
|
rc = self.missing()
|
||||||
|
elif self.args.stub:
|
||||||
|
rc = self.fill_missing_with_en_stub()
|
||||||
elif self.args.new_lang:
|
elif self.args.new_lang:
|
||||||
if not self.args.from_lang:
|
if not self.args.from_lang:
|
||||||
self.err('error: you must specify both --from-lang en --to-lang fr')
|
self.err("error: you must specify both --from-lang en --to-lang fr")
|
||||||
rc = 1
|
rc = 1
|
||||||
else:
|
else:
|
||||||
self.get_languages()
|
self.get_languages()
|
||||||
if not self.args.from_lang in self.languages:
|
if not self.args.from_lang in self.languages:
|
||||||
self.err('error: --from-lang %s is not one of the existing langs: %s' % (self.args.from_lang, self.languages))
|
self.err(
|
||||||
|
"error: --from-lang %s is not one of the existing langs: %s"
|
||||||
|
% (self.args.from_lang, self.languages)
|
||||||
|
)
|
||||||
rc = 1
|
rc = 1
|
||||||
elif self.args.new_lang in self.languages:
|
elif self.args.new_lang in self.languages:
|
||||||
self.err('error: --new-lang %s must not be one of the existing langs: %s' % (self.args.from_lang, self.languages))
|
self.err(
|
||||||
|
"error: --new-lang %s must not be one of the existing langs: %s"
|
||||||
|
% (self.args.from_lang, self.languages)
|
||||||
|
)
|
||||||
rc = 1
|
rc = 1
|
||||||
elif not re.fullmatch('^[a-z-]{2,6}$', self.args.new_lang):
|
elif not re.fullmatch("^[a-z-]{2,6}$", self.args.new_lang):
|
||||||
self.err('error: --new-lang %s is not valid lang' % self.args.new_lang)
|
self.err(
|
||||||
|
"error: --new-lang %s is not valid lang" % self.args.new_lang
|
||||||
|
)
|
||||||
rc = 1
|
rc = 1
|
||||||
else:
|
else:
|
||||||
rc = self.new_lang()
|
rc = self.new_lang()
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(Main().run())
|
sys.exit(Main().run())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue