public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Matthias Heiserer <m.heiserer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2] fix #3103. node config: allow to configure default UI language
Date: Mon, 24 Jan 2022 11:09:51 +0100	[thread overview]
Message-ID: <20220124100950.2752861-1-m.heiserer@proxmox.com> (raw)

This language is only used if none is set in the cookies.

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
---
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<String>,
-    
+
     #[serde(skip_serializing_if = "Option::is_none")]
     pub email_from: Option<String>,
 
     /// 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<String>,
-    
+
     /// 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<String>,
+
+    /// Default language used in the GUI
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub default_lang: Option<String>,
 }
 
 impl NodeConfig {
-- 
2.30.2





             reply	other threads:[~2022-01-24 10:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 10:09 Matthias Heiserer [this message]
2022-02-03 13:37 ` [pbs-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220124100950.2752861-1-m.heiserer@proxmox.com \
    --to=m.heiserer@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal