added localization for month and weekday to calendar-widget
This commit is contained in:
parent
1d6a43486e
commit
e49a30104b
2 changed files with 60 additions and 3 deletions
|
|
@ -9,3 +9,24 @@ designers = Designers
|
|||
artists = Artists
|
||||
translators = Translators
|
||||
documenters = Documenters
|
||||
|
||||
# Calendar
|
||||
january = January { $year }
|
||||
february = February { $year }
|
||||
march = March { $year }
|
||||
april = April { $year }
|
||||
may = May { $year }
|
||||
june = June { $year }
|
||||
july = July { $year }
|
||||
august = August { $year }
|
||||
september = September { $year }
|
||||
october = October { $year }
|
||||
november = November { $year }
|
||||
december = December { $year }
|
||||
monday = Mon
|
||||
tuesday = Tue
|
||||
wednesday = Wed
|
||||
thursday = Thu
|
||||
friday = Fri
|
||||
saturday = Sat
|
||||
sunday = Sun
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ use std::cmp;
|
|||
use crate::iced_core::{Alignment, Length, Padding};
|
||||
use crate::widget::{Grid, button, column, grid, icon, row, text};
|
||||
use apply::Apply;
|
||||
use chrono::{Datelike, Days, Local, Months, NaiveDate, Weekday};
|
||||
use chrono::{Datelike, Days, Local, Month, Months, NaiveDate, Weekday};
|
||||
use crate::fl;
|
||||
|
||||
/// A widget that displays an interactive calendar.
|
||||
pub fn calendar<M>(
|
||||
|
|
@ -129,7 +130,42 @@ where
|
|||
icon.padding([0, 12]).on_press($on_press)
|
||||
}};
|
||||
}
|
||||
let date = text(this.model.visible.format("%B %Y").to_string()).size(18);
|
||||
macro_rules! translate_month {
|
||||
($month:expr, $year:expr) => {{
|
||||
match $month {
|
||||
chrono::Month::January => fl!("january", year=$year),
|
||||
chrono::Month::February => fl!("february", year=$year),
|
||||
chrono::Month::March => fl!("march", year=$year),
|
||||
chrono::Month::April => fl!("april", year=$year),
|
||||
chrono::Month::May => fl!("may", year=$year),
|
||||
chrono::Month::June => fl!("june", year=$year),
|
||||
chrono::Month::July => fl!("july", year=$year),
|
||||
chrono::Month::August => fl!("august", year=$year),
|
||||
chrono::Month::September => fl!("september", year=$year),
|
||||
chrono::Month::October => fl!("october", year=$year),
|
||||
chrono::Month::November => fl!("november", year=$year),
|
||||
chrono::Month::December => fl!("december", year=$year)
|
||||
}
|
||||
}}
|
||||
}
|
||||
macro_rules! translate_weekday {
|
||||
($weekday:expr) => {{
|
||||
match $weekday {
|
||||
Weekday::Mon => fl!("monday"),
|
||||
Weekday::Tue => fl!("tuesday"),
|
||||
Weekday::Wed => fl!("wednesday"),
|
||||
Weekday::Thu => fl!("thursday"),
|
||||
Weekday::Fri => fl!("friday"),
|
||||
Weekday::Sat => fl!("saturday"),
|
||||
Weekday::Sun => fl!("sunday")
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
let date = text(translate_month!(
|
||||
Month::try_from(this.model.visible.month() as u8)
|
||||
.expect("Previously valid month is suddenly invalid"),
|
||||
this.model.visible.year())).size(18);
|
||||
|
||||
let month_controls = row::with_capacity(2)
|
||||
.push(icon!("go-previous-symbolic", (this.on_prev)()))
|
||||
|
|
@ -142,7 +178,7 @@ where
|
|||
let mut first_day_of_week = this.first_day_of_week;
|
||||
for _ in 0..7 {
|
||||
calendar_grid = calendar_grid.push(
|
||||
text(first_day_of_week.to_string())
|
||||
text(translate_weekday!(first_day_of_week))
|
||||
.size(12)
|
||||
.width(Length::Fixed(36.0))
|
||||
.align_x(Alignment::Center),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue