Write a rudimentary report

This commit is contained in:
Savanni D'Gerinel 2025-02-24 22:18:42 -05:00
parent 704009b76c
commit e5b3c7e4e1
5 changed files with 84 additions and 28 deletions

View File

@ -1,22 +1,22 @@
key = "SaveSettings"
description = "This is a label on a button which will save the settings when clicked"
[variants.en]
locale = "en"
content = "Save Settings"
modified = "2025-02-22T23:44:18.874218939Z"
[variants.eo]
locale = "eo"
content = "Konservi Agordojn"
modified = "2025-02-24T19:32:11.246639077Z"
[variants.de]
locale = "de"
content = "Einstellungen Speichern"
modified = "2025-02-24T19:33:19.516005843Z"
[variants.es]
locale = "es"
content = "Guardar Configuraciones"
modified = "2025-02-24T19:33:23.861329923Z"
[variants.en]
locale = "en"
content = "Save Settings"
modified = "2025-02-22T23:44:18.874218939Z"
[variants.de]
locale = "de"
content = "Einstellungen Speichern"
modified = "2025-02-24T19:33:19.516005843Z"

View File

@ -1,22 +1,22 @@
key = "TimeDistance"
description = "A summary of a workout or many workouts that involve a time and a distance"
[variants.en]
locale = "en"
content = "{distance} of {activity} in {hours, plural, =1 {{hours} hour} other {{hours} hours}} and {minutes, plural, =1 {{minutes} minute} other {{minutes} minutes}}"
modified = "2025-02-24T14:09:17.361641899Z"
[variants.es]
locale = "es"
content = "{distance} de {activity} en {hours, plural, one {}=1 {{hours} hora} other {{hours} horas}} y {minutes, plural, one {}=1 {{minutes} minuto} other {{minutes} minutos}}"
modified = "2025-02-24T19:33:23.861604738Z"
[variants.eo]
locale = "eo"
content = "{distance} de {activity} en {hours, plural, =1 {{hours} horo} other {{hours} horoj}} {minutes, plural, =1 {{minutes} minuto} other {{minutes} minutoj}}"
modified = "2025-02-24T19:32:11.246943602Z"
[variants.en]
locale = "en"
content = "{distance} of {activity} in {hours, plural, =1 {{hours} hour} other {{hours} hours}} and {minutes, plural, =1 {{minutes} minute} other {{minutes} minutes}}"
modified = "2025-02-24T14:09:17.361641899Z"
[variants.de]
locale = "de"
content = "{distance} von {activity} in {hours, plural, one {}=1 {{hours} Stunde} other {{hours} Stunden}} und {minutes, plural, one {}=1 {{minutes} Minute} other {{minutes} Minuten}}"
modified = "2025-02-24T19:33:19.516210807Z"
[variants.es]
locale = "es"
content = "{distance} de {activity} en {hours, plural, one {}=1 {{hours} hora} other {{hours} horas}} y {minutes, plural, one {}=1 {{minutes} minuto} other {{minutes} minutos}}"
modified = "2025-02-24T19:33:23.861604738Z"

View File

@ -1,16 +1,16 @@
key = "Welcome"
description = "This is a welcome content that will be shown on first app opening, before configuration."
[variants.en]
locale = "en"
content = "Welcome to FitnessTrax, the privacy-centered fitness tracker"
modified = "2025-02-25T02:12:25.757240004Z"
[variants.eo]
locale = "eo"
content = "Bonvenon al FitnessTrax"
modified = "2025-02-24T19:32:11.246407627Z"
[variants.en]
locale = "en"
content = "Welcome to FitnessTrax"
modified = "2025-02-22T23:43:24.786544124Z"
[variants.es]
locale = "es"
content = "Bienvenido a FitnessTrax"

View File

@ -7,7 +7,11 @@ use std::{
use clap::{Parser, Subcommand};
use icu_locid::{langid, LanguageIdentifier};
use l10n_db::{self, js, read_file, xliff::{self, import_file}, Bundle, Editor, ReadError};
use l10n_db::{
self, js, read_file,
xliff::{self, import_file},
Bundle, Editor, ReadError,
};
use serde::Deserialize;
#[derive(Parser)]
@ -41,6 +45,7 @@ enum Commands {
#[arg(short, long)]
locale: Option<String>,
},
Report,
}
#[derive(Debug, Deserialize)]
@ -56,6 +61,44 @@ fn edit_key(bundle: &mut Bundle, key: String, locale: LanguageIdentifier, editor
bundle.save();
}
#[derive(Clone, Debug, Default)]
struct Report {
keys: Vec<String>,
source_deleted: Vec<String>,
out_of_date: Vec<String>,
}
fn generate_report(
bundle: &Bundle,
base_locale: &LanguageIdentifier,
locales: Vec<LanguageIdentifier>,
) -> Report {
let mut report: Report = Default::default();
let locales: Vec<LanguageIdentifier> =
locales.into_iter().filter(|a| a != base_locale).collect();
for (key, message) in bundle.message_iter() {
match message.variant(base_locale) {
Some(ref base_variant) => {
for locale in locales.iter() {
match message.variant(locale) {
Some(v) if v.modified() < base_variant.modified() => {
report.out_of_date.push(key.to_owned())
}
Some(_) => {}
None => report.out_of_date.push(key.to_owned()),
}
}
}
None => {
report.source_deleted.push(key.clone());
}
}
let base_variant = message.variant(base_locale).clone();
}
report
}
fn main() {
let editor = std::env::var("EDITOR").expect("Set EDITOR to the path to your favorite editor");
@ -83,14 +126,23 @@ fn main() {
bundle.save();
}
Some(Commands::Export { format, locale }) => {
let locale = locale.as_ref().map(|l| l.clone().parse::<LanguageIdentifier>().unwrap()).unwrap_or(langid!("en"));
let locale = locale
.as_ref()
.map(|l| l.clone().parse::<LanguageIdentifier>().unwrap())
.unwrap_or(langid!("en"));
match format.as_ref() {
"js" => js::export_file(&bundle, locale, &PathBuf::from("output.json")).unwrap(),
"xliff" => xliff::export_file(&bundle, locale, &PathBuf::from("output.xliff")).unwrap(),
"xliff" => {
xliff::export_file(&bundle, locale, &PathBuf::from("output.xliff")).unwrap()
}
_ => todo!(),
}
},
}
Some(Commands::Report) => {
let report = generate_report(&bundle, &config.base_locale, config.locales);
println!("{:?}", report);
}
None => {}
}
}

View File

@ -65,6 +65,10 @@ impl Variant {
self.content = content;
self.modified = Utc::now();
}
pub fn modified(&self) -> DateTime<Utc> {
self.modified
}
}
/*