feat(client_web): i18n
This commit is contained in:
parent
d3a20eb6b6
commit
4ecb222e55
11 changed files with 877 additions and 99 deletions
|
|
@ -1,23 +1,25 @@
|
|||
use leptos::prelude::*;
|
||||
use trictrac_store::{CheckerMove, Jan};
|
||||
|
||||
use crate::i18n::*;
|
||||
use crate::trictrac::types::{JanEntry, PlayerScore};
|
||||
|
||||
fn jan_label(jan: &Jan) -> &'static str {
|
||||
fn jan_label(jan: &Jan) -> String {
|
||||
let i18n = use_i18n();
|
||||
match jan {
|
||||
Jan::FilledQuarter => "Remplissage",
|
||||
Jan::TrueHitSmallJan => "Battage à vrai (petit jan)",
|
||||
Jan::TrueHitBigJan => "Battage à vrai (grand jan)",
|
||||
Jan::TrueHitOpponentCorner => "Battage coin adverse",
|
||||
Jan::FirstPlayerToExit => "Premier sorti",
|
||||
Jan::SixTables => "Six tables",
|
||||
Jan::TwoTables => "Deux tables",
|
||||
Jan::Mezeas => "Mezeas",
|
||||
Jan::FalseHitSmallJan => "Battage à faux (petit jan)",
|
||||
Jan::FalseHitBigJan => "Battage à faux (grand jan)",
|
||||
Jan::ContreTwoTables => "Contre deux tables",
|
||||
Jan::ContreMezeas => "Contre mezeas",
|
||||
Jan::HelplessMan => "Dame impuissante",
|
||||
Jan::FilledQuarter => t_string!(i18n, jan_filled_quarter).to_owned(),
|
||||
Jan::TrueHitSmallJan => t_string!(i18n, jan_true_hit_small).to_owned(),
|
||||
Jan::TrueHitBigJan => t_string!(i18n, jan_true_hit_big).to_owned(),
|
||||
Jan::TrueHitOpponentCorner => t_string!(i18n, jan_true_hit_corner).to_owned(),
|
||||
Jan::FirstPlayerToExit => t_string!(i18n, jan_first_exit).to_owned(),
|
||||
Jan::SixTables => t_string!(i18n, jan_six_tables).to_owned(),
|
||||
Jan::TwoTables => t_string!(i18n, jan_two_tables).to_owned(),
|
||||
Jan::Mezeas => t_string!(i18n, jan_mezeas).to_owned(),
|
||||
Jan::FalseHitSmallJan => t_string!(i18n, jan_false_hit_small).to_owned(),
|
||||
Jan::FalseHitBigJan => t_string!(i18n, jan_false_hit_big).to_owned(),
|
||||
Jan::ContreTwoTables => t_string!(i18n, jan_contre_two).to_owned(),
|
||||
Jan::ContreMezeas => t_string!(i18n, jan_contre_mezeas).to_owned(),
|
||||
Jan::HelplessMan => t_string!(i18n, jan_helpless_man).to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -36,13 +38,18 @@ fn format_move_pair(m1: CheckerMove, m2: CheckerMove) -> String {
|
|||
}
|
||||
|
||||
fn jan_row(idx: usize, entry: JanEntry, expanded: RwSignal<Option<usize>>) -> impl IntoView {
|
||||
let i18n = use_i18n();
|
||||
let row_class = if entry.total >= 0 {
|
||||
"jan-row jan-expandable jan-positive"
|
||||
} else {
|
||||
"jan-row jan-expandable jan-negative"
|
||||
};
|
||||
let label = jan_label(&entry.jan);
|
||||
let double_tag = if entry.is_double { "double" } else { "simple" };
|
||||
let double_tag = if entry.is_double {
|
||||
t_string!(i18n, jan_double).to_owned()
|
||||
} else {
|
||||
t_string!(i18n, jan_simple).to_owned()
|
||||
};
|
||||
let ways_tag = format!("×{}", entry.ways);
|
||||
let pts_str = if entry.total >= 0 {
|
||||
format!("+{}", entry.total)
|
||||
|
|
@ -84,12 +91,10 @@ fn jan_row(idx: usize, entry: JanEntry, expanded: RwSignal<Option<usize>>) -> im
|
|||
}
|
||||
}
|
||||
|
||||
/// One player's score panel: name, progress bars (points & holes), bredouille indicator,
|
||||
/// and the list of jans scored by this player in the last roll.
|
||||
/// `jans` should already be filtered and sign-corrected for this player's perspective.
|
||||
#[component]
|
||||
pub fn PlayerScorePanel(score: PlayerScore, jans: Vec<JanEntry>, is_you: bool) -> impl IntoView {
|
||||
let label = if is_you { " (vous)" } else { "" };
|
||||
let i18n = use_i18n();
|
||||
|
||||
let points_pct = format!("{}%", (score.points as u32 * 100 / 12).min(100));
|
||||
let holes_pct = format!("{}%", (score.holes as u32 * 100 / 12).min(100));
|
||||
let points_val = format!("{}/12", score.points);
|
||||
|
|
@ -106,21 +111,24 @@ pub fn PlayerScorePanel(score: PlayerScore, jans: Vec<JanEntry>, is_you: bool) -
|
|||
view! {
|
||||
<div class="player-score-panel">
|
||||
<div class="player-score-header">
|
||||
<span class="player-name">{score.name}{label}</span>
|
||||
<span class="player-name">
|
||||
{score.name}
|
||||
{is_you.then(|| t!(i18n, you_suffix))}
|
||||
</span>
|
||||
</div>
|
||||
<div class="score-bars">
|
||||
<div class="score-bar-row">
|
||||
<span class="score-bar-label">"Points"</span>
|
||||
<span class="score-bar-label">{t!(i18n, points_label)}</span>
|
||||
<div class="score-bar">
|
||||
<div class="score-bar-fill score-bar-points" style=format!("width:{points_pct}")></div>
|
||||
</div>
|
||||
<span class="score-bar-value">{points_val}</span>
|
||||
{can_bredouille.then(|| view! {
|
||||
<span class="bredouille-badge" title="Peut faire bredouille">"B"</span>
|
||||
<span class="bredouille-badge" title=move || t_string!(i18n, bredouille_title).to_owned()>"B"</span>
|
||||
})}
|
||||
</div>
|
||||
<div class="score-bar-row">
|
||||
<span class="score-bar-label">"Trous"</span>
|
||||
<span class="score-bar-label">{t!(i18n, holes_label)}</span>
|
||||
<div class="score-bar">
|
||||
<div class="score-bar-fill score-bar-holes" style=format!("width:{holes_pct}")></div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue