diff --git a/.github/workflows/console.yml b/.github/workflows/console.yml index 355aad9..fdc1269 100644 --- a/.github/workflows/console.yml +++ b/.github/workflows/console.yml @@ -127,6 +127,8 @@ jobs: - name: NVDEC streams run: sudo apt-get update && sudo apt-get install -y ffmpeg && scripts/nvdec-streams.sh - uses: actions/upload-artifact@v4 + # A storage quota must not red the build; the title is proven by the link above. + continue-on-error: true with: name: pf-nx-probe path: | @@ -134,6 +136,8 @@ jobs: dist/pf-nx-probe.elf dist/nvdec-* - uses: actions/upload-artifact@v4 + # A storage quota must not red the build; the title is proven by the link above. + continue-on-error: true with: name: punktfunk path: | diff --git a/Cargo.lock b/Cargo.lock index d3786de..928ee17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -593,7 +593,7 @@ dependencies = [ [[package]] name = "fec-rs" version = "0.1.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=12e4dfd1ba7855d0043a15c2939fc923a85771ef#12e4dfd1ba7855d0043a15c2939fc923a85771ef" +source = "git+https://git.unom.io/unom/punktfunk?rev=b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12#b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12" [[package]] name = "fiat-crypto" @@ -1107,11 +1107,12 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pf-client-core" -version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=12e4dfd1ba7855d0043a15c2939fc923a85771ef#12e4dfd1ba7855d0043a15c2939fc923a85771ef" +version = "0.46.0" +source = "git+https://git.unom.io/unom/punktfunk?rev=b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12#b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12" dependencies = [ "anyhow", "cfg_aliases", + "pf-l10n", "punktfunk-core", "rand", "serde", @@ -1122,8 +1123,8 @@ dependencies = [ [[package]] name = "pf-client-video" -version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=12e4dfd1ba7855d0043a15c2939fc923a85771ef#12e4dfd1ba7855d0043a15c2939fc923a85771ef" +version = "0.46.0" +source = "git+https://git.unom.io/unom/punktfunk?rev=b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12#b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12" dependencies = [ "anyhow", "ash", @@ -1136,11 +1137,12 @@ dependencies = [ [[package]] name = "pf-console-ui" -version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=12e4dfd1ba7855d0043a15c2939fc923a85771ef#12e4dfd1ba7855d0043a15c2939fc923a85771ef" +version = "0.46.0" +source = "git+https://git.unom.io/unom/punktfunk?rev=b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12#b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12" dependencies = [ "anyhow", "pf-client-core", + "pf-l10n", "punktfunk-core", "serde", "serde_json", @@ -1149,6 +1151,11 @@ dependencies = [ "tracing", ] +[[package]] +name = "pf-l10n" +version = "0.46.0" +source = "git+https://git.unom.io/unom/punktfunk?rev=b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12#b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12" + [[package]] name = "pf-nx" version = "1.0.0" @@ -1171,6 +1178,7 @@ dependencies = [ "opus", "pf-client-core", "pf-console-ui", + "pf-l10n", "punktfunk-core", "rustls", "serde", @@ -1324,8 +1332,8 @@ dependencies = [ [[package]] name = "punktfunk-core" -version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=12e4dfd1ba7855d0043a15c2939fc923a85771ef#12e4dfd1ba7855d0043a15c2939fc923a85771ef" +version = "0.46.0" +source = "git+https://git.unom.io/unom/punktfunk?rev=b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12#b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12" dependencies = [ "aes-gcm", "aws-lc-rs", @@ -1336,11 +1344,13 @@ dependencies = [ "if-addrs", "libc", "opus", + "pf-l10n", "quinn", "quinn-udp", "rcgen", "reed-solomon-simd", "rustls", + "rustls-webpki", "serde", "sha2 0.11.1", "socket2", @@ -1360,8 +1370,8 @@ checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea" [[package]] name = "pyrowave-sys" -version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=12e4dfd1ba7855d0043a15c2939fc923a85771ef#12e4dfd1ba7855d0043a15c2939fc923a85771ef" +version = "0.46.0" +source = "git+https://git.unom.io/unom/punktfunk?rev=b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12#b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12" dependencies = [ "bindgen 0.73.2", "cmake", diff --git a/Cargo.toml b/Cargo.toml index f0b29d0..dafb18a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,12 +55,14 @@ ash = { version = "0.38", default-features = false, features = ["debug", "std"] skia-safe = { version = "0.153", features = ["textlayout"] } # One REV for all shared crates: a tag and a rev build two copies whose types don't unify. # At least the merge of monorepo #2180, which carries the Horizon cfgs this client builds on. -punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "12e4dfd1ba7855d0043a15c2939fc923a85771ef", features = ["quic"] } -pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "12e4dfd1ba7855d0043a15c2939fc923a85771ef", default-features = false } -pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "12e4dfd1ba7855d0043a15c2939fc923a85771ef", default-features = false } +punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", features = ["quic", "l10n"] } +pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", default-features = false } +pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", default-features = false } +# The parts this crate reads itself. The host's sentences come worded from the core. +pf-l10n = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", default-features = false, features = ["client", "console", "host"] } # No `pyrowave` here: pf-nx-vk's own feature turns the lane on (plan D14), so a default build # compiles none of the wavelet decoder for the console. -pf-client-video = { git = "https://git.unom.io/unom/punktfunk", rev = "12e4dfd1ba7855d0043a15c2939fc923a85771ef", default-features = false } +pf-client-video = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", default-features = false } [workspace.lints.rust] unsafe_op_in_unsafe_fn = "deny" diff --git a/crates/pf-nx-app/Cargo.toml b/crates/pf-nx-app/Cargo.toml index de28d89..fb1086e 100644 --- a/crates/pf-nx-app/Cargo.toml +++ b/crates/pf-nx-app/Cargo.toml @@ -18,6 +18,7 @@ tracing-appender = "0.2" punktfunk-core.workspace = true pf-client-core.workspace = true pf-console-ui.workspace = true +pf-l10n.workspace = true skia-safe.workspace = true # Library and art fetch over pinned TLS. No ureq backend feature: the provider is named in code. # `~3.4`: the connector uses ureq's `unversioned` transport API, which 3.5 changed. @@ -32,5 +33,9 @@ miniz_oxide = "0.8" serde_json = "1" miniz_oxide = "0.8" +[dev-dependencies] +# `en-XA`, the pseudo-language the tests word in to find text that does not come from pf-l10n. +pf-l10n = { workspace = true, features = ["pseudo"] } + [lints] workspace = true diff --git a/crates/pf-nx-app/src/core/errors.rs b/crates/pf-nx-app/src/core/errors.rs index 7e91160..a07de91 100644 --- a/crates/pf-nx-app/src/core/errors.rs +++ b/crates/pf-nx-app/src/core/errors.rs @@ -1,78 +1,29 @@ //! User-facing sentences for `punktfunk-core`'s error and rejection types. //! -//! Ported from `pf-client-core::trust`'s `connect_reject_message`/`pair_error_message` — -//! the same wording every other punktfunk client shows — rather than depending on that -//! crate (see `session`'s module docs for why this client can't). -//! -//! Without this, failures render as Debug strings (e.g. "connect: Rejected(Busy)"). -use punktfunk_core::reject::RejectReason; - +//! A host's refusal is worded by `pf-client-core`; the rest are this client's own, from +//! `pf-l10n`. Without this, failures render as Debug strings (e.g. "connect: Rejected(Busy)"). +use pf_client_core::trust::connect_reject_message; +use pf_l10n::{client, console}; use punktfunk_core::PunktfunkError; -/// Why the host turned this connection away. -fn reject_message(reason: RejectReason) -> String { - match reason { - RejectReason::Denied => "The host declined this device's request.".into(), - RejectReason::ApprovalTimeout => { - "Nobody approved the request in time — approve this device, then try again.".into() - } - RejectReason::Superseded => { - "A newer request from this device replaced this one — approve the latest request.".into() - } - RejectReason::IdentityRequired => { - "The host requires pairing — pair this device (PIN or request access) first.".into() - } - RejectReason::PairingNotArmed => { - "Pairing isn't armed on the host — arm it on the host's Pairing page, then try again.".into() - } - RejectReason::PairingBoundToOtherDevice => { - "The host's pairing window is armed for a different device — arm it for this one.".into() - } - RejectReason::PairingRateLimited => { - "Too many pairing attempts — wait a couple of seconds and try again.".into() - } - RejectReason::WireVersionMismatch => { - "Client and host versions don't match — update both to the same release.".into() - } - RejectReason::Busy => "The host is busy with another session.".into(), - RejectReason::SetupFailed => { - "The host accepted the connection but couldn't start the stream — see host's logs.".into() - } - RejectReason::AccessExpired => { - "Your access to this host has expired — ask the host's owner to grant it again.".into() - } - RejectReason::HostPower => { - "The host is going to sleep or shutting down — wake it when you want to play again.".into() - } - RejectReason::LaunchNotPermitted => { - "This device isn't permitted to launch games on the host — connect without picking a game, \ - or ask the host's owner to allow launching." - .into() - } - RejectReason::ProfileUnknown => "That profile is gone from this host. Pick another one.".into(), - RejectReason::NoSeat => "All seats are taken.".into(), - RejectReason::SeatOccupied => "Someone is already playing as that profile.".into(), - RejectReason::SeatUnavailable => "That profile can't play on this host right now.".into(), - } -} - /// Why connect/probe failed (distinguishes rejection from transport trouble). fn connect_message(err: &PunktfunkError) -> String { match err { - PunktfunkError::Rejected(reason, _) => reject_message(*reason), - PunktfunkError::Timeout => "The host didn't answer. Is it running and reachable?".into(), + PunktfunkError::Rejected(reason, _) => connect_reject_message(*reason), + PunktfunkError::Timeout => client::error_host_timeout().into(), PunktfunkError::Io(e) => { - format!("Couldn't reach the host ({e}) — the console and the host must be on the same network.") + tracing::warn!(error = %e, "host unreachable"); + client::error_host_unreachable().into() } - PunktfunkError::Closed => "The host closed the connection.".into(), - other => format!("Connection failed: {other}"), + PunktfunkError::Closed => console::console_error_host_closed().into(), + other => console::console_error_connect_failed_detail(other), } } /// Why PIN pairing failed (Crypto = wrong PIN, not network problem). pub fn pair_message(err: &PunktfunkError) -> String { match err { - PunktfunkError::Crypto => "Wrong PIN — check the PIN on the host's Pairing page and try again.".into(), + PunktfunkError::Crypto => client::pair_wrong_pin().into(), other => connect_message(other), } } @@ -80,9 +31,7 @@ pub fn pair_message(err: &PunktfunkError) -> String { /// Why a request for access failed. It has no PIN, so Crypto is a host that didn't match its advert. pub fn access_message(err: &PunktfunkError) -> String { match err { - PunktfunkError::Crypto => { - "The host didn't present the identity it advertised. Pair with its PIN instead.".into() - } + PunktfunkError::Crypto => client::pair_identity_mismatch().into(), other => connect_message(other), } } @@ -92,3 +41,31 @@ pub fn friendly(err: &anyhow::Error) -> String { err.downcast_ref::() .map_or_else(|| format!("{err:#}"), connect_message) } + +#[cfg(test)] +mod tests { + use super::*; + use punktfunk_core::reject::RejectReason; + + /// Every sentence a failure shows comes from `pf-l10n`: in the pseudo-language each reads + /// bracketed, and a literal would not. + #[test] + fn every_failure_reads_the_language() { + let errors = [ + PunktfunkError::Rejected(RejectReason::Busy, String::new()), + PunktfunkError::Timeout, + PunktfunkError::Io(std::io::ErrorKind::NotFound.into()), + PunktfunkError::Closed, + PunktfunkError::Crypto, + PunktfunkError::BadPacket, + ]; + pf_l10n::with_language("en-XA", || { + for e in &errors { + for said in [pair_message(e), access_message(e)] { + assert!(said.starts_with('['), "{e:?}: {said}"); + } + } + }); + assert!(!pair_message(&PunktfunkError::Timeout).starts_with('[')); + } +} diff --git a/crates/pf-nx-app/src/platform/mod.rs b/crates/pf-nx-app/src/platform/mod.rs index 0912386..d3a8460 100644 --- a/crates/pf-nx-app/src/platform/mod.rs +++ b/crates/pf-nx-app/src/platform/mod.rs @@ -45,6 +45,8 @@ pub struct DeviceInfo { pub ui: String, /// Launched as an applet (from the album), with a fraction of the title's memory (plan D13). pub applet_mode: bool, + /// The system's UI language as BCP-47 tags, most preferred first. Empty reads as English. + pub languages: Vec, } /// Refresh rate of the scan-out, in millihertz (60 000, 59 940). diff --git a/crates/pf-nx-app/src/runtime/menu.rs b/crates/pf-nx-app/src/runtime/menu.rs index 9ba14d6..8954fcd 100644 --- a/crates/pf-nx-app/src/runtime/menu.rs +++ b/crates/pf-nx-app/src/runtime/menu.rs @@ -55,7 +55,10 @@ pub(super) fn run(app: &mut App, notice: Option) -> Result { gpu_cache_bytes: pf_console_ui::DEFAULT_GPU_CACHE_BYTES, screen: None, profiles: false, + // No profile picker, so a locked profile is dialled as it stands. + prompts_unlock: false, spatial: false, + languages: app.device.languages.clone(), }; let scripted = app.test_run.as_ref().and_then(|run| { let host = run.host.as_deref()?; @@ -166,7 +169,9 @@ pub(super) fn run(app: &mut App, notice: Option) -> Result { } Err(e) => { tracing::warn!("console: launch refused: {e:#}"); - handles.console.set_notice(format!("Couldn't start the stream — {e}")); + handles + .console + .set_notice(pf_l10n::client::dial_stream_start_failed().to_string()); } } } @@ -244,7 +249,7 @@ fn pad_label(batch: &[PadSample]) -> Option<&'static str> { PadKind::JoyConLeft => "Joy-Con (L)", PadKind::JoyConRight => "Joy-Con (R)", PadKind::SwitchPro => "Pro Controller", - PadKind::Other => "Controller", + PadKind::Other => pf_l10n::console::console_pad_fallback_name(), }) } @@ -265,12 +270,14 @@ fn legend_pref(pref: GamepadPref) -> GamepadPref { fn pad_infos(batch: &[PadSample], stored: GamepadType) -> impl Iterator + '_ { batch.iter().map(move |s| PadInfo { - name: pad_label(std::slice::from_ref(s)).unwrap_or("Controller").into(), + name: pad_label(std::slice::from_ref(s)) + .unwrap_or_else(pf_l10n::console::console_pad_fallback_name) + .into(), key: format!("slot{}", s.slot), pref: shown_kind(stored, std::slice::from_ref(s)).to_core(), steam_virtual: false, battery: None, - detail: format!("Player {}", s.slot + 1), + detail: pf_l10n::console::console_pad_player(s.slot + 1), forwarded: true, rumble: true, }) diff --git a/crates/pf-nx-app/src/runtime/mod.rs b/crates/pf-nx-app/src/runtime/mod.rs index c7dccac..0054023 100644 --- a/crates/pf-nx-app/src/runtime/mod.rs +++ b/crates/pf-nx-app/src/runtime/mod.rs @@ -103,6 +103,7 @@ pub fn run(platform: Platform) -> ! { // Without a log there is nothing to diagnose a failure from; the title still runs. let flush = crate::logger::init_subscriber(&crate::services::paths::logs_dir(), log).ok(); install_panic_hook(); + let language = pf_l10n::set_languages(&device.languages); tracing::info!( "punktfunk-switch {} on {} ({} firmware {}), gpu {}, ui {}{}", crate::core::build_id(), @@ -113,6 +114,7 @@ pub fn run(platform: Platform) -> ! { device.ui, if device.applet_mode { ", applet mode" } else { "" }, ); + tracing::info!("language {language} for the system's {:?}", device.languages); punktfunk_core::client::set_client_label(&client_label(&device)); crate::core::caps::install(video.caps()); // ureq's agents resolve their provider from the process default and panic without one. @@ -157,13 +159,15 @@ pub fn run(platform: Platform) -> ! { lifecycle.exit() } -/// What the first menu says when the title runs as an applet (plan D13). -const APPLET_MODE_NOTICE: &str = - "Opened from the Album, punktfunk has little memory and may close — hold R while starting a game to open it with full memory."; +/// What the first menu says when the title runs as an applet (plan D13). Holding `R` at +/// launch starts it with full memory. +fn applet_mode_notice() -> String { + pf_l10n::console::console_switch_applet_mode("R") +} /// The menu and the stream in turn, until one of them quits. fn alternate(app: &mut App) -> Option { - let mut notice = app.device.applet_mode.then(|| APPLET_MODE_NOTICE.to_string()); + let mut notice = app.device.applet_mode.then(applet_mode_notice); loop { let outcome = match menu::run(app, notice.take()) { Ok(outcome) => outcome, diff --git a/crates/pf-nx-app/src/runtime/stream.rs b/crates/pf-nx-app/src/runtime/stream.rs index 25bfc25..d3a67e2 100644 --- a/crates/pf-nx-app/src/runtime/stream.rs +++ b/crates/pf-nx-app/src/runtime/stream.rs @@ -253,7 +253,7 @@ pub(super) fn run(app: &mut App, launch: ConnectOutcome) -> StreamOutcome { tracing::info!("link lost — redial {redials} of {RECONNECTS}"); match redial(app, &target, &settings) { Some(c) => connected = c, - None => return StreamOutcome::ReturnToMenu(Some("The connection was lost.".into())), + None => return StreamOutcome::ReturnToMenu(Some(pf_l10n::client::ended_lost().into())), } } Next::Redial => { @@ -427,16 +427,12 @@ fn stream( if let Some(core) = hud.refresh(connected, decoder) { tracing::info!("stats: {} | {core}{}", perf.take_window(), app.clocks_suffix()); } - hud.local = vec![format!( - "present: {} frames, {} missed{}", - perf.frames, - perf.missed, - if connected.stats.holding.load(Ordering::Relaxed) { - " · holding for a keyframe" - } else { - "" - }, - )]; + let mut present = pf_l10n::console::console_overlay_present_frames(perf.frames, perf.missed); + if connected.stats.holding.load(Ordering::Relaxed) { + present.push_str(" · "); + present.push_str(pf_l10n::console::console_overlay_holding_keyframe()); + } + hud.local = vec![present]; let dt = last_frame.elapsed().as_secs_f64(); last_frame = Instant::now(); // Stats off and the dial out of sight draw nothing: the layer is skipped, not blended. @@ -452,7 +448,9 @@ fn stream( Ok(report) => perf.note(&report), Err(e) => { tracing::error!("present: {e:#}"); - break Next::End(StreamOutcome::ReturnToMenu(Some("The picture stopped.".into()))); + break Next::End(StreamOutcome::ReturnToMenu(Some( + pf_l10n::client::ended_unexpected().into(), + ))); } } diff --git a/crates/pf-nx-app/src/services/library.rs b/crates/pf-nx-app/src/services/library.rs index 3d6eb47..4c02801 100644 --- a/crates/pf-nx-app/src/services/library.rs +++ b/crates/pf-nx-app/src/services/library.rs @@ -52,15 +52,16 @@ pub enum LibraryError { impl std::fmt::Display for LibraryError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use pf_l10n::console as m; match self { - Self::NotPaired => f.write_str("Not paired — pair with the host first."), - Self::PinMismatch => f.write_str("Host certificate changed — re-pair with a PIN."), - Self::Http(code) => write!(f, "Management API returned HTTP {code}."), - Self::Unreachable(_) => f.write_str("The host isn't answering."), - Self::Timeout(_) => f.write_str("The host is answering too slowly."), - Self::BadReply(_) => f.write_str("Couldn't read the host's reply."), - Self::Tls(_) => f.write_str("Couldn't secure the connection to the host."), - Self::Identity(_) => f.write_str("Couldn't load this device's pairing identity."), + Self::NotPaired => f.write_str(m::console_lib_not_paired()), + Self::PinMismatch => f.write_str(m::console_lib_pin_changed()), + Self::Http(code) => f.write_str(&m::console_lib_http(code)), + Self::Unreachable(_) => f.write_str(m::console_lib_unreachable()), + Self::Timeout(_) => f.write_str(m::console_lib_timeout()), + Self::BadReply(_) => f.write_str(m::console_lib_bad_reply()), + Self::Tls(_) => f.write_str(m::console_lib_tls()), + Self::Identity(_) => f.write_str(m::console_lib_identity()), } } } @@ -422,6 +423,26 @@ impl rustls::client::danger::ServerCertVerifier for PinVerify { mod tests { use super::*; + /// The sentence for each failure comes from `pf-l10n`, not a literal. + #[test] + fn every_failure_reads_the_language() { + let all = [ + LibraryError::NotPaired, + LibraryError::PinMismatch, + LibraryError::Http(500), + LibraryError::Unreachable(String::new()), + LibraryError::Timeout(String::new()), + LibraryError::BadReply(String::new()), + LibraryError::Tls(String::new()), + LibraryError::Identity(String::new()), + ]; + pf_l10n::with_language("en-XA", || { + for e in &all { + assert!(e.to_string().starts_with('['), "{e:?}"); + } + }); + } + fn page(ids: &[&str], next: Option<&str>) -> Result { let items: Vec<_> = ids .iter() diff --git a/crates/pf-nx-app/src/services/logs.rs b/crates/pf-nx-app/src/services/logs.rs index 7ffa64b..3ba6e44 100644 --- a/crates/pf-nx-app/src/services/logs.rs +++ b/crates/pf-nx-app/src/services/logs.rs @@ -2,6 +2,7 @@ //! runs it on a worker. use crate::logger::MAX_LOG_BYTES; use crate::services::library::{self, LibraryError}; +use pf_l10n::{client, console}; use std::path::Path; /// Host endpoint and credentials resolved before starting the worker. @@ -17,7 +18,7 @@ pub struct HostTarget { /// Reads the newest `budget` bytes, dropping any partial leading line. fn log_tail(path: &Path, budget: u64) -> Result { use std::io::{Read as _, Seek as _, SeekFrom}; - let unreadable = |e: std::io::Error| format!("Couldn't read the log file: {e}"); + let unreadable = |e: std::io::Error| console::console_logs_read_failed(e); let mut f = std::fs::File::open(path).map_err(unreadable)?; let len = f.metadata().map_err(unreadable)?.len(); let truncated = len > budget; @@ -34,7 +35,7 @@ fn log_tail(path: &Path, budget: u64) -> Result { }; let text = String::from_utf8_lossy(&raw[from..]); if text.trim().is_empty() { - return Err("No logs to send yet.".into()); + return Err(console::console_logs_none().into()); } Ok(if truncated { format!("… older log lines truncated …\n{text}") @@ -61,7 +62,7 @@ fn post_log(target: &HostTarget) -> Result { } else { MAX_LOG_BYTES }; - let path = crate::logger::latest_log_file(&dir).ok_or("No logs to send yet.")?; + let path = crate::logger::latest_log_file(&dir).ok_or(console::console_logs_none())?; let log = log_tail(&path, budget)?; let previous = previous .filter(|p| *p != path) @@ -73,7 +74,7 @@ fn post_log(target: &HostTarget) -> Result { crate::core::build_id(), ); let agent = library::agent(&target.identity, Some(target.pin)) - .map_err(|e| format!("Couldn't send logs to {} — {e}", target.name))?; + .map_err(|e| console::console_logs_send_failed(&target.name, e))?; let url = format!( "{}/api/v1/client-logs", library::base_url(&target.addr, target.mgmt_port) @@ -83,14 +84,11 @@ fn post_log(target: &HostTarget) -> Result { .header("Content-Type", "text/plain; charset=utf-8") .send(body.as_bytes()) { - Ok(_) => Ok(format!( - "Logs sent to {} — download them from its web console's Logs page", - target.name - )), + Ok(_) => Ok(client::hostcard_logs_sent_body(&target.name)), Err(e) => Err(match library::classify(e) { - LibraryError::Http(413) => "Log file too large to send (1 MB limit).".into(), - LibraryError::NotPaired => format!("{} refused the logs — pair with it again.", target.name), - other => format!("{}: {other}", target.name), + LibraryError::Http(413) => console::console_logs_too_large().into(), + LibraryError::NotPaired => console::console_logs_refused(&target.name), + other => console::console_logs_failed_why(&target.name, other), }), } } diff --git a/crates/pf-nx-app/src/session/connect.rs b/crates/pf-nx-app/src/session/connect.rs index d4974b7..80375b1 100644 --- a/crates/pf-nx-app/src/session/connect.rs +++ b/crates/pf-nx-app/src/session/connect.rs @@ -322,13 +322,14 @@ impl Connected { /// The sentence for the menu's notice when the session ended on its own. pub fn end_message(&self) -> String { + use pf_l10n::{client, console}; use punktfunk_core::client::PunktfunkEndReason as R; match self.end_reason() { - R::GameExited => "The game exited.", - R::HostEnded => "The host ended the session.", - R::HostError => "The host closed the session with an error.", - R::Lost => "The connection was lost.", - R::None | R::Local => "The host closed the connection.", + R::GameExited => console::console_ended_game_exited(), + R::HostEnded => console::console_ended_host_ended(), + R::HostError => client::ended_host_error(), + R::Lost => client::ended_lost(), + R::None | R::Local => client::ended_closed(), } .to_string() } diff --git a/crates/pf-nx-app/src/ui/service.rs b/crates/pf-nx-app/src/ui/service.rs index f5453e4..20030b9 100644 --- a/crates/pf-nx-app/src/ui/service.rs +++ b/crates/pf-nx-app/src/ui/service.rs @@ -413,7 +413,7 @@ impl Service { }, ); self.handles.console.set_licenses(vec![pf_console_ui::LicenseSection { - heading: "Third-party software".into(), + heading: pf_l10n::client::about_third_party_heading().into(), text, }]); } @@ -567,7 +567,7 @@ impl Service { self.handles.library.set_phase( &req, LibraryPhase::Error { - title: "Couldn't load the library".into(), + title: pf_l10n::client::lib_load_failed().into(), body: e.to_string(), can_retry, }, @@ -950,7 +950,7 @@ impl Service { .map(|i| state.known_hosts[i].mac.clone()) .unwrap_or_default(); if macs.is_empty() { - self.notice(format!("{} has no wake address on record", row.name)); + self.notice(pf_l10n::console::console_dial_no_wake_address(&row.name)); // Nothing to send: end the card the shell opened. self.handles.console.set_wake(Some(WakeStatus { req, @@ -980,11 +980,11 @@ impl Service { move || match power::invoke(&addr, mgmt, &identity, pin, &action_id, budget::REQUEST) { Ok(()) => { tracing::info!("console: {host_name} accepted {action_id}"); - console.set_notice(format!("{host_name}: {label} — on its way")); + console.set_notice(pf_l10n::client::hostcard_action_sent_body(&host_name, &label)); } Err(e) => { - tracing::warn!("console: {host_name} refused {action_id}: {e}"); - console.set_notice(format!("{label} failed — {e}")); + tracing::warn!("console: {host_name} refused {action_id}: {e:?}"); + console.set_notice(pf_l10n::client::hostcard_action_failed(&label, &e)); } }, ) @@ -1081,8 +1081,8 @@ fn same_host(h: &KnownHost, d: &DiscoveredHost) -> bool { /// worse than naming the two it does understand. fn power_rows(rights: PowerRights) -> Vec { [ - (ExitAction::Sleep, "Sleep", false), - (ExitAction::Shutdown, "Shut down", true), + (ExitAction::Sleep, pf_l10n::host::host_power_sleep(), false), + (ExitAction::Shutdown, pf_l10n::host::host_power_shutdown(), true), ] .into_iter() .filter_map(|(action, label, danger)| { diff --git a/crates/pf-nx-host/src/lib.rs b/crates/pf-nx-host/src/lib.rs index 4955a57..824e250 100644 --- a/crates/pf-nx-host/src/lib.rs +++ b/crates/pf-nx-host/src/lib.rs @@ -348,6 +348,7 @@ pub fn platform(opts: &Options) -> Result { gpu, ui, applet_mode: false, + languages: Vec::new(), }, }) } diff --git a/crates/pf-nx-platform/src/console/mod.rs b/crates/pf-nx-platform/src/console/mod.rs index a3fdc03..17292af 100644 --- a/crates/pf-nx-platform/src/console/mod.rs +++ b/crates/pf-nx-platform/src/console/mod.rs @@ -12,7 +12,7 @@ use std::sync::{Arc, OnceLock}; use anyhow::{Context, Result}; use pf_nx_app::platform::{DeviceInfo, Display, OperationMode, Platform, Storage, VideoDecoders}; -use pf_nx_sys::{applet, nvk, setsys, socket, vi}; +use pf_nx_sys::{applet, nvk, set, setsys, socket, vi}; use pf_nx_vk::{GpuDevice, Presenter, Target, VideoSlot}; /// Identity, settings, logs and bundles; the NRO itself lives here too (plan D18). @@ -137,6 +137,7 @@ pub fn platform(kind: DisplayKind) -> Result { applet::applet_type(), applet::AppletType::Application | applet::AppletType::SystemApplication ), + languages: set::system_languages(), }; Ok(Platform { display, diff --git a/crates/pf-nx-sys/src/lib.rs b/crates/pf-nx-sys/src/lib.rs index 78da52b..92240e1 100644 --- a/crates/pf-nx-sys/src/lib.rs +++ b/crates/pf-nx-sys/src/lib.rs @@ -27,6 +27,7 @@ pub mod nvk; pub mod random; #[cfg(target_os = "horizon")] pub mod rt; +pub mod set; pub mod setsys; pub mod socket; pub mod swkbd; diff --git a/crates/pf-nx-sys/src/set.rs b/crates/pf-nx-sys/src/set.rs new file mode 100644 index 0000000..bfc3ea1 --- /dev/null +++ b/crates/pf-nx-sys/src/set.rs @@ -0,0 +1,65 @@ +//! The system's language. Externs from `services/set.h`, libnx 4.12.0. This is the `set` service +//! any title may open, not `set:sys` (see [`crate::setsys`]); libnx counts the opens. + +/// A `LanguageCode` as a BCP-47 tag: up to eight ASCII bytes, NUL-padded, packed little-endian +/// into a `u64` (`en-US`, `es-419`, `zh-Hans`). `None` for an empty or non-tag value. +pub fn language_tag(code: u64) -> Option { + let bytes = code.to_le_bytes(); + let len = bytes.iter().position(|&b| b == 0).unwrap_or(bytes.len()); + let tag = &bytes[..len]; + let valid = !tag.is_empty() && tag.iter().all(|b| b.is_ascii_alphanumeric() || *b == b'-'); + valid.then(|| tag.iter().map(|&b| char::from(b)).collect()) +} + +#[cfg(target_os = "horizon")] +mod ffi { + extern "C" { + pub fn setInitialize() -> u32; + pub fn setExit(); + pub fn setGetSystemLanguage(language_code: *mut u64) -> u32; + } +} + +/// The system's UI language as a list of BCP-47 tags, most preferred first. The console has one; +/// the list is empty where the service does not answer. +#[cfg(target_os = "horizon")] +pub fn system_languages() -> Vec { + // SAFETY: no arguments; balanced by setExit. + if unsafe { ffi::setInitialize() } != 0 { + return Vec::new(); + } + let mut code = 0u64; + // SAFETY: set is open; `code` is a valid out-pointer. + let rc = unsafe { ffi::setGetSystemLanguage(&mut code) }; + // SAFETY: balances the setInitialize above. + unsafe { ffi::setExit() }; + if rc != 0 { + return Vec::new(); + } + language_tag(code).into_iter().collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + fn pack(tag: &str) -> u64 { + let mut bytes = [0u8; 8]; + bytes[..tag.len()].copy_from_slice(tag.as_bytes()); + u64::from_le_bytes(bytes) + } + + #[test] + fn a_language_code_unpacks_to_its_tag() { + assert_eq!(language_tag(pack("en-US")).as_deref(), Some("en-US")); + assert_eq!(language_tag(pack("es-419")).as_deref(), Some("es-419")); + assert_eq!(language_tag(pack("zh-Hans")).as_deref(), Some("zh-Hans")); + assert_eq!(language_tag(pack("de")).as_deref(), Some("de")); + } + + #[test] + fn a_code_that_is_not_a_tag_is_none() { + assert_eq!(language_tag(0), None); + assert_eq!(language_tag(u64::MAX), None); + } +} diff --git a/docs/pins.md b/docs/pins.md index 7d97222..4719798 100644 --- a/docs/pins.md +++ b/docs/pins.md @@ -5,7 +5,7 @@ | Pin | Value | What it fixes | Moves when | | --- | --- | --- | --- | | Rust nightly | `nightly-2026-10-04` (rustc 1.101.0, `db8f076d2`) | `-Z build-std` for the custom target; the legs were made against it | a std change is needed; re-run the probe | -| punktfunk | `12e4dfd1b` | `punktfunk-core`, `pf-client-core`, `pf-console-ui`, `pf-client-video`, one rev for all | the shared crates change; one bump, all four | +| punktfunk | `b58dc3cfe` | `punktfunk-core`, `pf-client-core`, `pf-console-ui`, `pf-client-video`, `pf-l10n`, one rev for all | the shared crates change; one bump, all five | | devkitA64 | `r30-1` (GCC 16.1.0, newlib 4.6.0) | the C compiler, newlib, libgcc's `pic` objects | devkitPro ships a new one: `-Syu` in the image fails until this moves | | libnx | `4.12.0-1` | crt0, sockets, threads, the services | with devkitA64 | | switch-tools | `1.13.1-1` | `elf2nro`, `nacptool`, `nxlink` | with devkitA64 | diff --git a/scripts/pins.env b/scripts/pins.env index bc4b8e8..919cac9 100644 --- a/scripts/pins.env +++ b/scripts/pins.env @@ -2,7 +2,7 @@ # The Rust toolchain (rust-toolchain.toml carries the same value). RUST_NIGHTLY=nightly-2026-10-04 # The shared crates (Cargo.toml carries the same rev). -PUNKTFUNK_REV=12e4dfd1ba7855d0043a15c2939fc923a85771ef +PUNKTFUNK_REV=b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12 # devkitPro packages the image checks after -Syu (docker/Dockerfile carries the same values). DEVKITA64=r30-1 LIBNX=4.12.0-1