i18n(rust): my-qbz strings

Wrap user-facing eyebrow labels (MIXTAPE/COLLECTION/ARTIST), album/item
counts, add/edit/builder/cover toasts, dialog titles + image filters,
play/queue toasts, and the default discography name in the My QBZ
controllers with qbz_i18n t/t_args/tf helpers. Keep the My QBZ brand
itself untranslated via positional interpolation.

cc
This commit is contained in:
vicrodh committed 2026-06-23 14:32:38 -06:00
1 parent f14c513099
commit 66aa469aa5
9 files changed
+81 -80

No files matched your search

+5 -9
View File
@@ -252,22 +252,18 @@ fn kind_str(kind: CollectionKind) -> &'static str {
}
/// Eyebrow label, uppercase (Tauri `labelFor` / `mixtapes.label`).
fn label_for(kind: CollectionKind) -> &'static str {
fn label_for(kind: CollectionKind) -> String {
match kind {
CollectionKind::Mixtape => "MIXTAPE",
CollectionKind::Collection => "COLLECTION",
CollectionKind::ArtistCollection => "ARTIST",
CollectionKind::Mixtape => qbz_i18n::t("MIXTAPE"),
CollectionKind::Collection => qbz_i18n::t("COLLECTION"),
CollectionKind::ArtistCollection => qbz_i18n::t("ARTIST"),
}
}
/// `mixtapes.albumCount` ICU plural — "1 album" / "N albums". Always "album(s)"
/// regardless of item_type (1:1 with the PSD).
fn album_count_label(count: usize) -> String {
if count == 1 {
"1 album".to_string()
} else {
format!("{count} albums")
}
qbz_i18n::tf("{} album", "{} albums", count as i64, &[&count.to_string()])
}
/// Pre-downscale a Qobuz cover URL to a per-cell target size, mirroring the
+20 -17
View File
@@ -83,13 +83,14 @@ pub fn open(window: &AppWindow, items: Vec<AddItem>) {
let first = &items[0];
let header_title: String = if bulk {
format!("{} items", items.len())
qbz_i18n::tf("{} item", "{} items", items.len() as i64, &[&items.len().to_string()])
} else {
first.title.clone()
};
let header_subtitle: String = if bulk {
// "{first title} + N more" — hardcoded English suffix (1:1 with PSD).
format!("{} + {} more", first.title, items.len() - 1)
// "{first title} + N more" — 1:1 with PSD.
let more = (items.len() - 1).to_string();
qbz_i18n::t_args("{} + {} more", &[&first.title, &more])
} else {
first.subtitle.clone().unwrap_or_default()
};
@@ -207,21 +208,17 @@ fn kind_icon(kind: CollectionKind) -> &'static str {
}
}
fn kind_label(kind: CollectionKind) -> &'static str {
fn kind_label(kind: CollectionKind) -> String {
match kind {
CollectionKind::Mixtape => "MIXTAPE",
CollectionKind::Collection => "COLLECTION",
CollectionKind::ArtistCollection => "ARTIST",
CollectionKind::Mixtape => qbz_i18n::t("MIXTAPE"),
CollectionKind::Collection => qbz_i18n::t("COLLECTION"),
CollectionKind::ArtistCollection => qbz_i18n::t("ARTIST"),
}
}
/// "N albums" / "1 album" (always "album(s)" regardless of item_type — 1:1 PSD).
fn album_count_label(count: usize) -> String {
if count == 1 {
"1 album".to_string()
} else {
format!("{count} albums")
}
qbz_i18n::tf("{} album", "{} albums", count as i64, &[&count.to_string()])
}
/// Render loaded rows into `MyQbzAddState`, applying the active search filter.
@@ -316,14 +313,20 @@ pub fn add_items(collection_id: &str, items: &[AddItem]) -> AddOutcome {
pub fn toast_outcome(window: &AppWindow, name: &str, outcome: &AddOutcome) {
let msg = if outcome.added == 0 {
// Nothing inserted -> everything was a duplicate ("Already in {name}").
format!("Already in {name}")
qbz_i18n::t_args("Already in {}", &[name])
} else if outcome.skipped > 0 {
format!(
"Added {} to {name} ({} duplicate(s) skipped)",
outcome.added, outcome.skipped
let skipped_label = qbz_i18n::tf(
"{} duplicate skipped",
"{} duplicates skipped",
outcome.skipped as i64,
&[&outcome.skipped.to_string()],
);
qbz_i18n::t_args(
"Added {} to {} ({})",
&[&outcome.added.to_string(), name, &skipped_label],
)
} else {
format!("Added {} to {name}", outcome.added)
qbz_i18n::t_args("Added {} to {}", &[&outcome.added.to_string(), name])
};
let kind = if outcome.added == 0 {
ToastKind::Info
+2 -2
View File
@@ -729,11 +729,11 @@ pub fn install(
// Default collection name if still empty.
if state.get_collection_name().is_empty() {
let base = if artist_name.is_empty() {
"Artist".to_string()
qbz_i18n::t("Artist")
} else {
artist_name.clone()
};
state.set_collection_name(format!("{base} — Complete Discography").into());
state.set_collection_name(qbz_i18n::t_args("{} — Complete Discography", &[&base]).into());
}
// Keep the trimmed-empty gate in sync with whatever the name now holds
// (the default name is non-empty; a pre-existing whitespace name stays
+6 -6
View File
@@ -161,8 +161,8 @@ pub fn upload(
) {
handle.clone().spawn(async move {
let Some(file) = rfd::AsyncFileDialog::new()
.set_title("Choose a cover image")
.add_filter("Image", &["png", "jpg", "jpeg", "webp"])
.set_title(&qbz_i18n::t("Choose a cover image"))
.add_filter(&qbz_i18n::t("Image"), &["png", "jpg", "jpeg", "webp"])
.pick_file()
.await
else {
@@ -177,12 +177,12 @@ pub fn upload(
match result {
Ok(_) => {
crate::toast::success_weak(&weak, "Cover updated");
crate::toast::success_weak(&weak, qbz_i18n::t("Cover updated"));
reload(weak.clone(), handle.clone(), image_cache.clone(), id);
}
Err(e) => {
log::warn!("[qbz-slint] myqbz_cover upload failed: {e}");
crate::toast::error_weak(&weak, "Failed to upload cover");
crate::toast::error_weak(&weak, qbz_i18n::t("Failed to upload cover"));
}
}
});
@@ -203,12 +203,12 @@ pub fn remove(
match result {
Ok(()) => {
crate::toast::success_weak(&weak, "Cover removed");
crate::toast::success_weak(&weak, qbz_i18n::t("Cover removed"));
reload(weak.clone(), handle.clone(), image_cache.clone(), id);
}
Err(e) => {
log::warn!("[qbz-slint] myqbz_cover remove failed: {e}");
crate::toast::error_weak(&weak, "Failed to remove cover");
crate::toast::error_weak(&weak, qbz_i18n::t("Failed to remove cover"));
}
}
});
+9 -13
View File
@@ -184,11 +184,11 @@ fn kind_str(kind: CollectionKind) -> &'static str {
/// Eyebrow label (Tauri `kindLabel`): mixtapes.label / collections.artistLabel
/// / collections.label, uppercased to match the grid card eyebrow.
fn kind_label(kind: CollectionKind) -> &'static str {
fn kind_label(kind: CollectionKind) -> String {
match kind {
CollectionKind::Mixtape => "MIXTAPE",
CollectionKind::ArtistCollection => "ARTIST",
CollectionKind::Collection => "COLLECTION",
CollectionKind::Mixtape => qbz_i18n::t("MIXTAPE"),
CollectionKind::ArtistCollection => qbz_i18n::t("ARTIST"),
CollectionKind::Collection => qbz_i18n::t("COLLECTION"),
}
}
@@ -217,21 +217,17 @@ pub fn item_type_str(t: ItemType) -> &'static str {
/// `mixtapes.albumCount` ICU plural — always "album(s)" regardless of
/// item_type (1:1 with the PSD / the grid card meta).
fn album_count_label(count: usize) -> String {
if count == 1 {
"1 album".to_string()
} else {
format!("{count} albums")
}
qbz_i18n::tf("{} album", "{} albums", count as i64, &[&count.to_string()])
}
/// Type-cell label, uppercase (spec 12 §6.3 col-3 `itemTypeLabel`). Release-type
/// overrides (album rows showing EP/Single/…) are a later slice — albums render
/// "ALBUM" here.
fn type_label(t: ItemType) -> &'static str {
fn type_label(t: ItemType) -> String {
match t {
ItemType::Album => "ALBUM",
ItemType::Track => "TRACK",
ItemType::Playlist => "PLAYLIST",
ItemType::Album => qbz_i18n::t("ALBUM"),
ItemType::Track => qbz_i18n::t("TRACK"),
ItemType::Playlist => qbz_i18n::t("PLAYLIST"),
}
}
+14 -11
View File
@@ -89,7 +89,7 @@ pub fn rename(
.await
.unwrap_or_else(|e| Err(format!("rename task panicked: {e}")));
finish(&weak, &handle, &image_cache, id, result, None, "Failed to rename");
finish(&weak, &handle, &image_cache, id, result, None, qbz_i18n::t("Failed to rename"));
});
}
@@ -120,7 +120,7 @@ pub fn set_description(
.await
.unwrap_or_else(|e| Err(format!("description task panicked: {e}")));
finish(&weak, &handle, &image_cache, id, result, None, "Failed to save description");
finish(&weak, &handle, &image_cache, id, result, None, qbz_i18n::t("Failed to save description"));
});
}
@@ -149,7 +149,7 @@ pub fn toggle_play_mode(
.await
.unwrap_or_else(|e| Err(format!("play-mode task panicked: {e}")));
finish(&weak, &handle, &image_cache, id, result, None, "Failed to change play mode");
finish(&weak, &handle, &image_cache, id, result, None, qbz_i18n::t("Failed to change play mode"));
});
}
@@ -172,7 +172,7 @@ pub fn convert_kind(
"mixtape" => CollectionKind::Collection,
"collection" => CollectionKind::Mixtape,
_ => {
crate::toast::error_weak(&weak, "Cannot convert this kind");
crate::toast::error_weak(&weak, qbz_i18n::t("Cannot convert this kind"));
return;
}
};
@@ -186,12 +186,12 @@ pub fn convert_kind(
match result {
Ok(()) => {
crate::toast::success_weak(&weak, "Converted");
crate::toast::success_weak(&weak, qbz_i18n::t("Converted"));
reload(&weak, &handle, &image_cache, id);
}
Err(_) => {
// The repo's only rejection here is the artist_collection guard.
crate::toast::error_weak(&weak, "Cannot convert this kind");
crate::toast::error_weak(&weak, qbz_i18n::t("Cannot convert this kind"));
}
}
});
@@ -234,7 +234,7 @@ pub fn delete(
}
Err(e) => {
log::warn!("[qbz-slint] myqbz_edit delete failed: {e}");
crate::toast::error(&w, "Failed to delete");
crate::toast::error(&w, qbz_i18n::t("Failed to delete"));
}
}
});
@@ -283,12 +283,15 @@ pub fn remove_selected(
let _ = weak.upgrade_in_event_loop(|w| {
crate::myqbz_detail::clear_selection(&w);
});
crate::toast::info_weak(&weak, format!("Removed {count}"));
crate::toast::info_weak(
&weak,
qbz_i18n::tf("Removed {} item", "Removed {} items", count as i64, &[&count.to_string()]),
);
reload(&weak, &handle, &image_cache, id);
}
Err(e) => {
log::warn!("[qbz-slint] myqbz_edit bulk-remove failed: {e}");
crate::toast::error_weak(&weak, "Failed to remove items");
crate::toast::error_weak(&weak, qbz_i18n::t("Failed to remove items"));
}
}
});
@@ -304,8 +307,8 @@ fn finish(
image_cache: &ImageCache,
id: String,
result: Result<(), String>,
success_toast: Option<&'static str>,
err_msg: &'static str,
success_toast: Option<String>,
err_msg: String,
) {
match result {
Ok(()) => {
+8 -5
View File
@@ -143,7 +143,7 @@ pub fn open(
handle.spawn(async move {
let Some(collection) = crate::myqbz_play::load_collection(&collection_id).await else {
close_with_error(&weak, "Couldn't load this collection");
close_with_error(&weak, qbz_i18n::t("Couldn't load this collection"));
return;
};
// Always InOrder for DJ-mix (force_shuffle = false): the sampler does its
@@ -156,7 +156,7 @@ pub fn open(
// Nothing playable — close with a hint (mirrors the resolve-empty
// toast on the play paths).
close(&w);
crate::toast::error(&w, "This collection resolved to 0 playable tracks");
crate::toast::error(&w, qbz_i18n::t("This collection resolved to 0 playable tracks"));
} else {
apply_options(&w, unique);
}
@@ -165,7 +165,7 @@ pub fn open(
}
/// Close the modal (UI thread hop, callable from any thread).
fn close_with_error(weak: &slint::Weak<AppWindow>, msg: &'static str) {
fn close_with_error(weak: &slint::Weak<AppWindow>, msg: String) {
let _ = weak.upgrade_in_event_loop(move |w| {
close(&w);
crate::toast::error(&w, msg);
@@ -207,7 +207,7 @@ pub fn shuffle(
handle.spawn(async move {
let Some(collection) = crate::myqbz_play::load_collection(&collection_id).await else {
close_with_error(&weak, "Couldn't load this collection");
close_with_error(&weak, qbz_i18n::t("Couldn't load this collection"));
return;
};
// Resolve in-order (await completes BEFORE the RNG is created).
@@ -236,7 +236,10 @@ pub fn shuffle(
// DJ-mix actualCount can be < requested (per-album cap) — surface it.
if actual > 0 && actual < requested {
crate::toast::info_weak(&weak, format!("Playing {actual} of {requested}"));
crate::toast::info_weak(
&weak,
qbz_i18n::t_args("Playing {} of {}", &[&actual.to_string(), &requested.to_string()]),
);
}
});
}
+15 -15
View File
@@ -252,7 +252,7 @@ pub(crate) async fn play_all_tracks(
tracks: Vec<QueueTrack>,
) {
if tracks.is_empty() {
crate::toast::error_weak(weak, "This collection resolved to 0 playable tracks");
crate::toast::error_weak(weak, qbz_i18n::t("This collection resolved to 0 playable tracks"));
return;
}
let first_id = tracks[0].id;
@@ -280,7 +280,7 @@ pub fn play_all(
) {
handle.spawn(async move {
let Some(collection) = load_collection(&collection_id).await else {
crate::toast::error_weak(&weak, "Couldn't load this collection");
crate::toast::error_weak(&weak, qbz_i18n::t("Couldn't load this collection"));
return;
};
let tracks = resolve_collection(&runtime, &collection, false).await;
@@ -304,7 +304,7 @@ pub fn shuffle(
) {
handle.clone().spawn(async move {
let Some(collection) = load_collection(&collection_id).await else {
crate::toast::error_weak(&weak, "Couldn't load this collection");
crate::toast::error_weak(&weak, qbz_i18n::t("Couldn't load this collection"));
return;
};
let tracks = resolve_collection(&runtime, &collection, true).await;
@@ -396,7 +396,7 @@ pub fn item_action(
};
handle.spawn(async move {
let Some(collection) = load_collection(&collection_id).await else {
crate::toast::error_weak(&weak, "Couldn't load this collection");
crate::toast::error_weak(&weak, qbz_i18n::t("Couldn't load this collection"));
return;
};
let Some(item) = collection
@@ -413,7 +413,7 @@ pub fn item_action(
let tracks = resolve_single_item(&runtime, &item).await;
if tracks.is_empty() {
crate::toast::error_weak(&weak, "This item resolved to 0 playable tracks");
crate::toast::error_weak(&weak, qbz_i18n::t("This item resolved to 0 playable tracks"));
return;
}
@@ -433,12 +433,12 @@ pub fn item_action(
runtime.core().add_track_next(track).await;
}
refresh_sidebar(false);
crate::toast::success_weak(&weak, "Playing next");
crate::toast::success_weak(&weak, qbz_i18n::t("Playing next"));
}
RowMode::AddToQueue => {
runtime.core().add_tracks(tracks).await;
refresh_sidebar(false);
crate::toast::success_weak(&weak, "Added to queue");
crate::toast::success_weak(&weak, qbz_i18n::t("Added to queue"));
}
}
});
@@ -474,7 +474,7 @@ pub fn bulk_enqueue(
Some(c) => c.clone(),
None => {
log::warn!("[qbz-slint] myqbz_play: no Qobuz client; cannot bulk-enqueue");
crate::toast::error_weak(&weak, "These items resolved to 0 playable tracks");
crate::toast::error_weak(&weak, qbz_i18n::t("These items resolved to 0 playable tracks"));
return;
}
}
@@ -506,7 +506,7 @@ pub fn bulk_enqueue(
}
if tracks.is_empty() {
crate::toast::error_weak(&weak, "These items resolved to 0 playable tracks");
crate::toast::error_weak(&weak, qbz_i18n::t("These items resolved to 0 playable tracks"));
return;
}
@@ -517,11 +517,11 @@ pub fn bulk_enqueue(
runtime.core().add_track_next(track).await;
}
refresh_sidebar(false);
crate::toast::success_weak(&weak, "Playing next");
crate::toast::success_weak(&weak, qbz_i18n::t("Playing next"));
} else {
runtime.core().add_tracks(tracks).await;
refresh_sidebar(false);
crate::toast::success_weak(&weak, "Added to queue");
crate::toast::success_weak(&weak, qbz_i18n::t("Added to queue"));
}
});
}
@@ -627,7 +627,7 @@ pub fn play_inline_track(
};
handle.spawn(async move {
let Some(collection) = load_collection(&collection_id).await else {
crate::toast::error_weak(&weak, "Couldn't load this collection");
crate::toast::error_weak(&weak, qbz_i18n::t("Couldn't load this collection"));
return;
};
let Some(item) = collection
@@ -644,7 +644,7 @@ pub fn play_inline_track(
let tracks = fetch_item_tracks(&runtime, &item).await;
let Some(track) = tracks.into_iter().find(|t| t.id == track_id) else {
crate::toast::error_weak(&weak, "This track is no longer available");
crate::toast::error_weak(&weak, qbz_i18n::t("This track is no longer available"));
return;
};
@@ -658,12 +658,12 @@ pub fn play_inline_track(
InlineTrackMode::PlayNext => {
runtime.core().add_track_next(track).await;
refresh_sidebar(false);
crate::toast::success_weak(&weak, "Playing next");
crate::toast::success_weak(&weak, qbz_i18n::t("Playing next"));
}
InlineTrackMode::PlayLater => {
runtime.core().add_tracks(vec![track]).await;
refresh_sidebar(false);
crate::toast::success_weak(&weak, "Added to queue");
crate::toast::success_weak(&weak, qbz_i18n::t("Added to queue"));
}
}
});
+2 -2
View File
@@ -208,8 +208,8 @@ pub fn reseed_weak(weak: &slint::Weak<AppWindow>) {
pub fn pick_icon(weak: slint::Weak<AppWindow>, handle: tokio::runtime::Handle) {
handle.spawn(async move {
let Some(file) = rfd::AsyncFileDialog::new()
.set_title("Choose a My QBZ icon")
.add_filter("Image", &["svg", "png", "jpg", "jpeg", "webp"])
.set_title(&qbz_i18n::t_args("Choose a {} icon", &[DEFAULT_LABEL]))
.add_filter(&qbz_i18n::t("Image"), &["svg", "png", "jpg", "jpeg", "webp"])
.pick_file()
.await
else {