From 86e113b6783cdf5d0267750ebcbce12ddecdadc0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 26 Jul 2021 00:49:33 +0800 Subject: [PATCH] =?UTF-8?q?add=20locale=20to=20front-end;=20update=20menus?= =?UTF-8?q?=20to=20suppress=20=F0=9F=94=87characters=20automatically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/gam/src/lib.rs | 9 +++++++-- services/ime-frontend/Cargo.toml | 1 + services/ime-frontend/locales/i18n.json | 7 +++++++ services/ime-frontend/src/main.rs | 4 +++- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 services/ime-frontend/locales/i18n.json diff --git a/services/gam/src/lib.rs b/services/gam/src/lib.rs index 241f2066e..01d7ab9f7 100644 --- a/services/gam/src/lib.rs +++ b/services/gam/src/lib.rs @@ -263,7 +263,7 @@ impl Gam { ).map(|_| ()) } /// requests a context switch to a new app. Doesn't have to be obeyed, depending - /// upon the GAM's policy. Only the main menu can switch apps, hence the token. + /// upon the GAM's policy. Only the certain sources can switch apps, hence the token. pub fn switch_to_app(&self, app_name: &str, token: [u32; 4]) -> Result<(), xous::Error> { let switchapp = SwitchToApp { token, @@ -277,7 +277,9 @@ impl Gam { let buf = Buffer::into_buf(menu_name).or(Err(xous::Error::InternalError))?; buf.send(self.conn, Opcode::RaiseMenu.to_u32().unwrap()).or(Err(xous::Error::InternalError)).map(|_|()) } - + pub fn raise_modal(&self, modal_name: &str) -> Result<(), xous::Error> { + self.raise_menu(modal_name) + } /// this is a one-way door, once you've set it, you can't unset it. pub fn set_devboot(&self, enable: bool) -> Result<(), xous::Error> { let ena = @@ -397,6 +399,9 @@ impl Menu { } // if successful, returns None, otherwise, the menu item pub fn add_item(&mut self, new_item: MenuItem) -> Option { + if new_item.name.as_str().unwrap() == "🔇" { // suppress the addition of menu items that are not applicable for a given locale + return None; + } // first, do the insertion. // add the menu item to the first free slot // any modifications to the menu structure should guarantee that the list is compacted diff --git a/services/ime-frontend/Cargo.toml b/services/ime-frontend/Cargo.toml index b0cb738f2..579b786c5 100644 --- a/services/ime-frontend/Cargo.toml +++ b/services/ime-frontend/Cargo.toml @@ -15,6 +15,7 @@ log = "0.4" log-server = {path = "../log-server"} ticktimer-server = {path = "../ticktimer-server"} xous = {path = "../../xous-rs"} +locales = {path = "../../locales"} xous-ipc = {path = "../../xous-ipc"} xous-names = {path = "../xous-names"} diff --git a/services/ime-frontend/locales/i18n.json b/services/ime-frontend/locales/i18n.json new file mode 100644 index 000000000..ee0f61ea3 --- /dev/null +++ b/services/ime-frontend/locales/i18n.json @@ -0,0 +1,7 @@ +{ + "input.greeting": { + "en": "Ready for input...", + "zh": "等待输入...", + "en-audio": "Ready for input" + } +} \ No newline at end of file diff --git a/services/ime-frontend/src/main.rs b/services/ime-frontend/src/main.rs index db8dec49f..a222476a6 100644 --- a/services/ime-frontend/src/main.rs +++ b/services/ime-frontend/src/main.rs @@ -19,6 +19,8 @@ use xous::{CID, msg_scalar_unpack}; use core::fmt::Write; +use locales::t; + /// max number of prediction options to track/render const MAX_PREDICTION_OPTIONS: usize = 4; pub(crate) const EMOJI_MENU_NAME: &'static str = "emoji menu"; @@ -550,7 +552,7 @@ impl InputTracker { empty_tv.draw_border = false; empty_tv.border_width = 1; empty_tv.clear_area = true; - write!(empty_tv.text, "Ready for input...").expect("couldn't set up empty TextView"); + write!(empty_tv.text, "{}", t!("input.greeting", xous::LANG)).expect("couldn't set up empty TextView"); if debug_canvas { info!("pc canvas {:?}", pc) } self.gam.post_textview(&mut empty_tv).expect("can't draw prediction TextView"); } else if update_predictor || force_redraw {