From 42349f14dddc02f14d8b7fe679d9370eb8be6808 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Thu, 15 Jan 2026 08:57:13 -0600 Subject: [PATCH] fix(api): respect user locale for artist biography - Add locale field to QobuzClient for API language preference - Pass lang parameter to Qobuz artist detail endpoints - Create set_api_locale command to update client locale - Sync API locale with UI i18n settings automatically - Render artist biography HTML tags properly using @html - Fix syntax error in FavoritesView (missing comma) cp --- src-tauri/src/api/client.rs | 20 ++++++++++++++++++- src-tauri/src/commands/auth.rs | 8 ++++++++ src-tauri/src/lib.rs | 1 + .../components/views/ArtistDetailView.svelte | 6 +++--- src/lib/components/views/FavoritesView.svelte | 2 +- src/lib/i18n/index.ts | 19 ++++++++++++++++-- 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/api/client.rs b/src-tauri/src/api/client.rs index 94aa29c99..60b841e92 100644 --- a/src-tauri/src/api/client.rs +++ b/src-tauri/src/api/client.rs @@ -19,6 +19,7 @@ pub struct QobuzClient { tokens: Arc>>, session: Arc>>, validated_secret: Arc>>, + locale: Arc>, } impl QobuzClient { @@ -34,6 +35,7 @@ impl QobuzClient { tokens: Arc::new(RwLock::new(None)), session: Arc::new(RwLock::new(None)), validated_secret: Arc::new(RwLock::new(None)), + locale: Arc::new(RwLock::new("en".to_string())), }) } @@ -44,6 +46,16 @@ impl QobuzClient { Ok(()) } + /// Set the locale for API requests + pub async fn set_locale(&self, locale: String) { + *self.locale.write().await = locale; + } + + /// Get the current locale + async fn locale(&self) -> String { + self.locale.read().await.clone() + } + /// Get app ID async fn app_id(&self) -> Result { self.tokens @@ -327,9 +339,11 @@ impl QobuzClient { offset: Option, ) -> Result { let url = endpoints::build_url(paths::ARTIST_GET); + let locale = self.locale().await; let mut query = vec![ ("artist_id", artist_id.to_string()), ("extra", "albums,tracks_appears_on,playlists".to_string()), + ("lang", locale), ]; if let Some(l) = limit { query.push(("limit", l.to_string())); @@ -360,7 +374,11 @@ impl QobuzClient { offset: Option, ) -> Result { let url = endpoints::build_url(paths::ARTIST_GET); - let mut query = vec![("artist_id", artist_id.to_string())]; + let locale = self.locale().await; + let mut query = vec![ + ("artist_id", artist_id.to_string()), + ("lang", locale), + ]; if with_albums { query.push(("extra", "albums".to_string())); } diff --git a/src-tauri/src/commands/auth.rs b/src-tauri/src/commands/auth.rs index 0c5584b97..e49313127 100644 --- a/src-tauri/src/commands/auth.rs +++ b/src-tauri/src/commands/auth.rs @@ -141,3 +141,11 @@ pub async fn auto_login(state: State<'_, AppState>) -> Result) -> Result<(), String> { + log::info!("Command: set_api_locale {}", locale); + let client = state.client.lock().await; + client.set_locale(locale).await; + Ok(()) +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 91ab32001..e40d24100 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -260,6 +260,7 @@ pub fn run() { commands::logout, commands::is_logged_in, commands::get_user_info, + commands::set_api_locale, // Credential persistence commands commands::has_saved_credentials, commands::save_credentials, diff --git a/src/lib/components/views/ArtistDetailView.svelte b/src/lib/components/views/ArtistDetailView.svelte index 4d27ed631..b637f030d 100644 --- a/src/lib/components/views/ArtistDetailView.svelte +++ b/src/lib/components/views/ArtistDetailView.svelte @@ -468,9 +468,9 @@ {#if bioText}
-

- {bioExpanded ? bioText : truncatedBio} -

+
+ {@html bioExpanded ? bioText : truncatedBio} +
{#if bioText.length > 300}