From 859aae94c9a511d94451b127b00dd4e8eaf384d6 Mon Sep 17 00:00:00 2001 From: David Kotval Date: Wed, 24 Jan 2024 16:39:43 +0000 Subject: [PATCH 1/8] feat: added stub to automatically fill in transaltions A missing translation will cause a panic in the localization macro. As a short term solution. The stub function in the i18n_helper.py just fills anything missing with its English placeholder. Note: After refactoring the python packing, I intend to add an "auto machine translate" funciton as well. --- tools/i18n_helper.py | 253 +++++++++++++++++++++++++++++++------------ 1 file changed, 181 insertions(+), 72 deletions(-) diff --git a/tools/i18n_helper.py b/tools/i18n_helper.py index 76202e266..dbc9d1b77 100755 --- a/tools/i18n_helper.py +++ b/tools/i18n_helper.py @@ -8,42 +8,72 @@ import os.path import pwd import re -class Main(object): +class Main(object): def __init__(self): parser = argparse.ArgumentParser(description="Xous i18n Helper") - parser.add_argument('-v', '--verbose', - help='Prints details of each action', - action='store_true', required=False) - parser.add_argument('-l', '--list-languages', - help='Lists current translations', - action='store_true', required=False) - parser.add_argument('-i', '--list-i18n-files', - help='Lists i18n files', - action='store_true', 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( + "-v", + "--verbose", + help="Prints details of each action", + action="store_true", + required=False, + ) + parser.add_argument( + "-l", + "--list-languages", + help="Lists current translations", + action="store_true", + required=False, + ) + parser.add_argument( + "-i", + "--list-i18n-files", + help="Lists i18n files", + action="store_true", + 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.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.pdir = os.path.normpath(os.path.dirname(self.args.program)) self.args.xousdir = os.path.normpath(os.path.dirname(self.args.pdir)) self.args.program = os.path.basename(self.args.program) self.errfile = sys.stderr # if end of string matches ' *EN*' (or some other lang) - self.temp_regex = re.compile('^.* \*[a-zA-Z]{2}\*$') - self.mt_regex = re.compile('^.* \*MT\*$') + self.temp_regex = re.compile("^.* \*[a-zA-Z]{2}\*$") + self.mt_regex = re.compile("^.* \*MT\*$") def out(self, *objects): print(*objects) @@ -56,15 +86,19 @@ class Main(object): self.err(*objects) def get_languages(self): - self.verr('-- get languages --') + self.verr("-- get languages --") # 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): - self.err('cannot find: %s' % root_keys); + self.err("cannot find: %s" % root_keys) return 1 # read keys in "rootkeys.backup_key": - essential = 'rootkeys.backup_key' - f = open(root_keys,) + essential = "rootkeys.backup_key" + f = open( + root_keys, + ) obj = json.load(f) self.languages = [] if essential in obj: @@ -76,34 +110,37 @@ class Main(object): def list_languages(self): if self.get_languages() != 0: return 1 - self.verr('-- list languages --') + self.verr("-- list languages --") for lang in self.languages: self.out(lang) return 0 def get_i18n_files(self): - self.verr('-- get i18n files --') + self.verr("-- get 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: topdir = os.path.join(self.args.xousdir, top) if os.path.exists(topdir): - if top == 'apps': - manifest = os.path.join(topdir, 'manifest.json') + if top == "apps": + manifest = os.path.join(topdir, "manifest.json") 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): thingdir = os.path.join(topdir, thing) 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): - self.i18n_files.append(i18n_path[len(self.args.xousdir)+1:]) + self.i18n_files.append( + i18n_path[len(self.args.xousdir) + 1 :] + ) return 0 def list_i18n_files(self): if self.get_i18n_files() != 0: return 1 - self.verr('-- list i18n files --') + self.verr("-- list i18n files --") for pathname in self.i18n_files: self.out(pathname) return 0 @@ -113,36 +150,86 @@ class Main(object): # other TAG def show_missing(self, i18n, is_manifest): i18n_path = os.path.join(self.args.xousdir, i18n) - f = open(i18n_path,) + 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] + 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 - status = 'OK' + lang_path = jqpath + "." + lang + status = "OK" if lang in translation: t = translation[lang] # to print translation # print('%s\t%s\t%s' % (i18n, lang_path, t)) - if t == '🔇': - status = 'MISSING' + if t == "🔇": + status = "MISSING" elif self.mt_regex.fullmatch(t): - status = 'MACHINE_TRANSLATION' + status = "MACHINE_TRANSLATION" elif self.temp_regex.fullmatch(t): - status = 'TEMPORARY' + status = "TEMPORARY" else: - status = 'ABSENT' - if self.args.show_ok or status != 'OK': - print('%s\t%s\t%s' % (i18n, lang_path, status)) + status = "ABSENT" + if self.args.show_ok or status != "OK": + 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 def missing(self): @@ -150,9 +237,9 @@ class Main(object): return 1 if self.get_i18n_files() != 0: return 1 - self.verr('-- missing --') + self.verr("-- missing --") 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: return 1 return 0 @@ -162,38 +249,49 @@ class Main(object): # other TAG def add_new_lang(self, i18n, is_manifest): 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): os.rename(i18n_path, i18n_path_orig) 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) orig_file.close() - new_file = open(i18n_path,'w') + new_file = open(i18n_path, "w") translation = None for tag in obj.keys(): if is_manifest: - appmenu = 'appmenu.' + tag - translation = obj[tag]['menu_name'][appmenu] + appmenu = "appmenu." + tag + translation = obj[tag]["menu_name"][appmenu] else: translation = obj[tag] t_from = translation[self.args.from_lang] t_new = t_from - if t_from != '🔇': + if t_from != "🔇": t_new += self.from_hint translation[self.args.new_lang] = t_new - json.dump(obj, new_file, ensure_ascii=False, check_circular=False, - sort_keys=True, indent=4) + json.dump( + obj, + new_file, + ensure_ascii=False, + check_circular=False, + sort_keys=True, + indent=4, + ) new_file.close() return 0 def new_lang(self): if self.get_i18n_files() != 0: return 1 - 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.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) + ) 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: return 1 return 0 @@ -201,7 +299,7 @@ class Main(object): def run(self): rc = 0 if self.args.verbose: - self.err('verbose mode') + self.err("verbose mode") self.err('xous dir: "%s"' % self.args.xousdir) self.err('program dir: "%s"' % self.args.pdir) self.err('program: "%s"' % self.args.program) @@ -209,27 +307,38 @@ class Main(object): if self.args.list_languages: rc = self.list_languages() elif self.args.list_i18n_files: - rc = self.list_i18n_files() + rc = self.list_i18n_files() elif self.args.missing: rc = self.missing() + elif self.args.stub: + rc = self.fill_missing_with_en_stub() elif self.args.new_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 else: self.get_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 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 - 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) + 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 + ) rc = 1 else: rc = self.new_lang() return rc + if __name__ == "__main__": sys.exit(Main().run()) From 14da821164888c48dd1875aa771ef0056f70c93c Mon Sep 17 00:00:00 2001 From: David Kotval Date: Wed, 24 Jan 2024 16:42:36 +0000 Subject: [PATCH 2/8] fix: added English stubs to tls messages. --- libs/tls/locales/i18n.json | 152 +++++++++++++++++++++++++------------ 1 file changed, 103 insertions(+), 49 deletions(-) diff --git a/libs/tls/locales/i18n.json b/libs/tls/locales/i18n.json index 5ed746284..176f579ef 100644 --- a/libs/tls/locales/i18n.json +++ b/libs/tls/locales/i18n.json @@ -1,74 +1,128 @@ { "tls.check_trust_prompt": { "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 ", + "en-tts": "net tls ", + "fr": "net tls *EN*", + "ja": "net tls *EN*", + "zh": "net tls *EN*" }, "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 \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 \n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser." - }, - "tls.cmd": { - "en": "net tls ", - "en-tts": "net tls " + "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 \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 \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*", + "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 \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*", + "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 \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.deleteall_cmd": { "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": { "en": "deleted Certificates", - "en-tts": "deleted Certificates" - }, - "tls.list_cmd": { - "en": "list trusted CA certificates", - "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" + "en-tts": "deleted Certificates", + "fr": "deleted Certificates *EN*", + "ja": "deleted Certificates *EN*", + "zh": "deleted Certificates *EN*" }, "tls.inspect_cmd": { "en": "save host CA'a if trusted", - "en-tts": "save host CA'a if trusted" - }, - "tls.inspect_fail_servername": { - "en": "failed to create server name from", - "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" + "en-tts": "save host CA'a if trusted", + "fr": "save host CA'a if trusted *EN*", + "ja": "save host CA'a if trusted *EN*", + "zh": "save host CA'a if trusted *EN*" }, "tls.inspect_done": { "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": { "en": "make tls connection to host", - "en-tts": "make tls connection to host" - }, - "tls.test_success_tcp": { - "en": "tcp connected\n", - "en-tts": "tcp connected" - }, - "tls.test_success_get": { - "en": "tls accepted GET\n", - "en-tts": "tls accepted GET" + "en-tts": "make tls connection to host", + "fr": "make tls connection to host *EN*", + "ja": "make tls connection to host *EN*", + "zh": "make tls connection to host *EN*" }, "tls.test_success_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*" } -} +} \ No newline at end of file From 701e5b46fe30de4c10a59badb7cc9468b3fc1665 Mon Sep 17 00:00:00 2001 From: David Kotval Date: Wed, 24 Jan 2024 16:45:46 +0000 Subject: [PATCH 3/8] feat: fill app manifest with English stubs --- apps/manifest.json | 79 ++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/apps/manifest.json b/apps/manifest.json index 6e00842f5..f97a0d821 100644 --- a/apps/manifest.json +++ b/apps/manifest.json @@ -3,8 +3,11 @@ "context_name": "App Loader", "menu_name": { "appmenu.app-loader": { - "en": "App Loader", - "en-tts": "App Loader" + "en": "App Loader", + "en-tts": "App Loader", + "fr": "App Loader *EN*", + "ja": "App Loader *EN*", + "zh": "App Loader *EN*" } }, "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": { "context_name": "Hello World", "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": { "context_name": "Matrix cli", "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": { "context_name": "repl demo app", "menu_name": { @@ -79,11 +90,27 @@ "context_name": "signal", "menu_name": { "appmenu.sigchat": { - "en": "Signal" + "en": "Signal", + "en-tts": "Signal *EN*", + "fr": "Signal *EN*", + "ja": "Signal *EN*", + "zh": "Signal *EN*" } }, "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": { "context_name": "Key Vault", "menu_name": { @@ -96,13 +123,5 @@ } }, "submenu": 1 - }, - "transientdisk": { - "context_name": "Transient USB disk", - "menu_name": { - "appmenu.transientdisk": { - "en": "Transient USB disk" - } - } } -} +} \ No newline at end of file From fa20e3c649aaaef5fd28c51fab955db7bce7bc33 Mon Sep 17 00:00:00 2001 From: David Kotval Date: Wed, 24 Jan 2024 16:46:08 +0000 Subject: [PATCH 4/8] wip: debugging sigchat build fail due to missing translations --- locales/build.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/locales/build.rs b/locales/build.rs index d32dccccf..e050522ec 100644 --- a/locales/build.rs +++ b/locales/build.rs @@ -18,16 +18,30 @@ type Locale = String; type Value = String; type Translations = HashMap>; +macro_rules! build_debug { + ($($tokens: tt)*) => { + println!("cargo:warning={}", format!($($tokens)*)) + } +} + fn read_locales() -> Translations { 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 locales = format!("{}/**/i18n.json", build_directory); - println!("Reading {}", &locales); - - for entry in glob(&locales).expect("Failed to read glob pattern") { + build_debug!("Reading {}", &locales); + // TODO: once this works, get from external directory/location arguments from xtask script + 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(); + build_debug!("{:?}",entry); println!("cargo:rerun-if-changed={}", entry.display()); let file = File::open(entry).expect("Failed to open the file"); let mut reader = std::io::BufReader::new(file); From b2208850b2789304a6e9f731faf86acb8be83447 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 29 Jan 2024 23:14:44 +0800 Subject: [PATCH 5/8] add a U2F USB event observer hook to the USB stack the intent of this is to send a message to listeners that want to be aware of the fact that a U2F packet has arrived. --- services/usb-device-xous/src/api.rs | 9 ++++++++ services/usb-device-xous/src/lib.rs | 10 +++++++++ services/usb-device-xous/src/main_hw.rs | 30 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/services/usb-device-xous/src/api.rs b/services/usb-device-xous/src/api.rs index 14e0f7470..f68a41f43 100644 --- a/services/usb-device-xous/src/api.rs +++ b/services/usb-device-xous/src/api.rs @@ -27,6 +27,8 @@ pub(crate) enum Opcode { DebugUsbOp = 9, /// Set autotype rate SetAutotypeRate = 10, + /// Register a USB event observer + RegisterUsbObserver = 11, /// Send a U2F message U2fTx = 128, @@ -139,3 +141,10 @@ pub struct UsbSerialBinary { pub d: [u8; SERIAL_BINARY_BUFLEN], pub len: usize, } + +/// this structure is used to register a USB listener. +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] +pub(crate) struct UsbListenerRegistration { + pub server_name: xous_ipc::String<64>, + pub listener_op_id: usize, +} diff --git a/services/usb-device-xous/src/lib.rs b/services/usb-device-xous/src/lib.rs index f84a49ed9..9425e30cb 100644 --- a/services/usb-device-xous/src/lib.rs +++ b/services/usb-device-xous/src/lib.rs @@ -370,6 +370,16 @@ impl UsbHid { ) .unwrap(); } + + pub fn register_u2f_observer(&self, server_name: &str, action_opcode: usize) { + let kr = UsbListenerRegistration { + server_name: xous_ipc::String::<64>::from_str(server_name), + listener_op_id: action_opcode, + }; + let buf = Buffer::into_buf(kr).unwrap(); + buf.lend(self.conn, Opcode::RegisterUsbObserver.to_u32().unwrap()) + .expect("couldn't register listener"); + } } use core::sync::atomic::{AtomicU32, Ordering}; diff --git a/services/usb-device-xous/src/main_hw.rs b/services/usb-device-xous/src/main_hw.rs index f0a4396f4..fd783c213 100644 --- a/services/usb-device-xous/src/main_hw.rs +++ b/services/usb-device-xous/src/main_hw.rs @@ -294,6 +294,10 @@ pub(crate) fn main_hw() -> ! { let mut was_suspend = true; let mut autotype_delay_ms = 30; + // event observer connection + let mut observer_conn: Option = None; + let mut observer_op: Option = None; + #[cfg(feature = "minimal")] std::thread::spawn(move || { // this keeps the watchdog alive in minimal mode; if there's no event, eventually the watchdog times @@ -492,6 +496,15 @@ pub(crate) fn main_hw() -> ! { xous::return_scalar(msg.sender, 1).expect("couldn't return compatibility status") }), Some(Opcode::U2fRxDeferred) => { + // notify the event listener, if any + if observer_conn.is_some() && observer_op.is_some() { + xous::try_send_message( + observer_conn.unwrap(), + xous::Message::new_scalar(observer_op.unwrap(), 0, 0, 0, 0), + ) + .ok(); + } + if fido_listener_pid.is_none() { fido_listener_pid = msg.sender.pid(); } @@ -1537,6 +1550,23 @@ pub(crate) fn main_hw() -> ! { serial_trng_interval.store(TRNG_REFILL_DELAY_MS, Ordering::SeqCst); } } + Some(Opcode::RegisterUsbObserver) => { + let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; + let ur = buffer.as_flat::().unwrap(); + if observer_conn.is_none() { + match xns.request_connection_blocking(ur.server_name.as_str()) { + Ok(cid) => { + observer_conn = Some(cid); + observer_op = Some(ur.listener_op_id as usize); + } + Err(e) => { + log::error!("couldn't connect to observer: {:?}", e); + observer_conn = None; + observer_op = None; + } + } + } + } Some(Opcode::Quit) => { log::warn!("Quit received, goodbye world!"); break; From f162555ac309a9ceb8e94b8cfad2762a4207d8ec Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 29 Jan 2024 23:15:34 +0800 Subject: [PATCH 6/8] register a listener for U2F events plugged into autobacklight this should cause the backlight to turn on anytime there is an incoming U2F packet, allowing a user to read the screen and see what they are trying to allow for authentication even in a dark room. --- services/status/src/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/status/src/main.rs b/services/status/src/main.rs index dd76f03f9..2f8f32eb7 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -223,8 +223,10 @@ fn wrapped_main() -> ! { // ------------------ lay out our public API infrastructure // ok, now that we have a GID, we can continue on with our merry way let status_gid: Gid = Gid::new(canvas_gid); - // allow only one connection, from keyboard to us. - let status_sid = xns.register_name(SERVER_NAME_STATUS, Some(1)).unwrap(); + // Expected connections: + // - from keyboard + // - from USB HID + let status_sid = xns.register_name(SERVER_NAME_STATUS, Some(2)).unwrap(); // create a connection for callback hooks let cb_cid = xous::connect(status_sid).unwrap(); unsafe { CB_TO_MAIN_CONN = Some(cb_cid) }; @@ -395,6 +397,9 @@ fn wrapped_main() -> ! { kbd.lock() .unwrap() .register_observer(SERVER_NAME_STATUS, StatusOpcode::Keypress.to_u32().unwrap() as usize); + // register the USB U2F event listener - point to the same handler as key press since our intention is to + // just toggle the backlight + usb_hid.register_u2f_observer(SERVER_NAME_STATUS, StatusOpcode::Keypress.to_u32().unwrap() as usize); let autobacklight_enabled = Arc::new(Mutex::new(true)); let (tx, rx): (Sender, Receiver) = unbounded(); From c4d40fbccb6154bcbaf7a3bf46e9c0352b4c631a Mon Sep 17 00:00:00 2001 From: David Kotval Date: Mon, 29 Jan 2024 11:54:42 -0600 Subject: [PATCH 7/8] fix: don't add *EN* to en-tts locale --- apps/manifest.json | 10 +++++----- tools/i18n_helper.py | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/manifest.json b/apps/manifest.json index f97a0d821..ca78d9d7a 100644 --- a/apps/manifest.json +++ b/apps/manifest.json @@ -29,7 +29,7 @@ "menu_name": { "appmenu.chat-test": { "en": "Chat UI test", - "en-tts": "Chat UI test *EN*", + "en-tts": "Chat UI test", "fr": "Chat UI test *EN*", "ja": "Chat UI test *EN*", "zh": "Chat UI test *EN*" @@ -54,7 +54,7 @@ "menu_name": { "appmenu.mtxchat": { "en": "[matrix]", - "en-tts": "[matrix] *EN*", + "en-tts": "[matrix]", "fr": "[matrix] *EN*", "ja": "[matrix] *EN*", "zh": "[matrix] *EN*" @@ -91,7 +91,7 @@ "menu_name": { "appmenu.sigchat": { "en": "Signal", - "en-tts": "Signal *EN*", + "en-tts": "Signal", "fr": "Signal *EN*", "ja": "Signal *EN*", "zh": "Signal *EN*" @@ -104,7 +104,7 @@ "menu_name": { "appmenu.transientdisk": { "en": "Transient USB disk", - "en-tts": "Transient USB disk *EN*", + "en-tts": "Transient USB disk", "fr": "Transient USB disk *EN*", "ja": "Transient USB disk *EN*", "zh": "Transient USB disk *EN*" @@ -124,4 +124,4 @@ }, "submenu": 1 } -} \ No newline at end of file +} diff --git a/tools/i18n_helper.py b/tools/i18n_helper.py index dbc9d1b77..0970d5e96 100755 --- a/tools/i18n_helper.py +++ b/tools/i18n_helper.py @@ -184,7 +184,6 @@ class Main(object): 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( @@ -205,7 +204,10 @@ class Main(object): for lang in self.languages: lang_path = jqpath + "." + lang if not lang in translation: - stub = f"{translation['en']} *EN*" + if lang == "en-tts": + stub = translation['en']} + else: + 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. From e2daf45e175c99e14624998a5ddc4c020b0ee114 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 30 Jan 2024 01:58:23 +0800 Subject: [PATCH 8/8] update release notes --- RELEASE-v0.9.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-v0.9.md b/RELEASE-v0.9.md index 686cd2f34..ae41cce88 100644 --- a/RELEASE-v0.9.md +++ b/RELEASE-v0.9.md @@ -465,6 +465,7 @@ perform the Xous firmware upgrade. This requires running manual update commands, - `sigchat` moved to its own repo with AGPL licensing: https://github.com/betrusted-io/sigchat - Formatting and contribution standards have been modified. Formatting with `rustfmt` and trailing white space removal is now mandatory for all Xous contributions, see [#477](https://github.com/betrusted-io/xous-core/pull/477) for a discussion of how we got there and why. - The repo has gone through a "flag day" where all the crates have been formatted, which means commits before the flag day may be more difficult to undo. The changes are committed on a crate-by-crate basis, so if something is really broken we can undo the formatting for the crate and add an exception to the rustfmt rules. +- Implement #478: backlight should turn on automatically when a U2F/FIDO packet comes in from the host, allowing users in dark conditions to see the screen and know what they are approving. ## Roadmap