i18n: register dynamic msgid literals via mark() and fix double-translation
Adds qbz_i18n::mark() (identity, extraction-only) and applies it at the definition sites of literals later translated through t(variable): release-type classifier, discover section labels, artist release-section titles + month names, label jump tabs, and audio settings dropdown tables. Fixes the discover_prefs double-t() (label_for now returns the marked literal, translated once at the consumer). cc
This commit is contained in:
6 files changed
+103
-74
No files matched your search
@@ -99,6 +99,13 @@ pub fn resolve_auto() -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// Marks a string literal for catalog extraction at its DEFINITION site without
|
||||
/// translating here. Pair with a later `t(value)` that does the lookup. The
|
||||
/// extractor scans `mark("...")`; runtime returns the literal unchanged.
|
||||
pub const fn mark(s: &'static str) -> &'static str {
|
||||
s
|
||||
}
|
||||
|
||||
/// Translate `msgid` (singular) in the current language.
|
||||
/// Falls back to the English `msgid` itself when untranslated.
|
||||
pub fn t(msgid: &str) -> String {
|
||||
@@ -185,6 +192,13 @@ mod tests {
|
||||
set_language("en");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mark_returns_literal_unchanged() {
|
||||
// `mark` is a no-op at runtime; it only exists for static extraction.
|
||||
assert_eq!(mark("Album"), "Album");
|
||||
assert_eq!(t(mark("Album")), t("Album"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_falls_back_to_msgid() {
|
||||
let _g = LOCK.lock().unwrap();
|
||||
|
||||
@@ -169,10 +169,12 @@ fn album_artist(album: &Album) -> (String, String) {
|
||||
/// release_type. Mirrors home.rs's Discover heuristic
|
||||
/// (<=3 = Single, <=6 = EP, else Album).
|
||||
pub fn classify_release_type(track_count: Option<u32>) -> &'static str {
|
||||
// Marked at the definition so the extractor sees the English literals; the
|
||||
// call sites (`album_map`/`home`) translate the marked value with `t(...)`.
|
||||
match track_count {
|
||||
Some(n) if n <= 3 => "Single",
|
||||
Some(n) if n <= 6 => "EP",
|
||||
_ => "Album",
|
||||
Some(n) if n <= 3 => qbz_i18n::mark("Single"),
|
||||
Some(n) if n <= 6 => qbz_i18n::mark("EP"),
|
||||
_ => qbz_i18n::mark("Album"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,18 +75,21 @@ pub struct ReleaseSection {
|
||||
|
||||
/// Official on-screen order of release buckets, with their display titles
|
||||
/// (webplayer-faithful). `release_type` keys come straight from the server.
|
||||
// Display titles are `mark`ed so the extractor registers the English literals;
|
||||
// they are translated once with `t(...)` at the consumer sites (the section
|
||||
// header, the jump-tab label, and `release_type_title`).
|
||||
const RELEASE_SECTION_ORDER: &[(&str, &str)] = &[
|
||||
("album", "Albums"),
|
||||
("epSingle", "EPs & Singles"),
|
||||
("ep", "EPs & Singles"),
|
||||
("single", "EPs & Singles"),
|
||||
("live", "Live"),
|
||||
("compilation", "Compilations"),
|
||||
("download", "Purchase Only"),
|
||||
("composer", "Composer"),
|
||||
("other", "Other"),
|
||||
("awardedRelease", "Critics' Picks"),
|
||||
("next", "Upcoming"),
|
||||
("album", qbz_i18n::mark("Albums")),
|
||||
("epSingle", qbz_i18n::mark("EPs & Singles")),
|
||||
("ep", qbz_i18n::mark("EPs & Singles")),
|
||||
("single", qbz_i18n::mark("EPs & Singles")),
|
||||
("live", qbz_i18n::mark("Live")),
|
||||
("compilation", qbz_i18n::mark("Compilations")),
|
||||
("download", qbz_i18n::mark("Purchase Only")),
|
||||
("composer", qbz_i18n::mark("Composer")),
|
||||
("other", qbz_i18n::mark("Other")),
|
||||
("awardedRelease", qbz_i18n::mark("Critics' Picks")),
|
||||
("next", qbz_i18n::mark("Upcoming")),
|
||||
];
|
||||
|
||||
/// Display title for a release_type (the dedicated discography page header).
|
||||
@@ -1624,20 +1627,22 @@ pub fn apply_mb_relationships(window: &AppWindow, data: MbRelationshipsRowData)
|
||||
/// formatMbDate_v2 output when the locale is en-US.
|
||||
fn format_mb_date_short(date: &str) -> String {
|
||||
let parts: Vec<&str> = date.split('-').collect();
|
||||
// Month names are `mark`ed so the extractor registers the English literals;
|
||||
// they are translated once with `t(name)` at the format arms below.
|
||||
let month = |m: &str| -> Option<&'static str> {
|
||||
Some(match m {
|
||||
"01" => "January",
|
||||
"02" => "February",
|
||||
"03" => "March",
|
||||
"04" => "April",
|
||||
"05" => "May",
|
||||
"06" => "June",
|
||||
"07" => "July",
|
||||
"08" => "August",
|
||||
"09" => "September",
|
||||
"10" => "October",
|
||||
"11" => "November",
|
||||
"12" => "December",
|
||||
"01" => qbz_i18n::mark("January"),
|
||||
"02" => qbz_i18n::mark("February"),
|
||||
"03" => qbz_i18n::mark("March"),
|
||||
"04" => qbz_i18n::mark("April"),
|
||||
"05" => qbz_i18n::mark("May"),
|
||||
"06" => qbz_i18n::mark("June"),
|
||||
"07" => qbz_i18n::mark("July"),
|
||||
"08" => qbz_i18n::mark("August"),
|
||||
"09" => qbz_i18n::mark("September"),
|
||||
"10" => qbz_i18n::mark("October"),
|
||||
"11" => qbz_i18n::mark("November"),
|
||||
"12" => qbz_i18n::mark("December"),
|
||||
_ => return None,
|
||||
})
|
||||
};
|
||||
|
||||
@@ -112,30 +112,32 @@ pub fn render_kind(id: DiscoverySectionId) -> &'static str {
|
||||
/// title). When gettext lands this swaps to an MO lookup with NO `.slint` change.
|
||||
/// The keys are kept verbatim (with their real, mixed `home.*` / `discover.*` /
|
||||
/// `discovery.*` namespaces) so the lookup ports 1:1 when the pipeline arrives.
|
||||
pub fn label_for(id: DiscoverySectionId) -> String {
|
||||
pub fn label_for(id: DiscoverySectionId) -> &'static str {
|
||||
use DiscoverySectionId::*;
|
||||
let en: &str = match id {
|
||||
NewReleases => "New Releases", // home.newReleases
|
||||
PressAwards => "Press Accolades", // home.pressAwards
|
||||
QobuzPlaylists => "Qobuz Playlists", // home.qobuzPlaylists
|
||||
RecentlyPlayedAlbums => "Recently Played", // home.recentlyPlayed
|
||||
ContinueListening => "Continue Listening", // home.continueListening
|
||||
IdealDiscography => "Ideal Discography", // discover.idealDiscography
|
||||
MostStreamed => "Most Streamed", // home.mostStreamed
|
||||
ReleaseWatch => "Release Watch", // home.releaseWatch
|
||||
EditorPicks => "Albums of the Week", // home.editorPicks
|
||||
Qobuzissimes => "Qobuzissimes", // home.qobuzissimes
|
||||
TopArtists => "Your Top Artists", // home.yourTopArtists
|
||||
FavoriteAlbums => "Favorite Albums", // home.favoriteAlbums
|
||||
QobuzMixes => "Qobuz Mixes", // home.qobuzMixes
|
||||
RadioStations => "Radio Stations", // home.radioStations
|
||||
SimilarAlbums => "More From Your Library", // discovery.similarAlbums
|
||||
RediscoverLibrary => "Rediscover Your Library", // discovery.rediscoverLibrary
|
||||
EssentialsByGenre => "Essentials by Genre", // discovery.essentialsByGenre
|
||||
ArtistsToFollow => "Artists to Follow", // discovery.artistsToFollow
|
||||
ArtistSpotlight => "Artist Spotlight", // discovery.artistSpotlight
|
||||
};
|
||||
qbz_i18n::t(en)
|
||||
// Returns the `mark`ed English literal so the extractor registers the
|
||||
// msgid here; the single `t(...)` lookup happens at the consumer
|
||||
// (`push_config_rows`). This translates each label exactly once.
|
||||
match id {
|
||||
NewReleases => qbz_i18n::mark("New Releases"), // home.newReleases
|
||||
PressAwards => qbz_i18n::mark("Press Accolades"), // home.pressAwards
|
||||
QobuzPlaylists => qbz_i18n::mark("Qobuz Playlists"), // home.qobuzPlaylists
|
||||
RecentlyPlayedAlbums => qbz_i18n::mark("Recently Played"), // home.recentlyPlayed
|
||||
ContinueListening => qbz_i18n::mark("Continue Listening"), // home.continueListening
|
||||
IdealDiscography => qbz_i18n::mark("Ideal Discography"), // discover.idealDiscography
|
||||
MostStreamed => qbz_i18n::mark("Most Streamed"), // home.mostStreamed
|
||||
ReleaseWatch => qbz_i18n::mark("Release Watch"), // home.releaseWatch
|
||||
EditorPicks => qbz_i18n::mark("Albums of the Week"), // home.editorPicks
|
||||
Qobuzissimes => qbz_i18n::mark("Qobuzissimes"), // home.qobuzissimes
|
||||
TopArtists => qbz_i18n::mark("Your Top Artists"), // home.yourTopArtists
|
||||
FavoriteAlbums => qbz_i18n::mark("Favorite Albums"), // home.favoriteAlbums
|
||||
QobuzMixes => qbz_i18n::mark("Qobuz Mixes"), // home.qobuzMixes
|
||||
RadioStations => qbz_i18n::mark("Radio Stations"), // home.radioStations
|
||||
SimilarAlbums => qbz_i18n::mark("More From Your Library"), // discovery.similarAlbums
|
||||
RediscoverLibrary => qbz_i18n::mark("Rediscover Your Library"), // discovery.rediscoverLibrary
|
||||
EssentialsByGenre => qbz_i18n::mark("Essentials by Genre"), // discovery.essentialsByGenre
|
||||
ArtistsToFollow => qbz_i18n::mark("Artists to Follow"), // discovery.artistsToFollow
|
||||
ArtistSpotlight => qbz_i18n::mark("Artist Spotlight"), // discovery.artistSpotlight
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -203,7 +205,7 @@ pub fn push_config_rows(window: &AppWindow, prefs: &DiscoverPrefs, tab: Discover
|
||||
.iter()
|
||||
.map(|p| ConfigRow {
|
||||
id: SharedString::from(p.id.as_str()),
|
||||
label: SharedString::from(label_for(p.id)),
|
||||
label: SharedString::from(qbz_i18n::t(label_for(p.id))),
|
||||
enabled: p.enabled,
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -911,11 +911,13 @@ fn build_label_jump_tabs(payload: &LabelPagePayload) -> Vec<JumpNavTab> {
|
||||
*cursor += SECTION_SPACER + CAROUSEL;
|
||||
}
|
||||
};
|
||||
push_carousel(&mut tabs, "releases", "Releases", !payload.releases.is_empty(), &mut cursor);
|
||||
push_carousel(&mut tabs, "critics", "Critics' Picks", !payload.critics.is_empty(), &mut cursor);
|
||||
push_carousel(&mut tabs, "playlists", "Playlists", !payload.playlists.is_empty(), &mut cursor);
|
||||
push_carousel(&mut tabs, "artists", "Artists", !payload.artists.is_empty(), &mut cursor);
|
||||
push_carousel(&mut tabs, "labels", "More Labels", !payload.more_labels.is_empty(), &mut cursor);
|
||||
// Labels are `mark`ed so the extractor registers the English literals; the
|
||||
// closure translates them once with `t(label)`.
|
||||
push_carousel(&mut tabs, "releases", qbz_i18n::mark("Releases"), !payload.releases.is_empty(), &mut cursor);
|
||||
push_carousel(&mut tabs, "critics", qbz_i18n::mark("Critics' Picks"), !payload.critics.is_empty(), &mut cursor);
|
||||
push_carousel(&mut tabs, "playlists", qbz_i18n::mark("Playlists"), !payload.playlists.is_empty(), &mut cursor);
|
||||
push_carousel(&mut tabs, "artists", qbz_i18n::mark("Artists"), !payload.artists.is_empty(), &mut cursor);
|
||||
push_carousel(&mut tabs, "labels", qbz_i18n::mark("More Labels"), !payload.more_labels.is_empty(), &mut cursor);
|
||||
tabs
|
||||
}
|
||||
|
||||
|
||||
@@ -32,31 +32,33 @@ use crate::{AppWindow, NowPlayingState, SettingsState};
|
||||
|
||||
/// Maximum-sample-rate dropdown options. Index 0 is "No limit" (`None`).
|
||||
/// Backs `device_max_sample_rate`.
|
||||
// Labels in these tables are `mark`ed so the extractor registers the English
|
||||
// literals; they are translated once with `t(l)` where the snapshot is built.
|
||||
const MAX_SAMPLE_RATES: &[(&str, Option<u32>)] = &[
|
||||
("No limit", None),
|
||||
("44.1 kHz", Some(44_100)),
|
||||
("48 kHz", Some(48_000)),
|
||||
("88.2 kHz", Some(88_200)),
|
||||
("96 kHz", Some(96_000)),
|
||||
("176.4 kHz", Some(176_400)),
|
||||
("192 kHz", Some(192_000)),
|
||||
("352.8 kHz", Some(352_800)),
|
||||
("384 kHz", Some(384_000)),
|
||||
(qbz_i18n::mark("No limit"), None),
|
||||
(qbz_i18n::mark("44.1 kHz"), Some(44_100)),
|
||||
(qbz_i18n::mark("48 kHz"), Some(48_000)),
|
||||
(qbz_i18n::mark("88.2 kHz"), Some(88_200)),
|
||||
(qbz_i18n::mark("96 kHz"), Some(96_000)),
|
||||
(qbz_i18n::mark("176.4 kHz"), Some(176_400)),
|
||||
(qbz_i18n::mark("192 kHz"), Some(192_000)),
|
||||
(qbz_i18n::mark("352.8 kHz"), Some(352_800)),
|
||||
(qbz_i18n::mark("384 kHz"), Some(384_000)),
|
||||
];
|
||||
|
||||
/// ALSA-plugin dropdown options.
|
||||
const ALSA_PLUGINS: &[(&str, AlsaPlugin)] = &[
|
||||
("hw (Direct Hardware)", AlsaPlugin::Hw),
|
||||
("plughw (Auto-convert)", AlsaPlugin::PlugHw),
|
||||
("pcm (Most compatible)", AlsaPlugin::Pcm),
|
||||
(qbz_i18n::mark("hw (Direct Hardware)"), AlsaPlugin::Hw),
|
||||
(qbz_i18n::mark("plughw (Auto-convert)"), AlsaPlugin::PlugHw),
|
||||
(qbz_i18n::mark("pcm (Most compatible)"), AlsaPlugin::Pcm),
|
||||
];
|
||||
|
||||
/// "When quality retries fail" dropdown options. The value is the
|
||||
/// `quality_fallback_behavior` DB string.
|
||||
const RETRY_BEHAVIORS: &[(&str, &str)] = &[
|
||||
("Ask me", "ask"),
|
||||
("Always try lowest quality", "always_fallback"),
|
||||
("Always skip track", "always_skip"),
|
||||
(qbz_i18n::mark("Ask me"), "ask"),
|
||||
(qbz_i18n::mark("Always try lowest quality"), "always_fallback"),
|
||||
(qbz_i18n::mark("Always skip track"), "always_skip"),
|
||||
];
|
||||
|
||||
/// What a persisted audio change requires of the live `Player`.
|
||||
@@ -269,11 +271,13 @@ fn alsa_section(id: &str, is_default: bool, label: &str) -> AlsaSection {
|
||||
|
||||
/// The display label for an ALSA section header.
|
||||
fn alsa_section_label(section: AlsaSection) -> &'static str {
|
||||
// Marked at the definition so the extractor registers the English literals;
|
||||
// the single `t(...)` happens at the `group_alsa_devices` call site.
|
||||
match section {
|
||||
AlsaSection::Defaults => "Defaults",
|
||||
AlsaSection::BitPerfect => "Bit-perfect (Hardware / Digital)",
|
||||
AlsaSection::PluginHw => "Plugin Hardware",
|
||||
AlsaSection::Other => "Other Outputs",
|
||||
AlsaSection::Defaults => qbz_i18n::mark("Defaults"),
|
||||
AlsaSection::BitPerfect => qbz_i18n::mark("Bit-perfect (Hardware / Digital)"),
|
||||
AlsaSection::PluginHw => qbz_i18n::mark("Plugin Hardware"),
|
||||
AlsaSection::Other => qbz_i18n::mark("Other Outputs"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user