From 3890d8ac88b2fdfa7b54d433e8e2edf2164be6f0 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 8 Apr 2021 17:44:53 +0200 Subject: add translation logic, locales for en and de This adds a basic "replace fixed keys"-approach to translating the UI of surveys. So far this works great, but for complex things it may fail for some languages — for now I'll just try to take care not to add any output that puts things in the middle of sentences, which I think should work for a simple survey thing. The default language is still english, which is important as the language is declared withing a survey config — i.e. if loading it fails, it cannot be applied, and the "enter passphrase" dialog can also not change based on locales. This could possibly be fixed by adding an unencrypted "header" to the encrypted configs, but for now I'm not sure if that makes a lot of sense — it may be easier to just guess based on the browser's settings, and otherwise fall back to some specified default language. The "thanks for your answers"-page also has no translation so far. --- utils/src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/src/main.rs b/utils/src/main.rs index 3d6f885..4428ac3 100644 --- a/utils/src/main.rs +++ b/utils/src/main.rs @@ -11,12 +11,20 @@ use secrecy::ExposeSecret; use age::x25519::Recipient; +#[derive(Deserialize, Serialize, StaticType, Debug)] +#[serde(rename_all="lowercase")] +enum Lang { + de, + en +} + #[derive(Deserialize, Serialize, StaticType, Debug)] struct Survey { title: String, description: String, questions: Vec, - pubkey: Option + pubkey: Option, + lang: Lang } #[derive(Deserialize, Serialize, StaticType, Debug)] @@ -56,9 +64,10 @@ fn main () { // imported: just wrap our input code into a dhall "let"-statement. // Probably doesn't scale very vell, though ... let code = format!( - "let Question = {} \nlet Answers = {} \nin {}", + "let Question = {} \nlet Answers = {} \nlet Lang = {}\nin {}", Question::static_type(), AnswerSpace::static_type(), + Lang::static_type(), config_file ); match serde_dhall::from_str(&code) -- cgit v1.2.3