Add intl filter, update tempates to accept languages

master
Tait Hoyem 1 year ago
parent 12f102d011
commit 078aa4259a

@ -1,5 +1,12 @@
use rust_i18n::t;
use crate::languages::SupportedLanguage;
pub fn seconds_as_time(secs: &i32) -> ::askama::Result<String> {
let minutes = secs / 60;
let seconds = secs % 60;
Ok(format!("{}:{}", minutes, seconds))
}
pub fn intl(key: &str, lang: &SupportedLanguage) -> ::askama::Result<String> {
Ok(t!(key, locale=&format!("{}", lang)))
}

@ -4,13 +4,14 @@ use serde::{
};
use strum_macros::{
EnumIter,
AsRefStr,
EnumVariantNames,
EnumCount,
};
use derive_more::Display;
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Display, EnumIter, EnumCount, EnumVariantNames)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Display, EnumIter, EnumCount, EnumVariantNames, AsRefStr)]
pub enum SupportedLanguage {
#[serde(rename="en-ca")]
#[display(fmt="en-ca")]

@ -28,6 +28,12 @@ use sqlx::{Pool, Postgres};
use std::net::SocketAddr;
use std::sync::Arc;
macro_rules! intl {
($key:expr) => {
t!($key, locale=path.as_ref())
}
}
#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate<'a> {
@ -81,6 +87,7 @@ struct LeagueListTemplate {
#[derive(Template)]
#[template(path="partials/iihf_team_stats_table.html")]
struct IihfTeamStatsTableTemplate {
lang: SupportedLanguage,
iihf_stats: Vec<IihfStatsI64>,
}
@ -278,6 +285,7 @@ async fn games_for_division_html(
division,
iihf_team_stats_table: IihfTeamStatsTableTemplate {
iihf_stats,
lang,
},
games,
lang,

@ -6,7 +6,7 @@
<h1 id="first-heading">Divisions for the {{ league.name }}</h1>
<ul aria-labelledby="first-heading">
{% for division in divisions %}
<li><a href="/en/division/{{ division.id }}/">{{ division.name }}</a></li>
<li><a href="/{{ lang }}/division/{{ division.id }}/">{{ division.name }}</a></li>
{% endfor %}
</ul>
{% endblock %}

@ -1,7 +1,7 @@
<table>
<thead>
<tr>
<th>Team</th>
<th>{{ "game_plural"|intl(lang)|capitalize }}</th>
<th>Points</th>
<th>RW</th>
<th>RL</th>

Loading…
Cancel
Save