From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2702C63013 for ; Mon, 24 Jan 2022 11:11:36 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1D6D61FFB9 for ; Mon, 24 Jan 2022 11:11:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id C72021FFAD for ; Mon, 24 Jan 2022 11:11:34 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7FEC14612A for ; Mon, 24 Jan 2022 11:11:34 +0100 (CET) From: Matthias Heiserer To: pbs-devel@lists.proxmox.com Date: Mon, 24 Jan 2022 11:09:51 +0100 Message-Id: <20220124100950.2752861-1-m.heiserer@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.000 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [node.rs, proxmox-backup-proxy.rs] Subject: [pbs-devel] [PATCH proxmox-backup v2] fix #3103. node config: allow to configure default UI language X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jan 2022 10:11:36 -0000 This language is only used if none is set in the cookies. Signed-off-by: Matthias Heiserer --- Changes from v1: Adhere to max length Remove trailing whitespace Use enum to store available translations Add language name to enum variants Rename chinese and portugese to same case as in i18 files Check for existance of translation file when using default language src/bin/proxmox-backup-proxy.rs | 9 ++++ src/config/node.rs | 75 ++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 523966cf..382d4507 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -168,6 +168,15 @@ async fn get_index_future( lang = language; } } + if lang.is_empty() { + if let Ok((config, _)) = proxmox_backup::config::node::config() { + if let Some(default) = config.default_lang { + if Path::new(&format!("/usr/share/pbs-i18n/pbs-lang-{}.js", default)).exists() { + lang = default; + } + } + } + } let data = json!({ "NodeName": nodename, diff --git a/src/config/node.rs b/src/config/node.rs index 40d7b220..a26f5974 100644 --- a/src/config/node.rs +++ b/src/config/node.rs @@ -57,6 +57,69 @@ pub struct AcmeConfig { account: AcmeAccountName, } +/// All available languages in Proxmox. Taken from proxmox-i18n repository. +/// pt_BR, zh_CN, and zh_TW use the same case in the translation files. +// TODO: auto-generate from available translations +#[api] +#[allow(non_camel_case_types)] +#[derive(Serialize, Deserialize)] +#[serde(rename_all="lowercase")] +pub enum Translation { + /// Arabic + Ar, + /// Catalan + Ca, + /// Danish + Da, + /// German + De, + /// Spanish + Es, + /// Euskera + Eu, + /// Persian (Farsi) + Fa, + /// French + Fr, + /// Galician + Gl, + /// Hebrew + He, + /// Hungarian + Hu, + /// Italian + It, + /// Japanese + Ja, + /// Korean + Kr, + /// Norwegian (Bokmal) + Nb, + /// Dutch + Nl, + /// Norwegian (Nynorsk) + Nn, + /// Polish + Pl, + /// Portuguese (Brazil) + #[serde(rename="pt_BR")] + Pt_Br, + /// Russian + Ru, + /// Slovenian + Sl, + /// Swedish + Sv, + /// Turkish + Tr, + /// Chinese (simplified) + #[serde(rename="zh_CN")] + Zh_Cn, + /// Chinese (traditional) + #[serde(rename="zh_TW")] + Zh_Tw, +} + #[api( properties: { acme: { @@ -100,6 +163,10 @@ pub struct AcmeConfig { schema: OPENSSL_CIPHERS_TLS_1_2_SCHEMA, optional: true, }, + "default-lang" : { + schema: Translation::API_SCHEMA, + optional: true, + } }, )] #[derive(Deserialize, Serialize, Updater)] @@ -127,17 +194,21 @@ pub struct NodeConfig { #[serde(skip_serializing_if = "Option::is_none")] pub http_proxy: Option, - + #[serde(skip_serializing_if = "Option::is_none")] pub email_from: Option, /// List of TLS ciphers for TLS 1.3 that will be used by the proxy. (Proxy has to be restarted for changes to take effect) #[serde(skip_serializing_if = "Option::is_none", rename="ciphers-tls-1.3")] pub ciphers_tls_1_3: Option, - + /// List of TLS ciphers for TLS <= 1.2 that will be used by the proxy. (Proxy has to be restarted for changes to take effect) #[serde(skip_serializing_if = "Option::is_none", rename="ciphers-tls-1.2")] pub ciphers_tls_1_2: Option, + + /// Default language used in the GUI + #[serde(skip_serializing_if = "Option::is_none")] + pub default_lang: Option, } impl NodeConfig { -- 2.30.2