diff --git a/rslib/src/i18n/scheduling.ftl b/rslib/src/i18n/scheduling.ftl index 2220368e3..482b2cdf9 100644 --- a/rslib/src/i18n/scheduling.ftl +++ b/rslib/src/i18n/scheduling.ftl @@ -11,29 +11,76 @@ answer-button-time-months = {$amount}mo answer-button-time-years = {$amount}y ## A span of time, such as the delay until a card is shown again, the -## amount of time taken to answer a card, and so on. +## amount of time taken to answer a card, and so on. It is used by itself, +## such as in the Interval column of the browse screen, +## and labels like "Total Time" in the card info screen. time-span-seconds = { $amount -> [one] {$amount} second *[other] {$amount} seconds } + time-span-minutes = { $amount -> [one] {$amount} minute *[other] {$amount} minutes } + time-span-hours = { $amount -> [one] {$amount} hour *[other] {$amount} hours } + time-span-days = { $amount -> [one] {$amount} day *[other] {$amount} days } + time-span-months = { $amount -> [one] {$amount} month *[other] {$amount} months } + time-span-years = { $amount -> [one] {$amount} year *[other] {$amount} years } + +## A span of time studying took place in, for example +## "(studied 30 cards) in 3 minutes". In English the text +## just adds "in" to the start of time-span-*, but other +## languages may need to use different words here instead +## of reusing the time-span-* text. +## See the 'studied-today' context for where this is used, +## and the Polish translation for an example of different +## wordings used here. + +in-time-span-seconds = in { time-span-seconds } +in-time-span-minutes = in { time-span-minutes } +in-time-span-hours = in { time-span-hours } +in-time-span-days = in { time-span-days } +in-time-span-months = in { time-span-months } +in-time-span-years = in { time-span-years } + +## + +cards = { $cards -> + [one] {$cards} card + *[other] {$cards} cards + } + +# Shown at the bottom of the deck list, and in the statistics screen. +# eg "Studied 3 cards in 13 seconds today (4.33s/card)." +# The { in-time-span-seconds } part should be pasted in from the English +# version unmodified. + +studied-today = + Studied { cards } + { $unit -> + [seconds] { in-time-span-seconds } + [minutes] { in-time-span-minutes } + [hours] { in-time-span-hours } + [days] { in-time-span-days } + [months] { in-time-span-months } + *[years] { in-time-span-years } + } today + ({$secs-per-card}s/card). diff --git a/rslib/src/sched/timespan.rs b/rslib/src/sched/timespan.rs index b70458c99..be278d9fb 100644 --- a/rslib/src/sched/timespan.rs +++ b/rslib/src/sched/timespan.rs @@ -28,6 +28,23 @@ pub fn time_span(seconds: f32, i18n: &I18n) -> String { .trn(&format!("time-span-{}", unit), args) } +// fixme: this doesn't belong here +#[allow(dead_code)] +fn studied_today(cards: usize, secs: f32, i18n: &I18n) -> String { + let span = Timespan::from_secs(secs).natural_span(); + let amount = span.as_unit(); + let unit = span.unit().as_str(); + let secs_per = if cards > 0 { + secs / (cards as f32) + } else { + 0.0 + }; + let args = tr_args!["amount" => amount, "unit" => unit, + "cards" => cards, "secs-per-card" => secs_per]; + i18n.get(StringsGroup::Scheduling) + .trn("studied-today", args) +} + const SECOND: f32 = 1.0; const MINUTE: f32 = 60.0 * SECOND; const HOUR: f32 = 60.0 * MINUTE; @@ -117,8 +134,8 @@ impl Timespan { #[cfg(test)] mod test { - use crate::i18n::I18n; - use crate::sched::timespan::{answer_button_time, MONTH}; + use crate::i18n::{I18n, StringsGroup}; + use crate::sched::timespan::{answer_button_time, studied_today, time_span, MONTH}; #[test] fn answer_buttons() { @@ -127,4 +144,22 @@ mod test { assert_eq!(answer_button_time(70.0, &i18n), "1m"); assert_eq!(answer_button_time(1.1 * MONTH, &i18n), "1.10mo"); } + + #[test] + fn time_spans() { + let i18n = I18n::new(&["zz"], ""); + assert_eq!(time_span(1.0, &i18n), "1 second"); + assert_eq!(time_span(30.0, &i18n), "30 seconds"); + assert_eq!(time_span(90.0, &i18n), "1.50 minutes"); + } + + #[test] + fn combo() { + // temporary test of fluent term handling + let i18n = I18n::new(&["zz"], ""); + assert_eq!( + &studied_today(3, 13.0, &i18n).replace("\n", " "), + "Studied 3 cards in 13 seconds today (4.33s/card)." + ); + } }