From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 1BB751FF16B for ; Fri, 12 Sep 2025 10:32:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9B3332730F; Fri, 12 Sep 2025 10:32:28 +0200 (CEST) From: Dominik Csapak To: yew-devel@lists.proxmox.com Date: Fri, 12 Sep 2025 10:32:15 +0200 Message-ID: <20250912083225.942200-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250912083225.942200-1-d.csapak@proxmox.com> References: <20250912083225.942200-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.025 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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. [mod.rs, language.rs] Subject: [yew-devel] [PATCH yew-widget-toolkit 3/3] widget: language selector: automatically set text direction from language X-BeenThere: yew-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Yew framework devel list at Proxmox List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Yew framework devel list at Proxmox Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: yew-devel-bounces@lists.proxmox.com Sender: "yew-devel" on first render and when changing the language. Signed-off-by: Dominik Csapak --- src/state/language.rs | 7 +++++++ src/state/mod.rs | 4 ++-- src/widget/language_selector.rs | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/state/language.rs b/src/state/language.rs index 3848731..5621a80 100644 --- a/src/state/language.rs +++ b/src/state/language.rs @@ -76,6 +76,13 @@ pub fn get_available_languages() -> Vec { .collect() } +/// Get [`LanguageInfo`] by its short name. +pub fn get_language_info(lang: &str) -> Option { + get_available_languages() + .into_iter() + .find(|info| info.lang == lang) +} + // this `thread_local!` definition should be fine as this crate is essentially WASM only where // besides web workers and similar ways to spawn futures, there is only one thread. if this // assumption changes, this will need to be adapted. diff --git a/src/state/mod.rs b/src/state/mod.rs index ff91faa..5a3ffc5 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -39,8 +39,8 @@ pub use theme::{ mod language; pub use language::{ - get_available_languages, set_available_languages, Language, LanguageInfo, LanguageObserver, - TextDirection, + get_available_languages, get_language_info, set_available_languages, Language, LanguageInfo, + LanguageObserver, TextDirection, }; use crate::props::StorageLocation; diff --git a/src/widget/language_selector.rs b/src/widget/language_selector.rs index 588cfab..9697915 100644 --- a/src/widget/language_selector.rs +++ b/src/widget/language_selector.rs @@ -1,6 +1,7 @@ use std::rc::Rc; -use crate::state::{Selection, Store}; +use crate::state::{get_current_language_info, get_language_info, Selection, Store}; +use crate::widget::rtl_switcher::set_text_direction; use yew::html::IntoEventCallback; use yew::virtual_dom::{Key, VComp, VNode}; @@ -122,6 +123,11 @@ impl Component for PwtLanguageSelector { } else { Language::store(lang); } + if let Some(info) = get_language_info(&self.lang) { + if let Err(err) = set_text_direction(info.direction) { + log::error!("could not set text direction: {err}"); + } + } true } } @@ -163,6 +169,16 @@ impl Component for PwtLanguageSelector { }) .into() } + + fn rendered(&mut self, _ctx: &Context, first_render: bool) { + if first_render { + if let Some(info) = get_language_info(&self.lang) { + if let Err(err) = set_text_direction(info.direction) { + log::error!("could not set text direction: {err}"); + } + } + } + } } impl From for VNode { -- 2.47.3 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel