fix #3103. node config: allow to configure default UI language

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

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
This commit is contained in:
Matthias Heiserer 2022-01-24 11:09:51 +01:00 committed by Thomas Lamprecht
parent 163629e62e
commit 68811af9f9
2 changed files with 82 additions and 2 deletions

View File

@ -170,6 +170,15 @@ async fn get_index_future(
lang = language; 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!({ let data = json!({
"NodeName": nodename, "NodeName": nodename,

View File

@ -57,6 +57,69 @@ pub struct AcmeConfig {
account: AcmeAccountName, 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( #[api(
properties: { properties: {
acme: { acme: {
@ -100,6 +163,10 @@ pub struct AcmeConfig {
schema: OPENSSL_CIPHERS_TLS_1_2_SCHEMA, schema: OPENSSL_CIPHERS_TLS_1_2_SCHEMA,
optional: true, optional: true,
}, },
"default-lang" : {
schema: Translation::API_SCHEMA,
optional: true,
}
}, },
)] )]
#[derive(Deserialize, Serialize, Updater)] #[derive(Deserialize, Serialize, Updater)]
@ -127,17 +194,21 @@ pub struct NodeConfig {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub http_proxy: Option<String>, pub http_proxy: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub email_from: Option<String>, 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) /// 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")] #[serde(skip_serializing_if = "Option::is_none", rename="ciphers-tls-1.3")]
pub ciphers_tls_1_3: Option<String>, 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) /// 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")] #[serde(skip_serializing_if = "Option::is_none", rename="ciphers-tls-1.2")]
pub ciphers_tls_1_2: Option<String>, 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 { impl NodeConfig {