Damage dealt and taken by type, mitigation, heals and shields on allies, gold and crowd control, as the source gives them, built once per recap and only drawn for the player unfolded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
253 lines
7.8 KiB
Rust
253 lines
7.8 KiB
Rust
//! French display helpers shared by the page and the table.
|
|
|
|
use arena_tracker_core::{ChampionState, Date, SyncProgress};
|
|
|
|
use crate::local_time::LocalTime;
|
|
|
|
/// Fixed decimals with a decimal comma: `1,96`.
|
|
pub fn decimal(value: f64, digits: usize) -> String {
|
|
format!("{value:.digits$}").replace('.', ",")
|
|
}
|
|
|
|
/// How many Matches are stored, with the singular and the empty case.
|
|
pub fn stored(count: usize) -> String {
|
|
match count {
|
|
0 => "Aucune Partie enregistrée".into(),
|
|
1 => "1 Partie enregistrée".into(),
|
|
n => format!("{n} Parties enregistrées"),
|
|
}
|
|
}
|
|
|
|
/// An integer in French format: groups of three digits separated by a narrow no-break space
|
|
/// (U+202F), as `toLocaleString('fr-FR')` writes it: `154 320`.
|
|
pub fn thousands(value: u64) -> String {
|
|
let digits = value.to_string();
|
|
let mut out = String::with_capacity(digits.len() + digits.len() / 3);
|
|
for (i, digit) in digits.chars().enumerate() {
|
|
if i > 0 && (digits.len() - i).is_multiple_of(3) {
|
|
out.push('\u{202f}');
|
|
}
|
|
out.push(digit);
|
|
}
|
|
out
|
|
}
|
|
|
|
/// A Placement as the sheet writes it: « 1ᵉʳ », « 2ᵉ », « 3ᵉ »…
|
|
pub fn ordinal(placement: u8) -> String {
|
|
match placement {
|
|
1 => "1ᵉʳ".into(),
|
|
n => format!("{n}ᵉ"),
|
|
}
|
|
}
|
|
|
|
/// An Attempt's rank, feminine: « 1ʳᵉ », « 2ᵉ »…
|
|
pub fn attempt_ordinal(attempt: usize) -> String {
|
|
match attempt {
|
|
1 => "1ʳᵉ".into(),
|
|
n => format!("{n}ᵉ"),
|
|
}
|
|
}
|
|
|
|
/// A day as the banner writes it: « 20 nov. », « 3 mai ».
|
|
pub fn short_date(date: Date) -> String {
|
|
const MONTHS: [&str; 12] = [
|
|
"janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.",
|
|
"déc.",
|
|
];
|
|
let month = MONTHS
|
|
.get(usize::from(date.month).wrapping_sub(1))
|
|
.copied()
|
|
.unwrap_or_default();
|
|
format!("{} {month}", date.day)
|
|
}
|
|
|
|
/// When a Match started, as its row and its recap write it: « 15 nov. 2026 · 18:29 ».
|
|
pub fn match_time(time: LocalTime) -> String {
|
|
format!(
|
|
"{} {} · {}:{:02}",
|
|
short_date(time.date),
|
|
time.date.year,
|
|
time.hour,
|
|
time.minute
|
|
)
|
|
}
|
|
|
|
/// A Match's length: « 31 min 14 s ».
|
|
pub fn duration(seconds: u32) -> String {
|
|
format!("{} min {:02} s", seconds / 60, seconds % 60)
|
|
}
|
|
|
|
/// A span of seconds, as the details write it: « 45 s », « 1 min 23 s ».
|
|
pub fn seconds(seconds: u64) -> String {
|
|
match seconds {
|
|
0..60 => format!("{seconds} s"),
|
|
_ => format!("{} min {:02} s", seconds / 60, seconds % 60),
|
|
}
|
|
}
|
|
|
|
pub fn state_label(state: Option<ChampionState>) -> &'static str {
|
|
match state {
|
|
Some(ChampionState::Completed) => "Validé",
|
|
Some(ChampionState::InProgress) => "En cours",
|
|
Some(ChampionState::NeverPlayed) => "Jamais joué",
|
|
None => "",
|
|
}
|
|
}
|
|
|
|
pub const CLIENT_ABSENT: &str =
|
|
"Client League of Legends non détecté : affichage des données enregistrées.";
|
|
const INTERNAL_ERROR: &str = "Mise à jour impossible : erreur interne.";
|
|
|
|
/// The discreet line under the Challenge tile.
|
|
pub fn official_note(official: u32) -> String {
|
|
format!("Progression officielle : {official}")
|
|
}
|
|
|
|
pub fn official_differs(app: usize, official: u32) -> String {
|
|
format!(
|
|
"La Progression officielle du jeu indique {official} champions validés, l'application en compte {app} : des Parties manquent peut-être."
|
|
)
|
|
}
|
|
|
|
/// The sync status line: what is running, else the last failure, else the stored count.
|
|
pub fn sync_line(
|
|
busy: bool,
|
|
progress: Option<SyncProgress>,
|
|
crashed: bool,
|
|
stored_count: Option<usize>,
|
|
) -> String {
|
|
match progress {
|
|
// A report with nothing to fetch is still the listing.
|
|
Some(p) if busy && p.to_fetch > 0 => {
|
|
format!("Import en cours : {} / {} Parties", p.fetched, p.to_fetch)
|
|
}
|
|
_ if busy => "Synchronisation en cours…".into(),
|
|
_ if crashed => INTERNAL_ERROR.into(),
|
|
_ => stored_count.map(stored).unwrap_or_default(),
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn decimals_use_a_comma() {
|
|
assert_eq!(decimal(1.96, 2), "1,96");
|
|
assert_eq!(decimal(3.0, 1), "3,0");
|
|
assert_eq!(decimal(2.0 / 3.0, 1), "0,7");
|
|
}
|
|
|
|
#[test]
|
|
fn thousands_are_grouped_with_a_narrow_no_break_space() {
|
|
assert_eq!(thousands(0), "0");
|
|
assert_eq!(thousands(999), "999");
|
|
assert_eq!(thousands(1_000), "1\u{202f}000");
|
|
assert_eq!(thousands(154_320), "154\u{202f}320");
|
|
assert_eq!(thousands(1_234_567), "1\u{202f}234\u{202f}567");
|
|
}
|
|
|
|
#[test]
|
|
fn placements_are_written_as_french_ordinals() {
|
|
assert_eq!(ordinal(1), "1ᵉʳ");
|
|
assert_eq!(ordinal(2), "2ᵉ");
|
|
assert_eq!(ordinal(8), "8ᵉ");
|
|
assert_eq!(attempt_ordinal(1), "1ʳᵉ");
|
|
assert_eq!(attempt_ordinal(3), "3ᵉ");
|
|
}
|
|
|
|
#[test]
|
|
fn short_dates_have_the_french_month_abbreviations() {
|
|
let date = |month, day| Date {
|
|
year: 2026,
|
|
month,
|
|
day,
|
|
};
|
|
assert_eq!(short_date(date(11, 20)), "20 nov.");
|
|
assert_eq!(short_date(date(2, 1)), "1 févr.");
|
|
assert_eq!(short_date(date(5, 3)), "3 mai");
|
|
assert_eq!(short_date(date(8, 31)), "31 août");
|
|
}
|
|
|
|
#[test]
|
|
fn match_times_and_lengths_are_written_in_french() {
|
|
let time = LocalTime {
|
|
date: Date {
|
|
year: 2026,
|
|
month: 11,
|
|
day: 5,
|
|
},
|
|
hour: 9,
|
|
minute: 4,
|
|
};
|
|
assert_eq!(match_time(time), "5 nov. 2026 · 9:04");
|
|
assert_eq!(duration(1874), "31 min 14 s");
|
|
assert_eq!(duration(60), "1 min 00 s");
|
|
}
|
|
|
|
#[test]
|
|
fn a_span_of_seconds_drops_the_minutes_under_one() {
|
|
assert_eq!(seconds(0), "0 s");
|
|
assert_eq!(seconds(45), "45 s");
|
|
assert_eq!(seconds(60), "1 min 00 s");
|
|
assert_eq!(seconds(83), "1 min 23 s");
|
|
}
|
|
|
|
#[test]
|
|
fn stored_matches_are_pluralised() {
|
|
assert_eq!(stored(0), "Aucune Partie enregistrée");
|
|
assert_eq!(stored(1), "1 Partie enregistrée");
|
|
assert_eq!(stored(42), "42 Parties enregistrées");
|
|
}
|
|
|
|
#[test]
|
|
fn states_have_a_french_label() {
|
|
assert_eq!(state_label(Some(ChampionState::Completed)), "Validé");
|
|
assert_eq!(state_label(Some(ChampionState::InProgress)), "En cours");
|
|
assert_eq!(state_label(Some(ChampionState::NeverPlayed)), "Jamais joué");
|
|
assert_eq!(state_label(None), "");
|
|
}
|
|
|
|
#[test]
|
|
fn official_progress_texts() {
|
|
assert_eq!(official_note(52), "Progression officielle : 52");
|
|
assert_eq!(
|
|
official_differs(50, 52),
|
|
"La Progression officielle du jeu indique 52 champions validés, l'application en compte 50 : des Parties manquent peut-être."
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn the_sync_line_follows_what_is_running() {
|
|
let progress = SyncProgress {
|
|
fetched: 3,
|
|
to_fetch: 10,
|
|
};
|
|
assert_eq!(
|
|
sync_line(true, Some(progress), false, Some(5)),
|
|
"Import en cours : 3 / 10 Parties"
|
|
);
|
|
assert_eq!(
|
|
sync_line(true, None, false, Some(5)),
|
|
"Synchronisation en cours…"
|
|
);
|
|
let nothing = SyncProgress {
|
|
fetched: 0,
|
|
to_fetch: 0,
|
|
};
|
|
assert_eq!(
|
|
sync_line(true, Some(nothing), false, Some(5)),
|
|
"Synchronisation en cours…"
|
|
);
|
|
assert_eq!(
|
|
sync_line(false, None, true, Some(5)),
|
|
"Mise à jour impossible : erreur interne."
|
|
);
|
|
assert_eq!(
|
|
sync_line(false, None, false, Some(1)),
|
|
"1 Partie enregistrée"
|
|
);
|
|
assert_eq!(sync_line(false, None, false, None), "");
|
|
}
|
|
}
|