Remove remaining warnings
This commit is contained in:
parent
a07ecae04a
commit
254a2aefd7
@ -1,6 +1,4 @@
|
|||||||
use std::{
|
use std::{fmt, path::PathBuf};
|
||||||
fmt, io::{BufReader, Read, Write}, path::PathBuf, process::Command
|
|
||||||
};
|
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
@ -24,9 +22,9 @@ enum Commands {
|
|||||||
/// Edit, potentially creating, a key
|
/// Edit, potentially creating, a key
|
||||||
EditKey {
|
EditKey {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
name: String,
|
key: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
locale: String,
|
locale: Option<String>,
|
||||||
},
|
},
|
||||||
/// List al keys in the database
|
/// List al keys in the database
|
||||||
ListKeys,
|
ListKeys,
|
||||||
@ -41,6 +39,8 @@ enum Commands {
|
|||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
format: String,
|
format: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
|
file: String,
|
||||||
|
#[arg(short, long)]
|
||||||
locale: Option<String>,
|
locale: Option<String>,
|
||||||
},
|
},
|
||||||
Report,
|
Report,
|
||||||
@ -50,7 +50,6 @@ enum Commands {
|
|||||||
struct Config {
|
struct Config {
|
||||||
db_path: PathBuf,
|
db_path: PathBuf,
|
||||||
base_locale: LanguageIdentifier,
|
base_locale: LanguageIdentifier,
|
||||||
locales: Vec<LanguageIdentifier>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit_key(bundle: &mut Bundle, key: String, locale: LanguageIdentifier, editor: &str) {
|
fn edit_key(bundle: &mut Bundle, key: String, locale: LanguageIdentifier, editor: &str) {
|
||||||
@ -62,28 +61,26 @@ fn edit_key(bundle: &mut Bundle, key: String, locale: LanguageIdentifier, editor
|
|||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
struct Report {
|
struct Report {
|
||||||
keys: Vec<String>,
|
keys: Vec<String>,
|
||||||
source_deleted: Vec<String>,
|
// source_deleted: Vec<String>,
|
||||||
out_of_date: Vec<String>,
|
out_of_date: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Report {
|
impl fmt::Display for Report {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "Out of date messages\n")?;
|
writeln!(f, "{} messages in bundle", self.keys.len())?;
|
||||||
|
writeln!(f, "Out of date messages")?;
|
||||||
for key in self.out_of_date.iter() {
|
for key in self.out_of_date.iter() {
|
||||||
write!(f, "\t{}\n", key)?;
|
writeln!(f, "\t{}", key)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_report(
|
fn generate_report(bundle: &Bundle, base_locale: &LanguageIdentifier) -> Report {
|
||||||
bundle: &Bundle,
|
|
||||||
base_locale: &LanguageIdentifier,
|
|
||||||
locales: Vec<LanguageIdentifier>,
|
|
||||||
) -> Report {
|
|
||||||
let mut report: Report = Default::default();
|
let mut report: Report = Default::default();
|
||||||
for (key, message) in bundle.message_iter() {
|
for (key, message) in bundle.message_iter() {
|
||||||
if message.variants_out_of_date(base_locale).len() > 0 {
|
report.keys.push(key.to_owned());
|
||||||
|
if !message.variants_out_of_date(base_locale).is_empty() {
|
||||||
report.out_of_date.push(key.to_owned())
|
report.out_of_date.push(key.to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,9 +101,11 @@ fn main() {
|
|||||||
let mut bundle = Bundle::load_from_disk(PathBuf::from(&config.db_path));
|
let mut bundle = Bundle::load_from_disk(PathBuf::from(&config.db_path));
|
||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Some(Commands::EditKey { name, locale }) => {
|
Some(Commands::EditKey { key, locale }) => {
|
||||||
let identifier = locale.parse::<LanguageIdentifier>().unwrap();
|
let identifier = locale.as_ref()
|
||||||
edit_key(&mut bundle, name.to_owned(), identifier, &editor)
|
.map(|l| l.parse::<LanguageIdentifier>().unwrap())
|
||||||
|
.unwrap_or(config.base_locale);
|
||||||
|
edit_key(&mut bundle, key.to_owned(), identifier, &editor)
|
||||||
}
|
}
|
||||||
Some(Commands::ListKeys) => {
|
Some(Commands::ListKeys) => {
|
||||||
for (key, _) in bundle.message_iter() {
|
for (key, _) in bundle.message_iter() {
|
||||||
@ -117,22 +116,26 @@ fn main() {
|
|||||||
import_file(&mut bundle, &PathBuf::from(file)).unwrap();
|
import_file(&mut bundle, &PathBuf::from(file)).unwrap();
|
||||||
bundle.save();
|
bundle.save();
|
||||||
}
|
}
|
||||||
Some(Commands::Export { format, locale }) => {
|
Some(Commands::Export {
|
||||||
|
format,
|
||||||
|
file,
|
||||||
|
locale,
|
||||||
|
}) => {
|
||||||
let locale = locale
|
let locale = locale
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|l| l.clone().parse::<LanguageIdentifier>().unwrap())
|
.map(|l| l.clone().parse::<LanguageIdentifier>().unwrap())
|
||||||
.unwrap_or(langid!("en"));
|
.unwrap_or(langid!("en"));
|
||||||
|
|
||||||
match format.as_ref() {
|
match format.as_ref() {
|
||||||
"js" => js::export_file(&bundle, locale, &PathBuf::from("output.json")).unwrap(),
|
"js" => js::export_file(&bundle, locale, &PathBuf::from(file)).unwrap(),
|
||||||
"xliff" => {
|
"xliff" => {
|
||||||
xliff::export_file(&bundle, locale, &PathBuf::from("output.xliff")).unwrap()
|
xliff::export_file(&bundle, locale, &PathBuf::from(file)).unwrap()
|
||||||
}
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Commands::Report) => {
|
Some(Commands::Report) => {
|
||||||
let report = generate_report(&bundle, &config.base_locale, config.locales);
|
let report = generate_report(&bundle, &config.base_locale);
|
||||||
println!("{}", report);
|
println!("{}", report);
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -47,7 +47,7 @@ impl Bundle {
|
|||||||
|
|
||||||
fn save_file(path: &PathBuf, s: &[u8]) {
|
fn save_file(path: &PathBuf, s: &[u8]) {
|
||||||
let mut f = File::create(path).unwrap();
|
let mut f = File::create(path).unwrap();
|
||||||
f.write(s).unwrap();
|
let _ = f.write(s).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
use std::{io::{BufReader, Read, Write}, path::Path, process::Command};
|
use std::{io::Write, process::Command};
|
||||||
|
|
||||||
use icu_locid::{langid, LanguageIdentifier};
|
use icu_locid::{langid, LanguageIdentifier};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{read_fh, Message};
|
use crate::{read_fh, Message};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
struct EditorMessage {
|
struct EditorMessage {
|
||||||
description: String,
|
description: String,
|
||||||
@ -13,19 +12,7 @@ struct EditorMessage {
|
|||||||
content: String,
|
content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
pub struct Editor {}
|
||||||
impl EditorMessage {
|
|
||||||
fn from_variant(description: String, variant: &Variant) -> Self {
|
|
||||||
Self {
|
|
||||||
description,
|
|
||||||
content: variant.content().to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub struct Editor {
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Editor {
|
impl Editor {
|
||||||
pub fn edit(msg: &mut Message, locale: LanguageIdentifier, editor: &str) {
|
pub fn edit(msg: &mut Message, locale: LanguageIdentifier, editor: &str) {
|
||||||
@ -47,10 +34,10 @@ impl Editor {
|
|||||||
let file = file.reopen().unwrap();
|
let file = file.reopen().unwrap();
|
||||||
let content = read_fh(&file).unwrap();
|
let content = read_fh(&file).unwrap();
|
||||||
|
|
||||||
let new_variant: EditorMessage = toml::from_str(&String::from_utf8(content).unwrap()).unwrap();
|
let new_variant: EditorMessage =
|
||||||
|
toml::from_str(&String::from_utf8(content).unwrap()).unwrap();
|
||||||
|
|
||||||
variant.set_content(new_variant.content);
|
variant.set_content(new_variant.content);
|
||||||
msg.set_description(new_variant.description);
|
msg.set_description(new_variant.description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ pub fn export_fh(bundle: &Bundle, locale: LanguageIdentifier, fh: &mut File) ->
|
|||||||
}).collect::<Vec<(String, String)>>();
|
}).collect::<Vec<(String, String)>>();
|
||||||
|
|
||||||
let messages: BTreeMap<String, String> = messages.into_iter().collect();
|
let messages: BTreeMap<String, String> = messages.into_iter().collect();
|
||||||
fh.write(serde_json::to_string_pretty(&messages).unwrap().as_bytes()).unwrap();
|
let _ = fh.write(serde_json::to_string_pretty(&messages).unwrap().as_bytes()).unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,14 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, BufReader, Read, Write},
|
io::{BufReader, Read, Write},
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
use icu_locid::{langid, LanguageIdentifier};
|
use icu_locid::{langid, LanguageIdentifier};
|
||||||
use xml::{attribute::OwnedAttribute, reader, writer, EmitterConfig, EventReader, EventWriter};
|
use xml::{attribute::OwnedAttribute, reader, writer, EmitterConfig, EventReader, EventWriter};
|
||||||
|
|
||||||
use crate::{Bundle, Message, ReadError, WriteError};
|
use crate::{Bundle, Message, ReadError, WriteError};
|
||||||
|
|
||||||
struct PartialMessage {
|
|
||||||
variants: HashMap<LanguageIdentifier, PartialVariant>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PartialVariant {
|
|
||||||
content: Option<String>,
|
|
||||||
modified: Option<DateTime<Utc>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn export_file(
|
pub fn export_file(
|
||||||
bundle: &Bundle,
|
bundle: &Bundle,
|
||||||
locale: LanguageIdentifier,
|
locale: LanguageIdentifier,
|
||||||
@ -133,12 +122,12 @@ fn write_message<T>(
|
|||||||
.into(),
|
.into(),
|
||||||
writer::XmlEvent::start_element("notes").into(),
|
writer::XmlEvent::start_element("notes").into(),
|
||||||
writer::XmlEvent::start_element("note").into(),
|
writer::XmlEvent::start_element("note").into(),
|
||||||
writer::XmlEvent::characters(message.description()).into(),
|
writer::XmlEvent::characters(message.description()),
|
||||||
writer::XmlEvent::end_element().into(),
|
writer::XmlEvent::end_element().into(),
|
||||||
writer::XmlEvent::end_element().into(),
|
writer::XmlEvent::end_element().into(),
|
||||||
writer::XmlEvent::start_element("segment").into(),
|
writer::XmlEvent::start_element("segment").into(),
|
||||||
writer::XmlEvent::start_element("source").into(),
|
writer::XmlEvent::start_element("source").into(),
|
||||||
writer::XmlEvent::characters(message.variant(locale).unwrap().content()).into(),
|
writer::XmlEvent::characters(message.variant(locale).unwrap().content()),
|
||||||
writer::XmlEvent::end_element().into(),
|
writer::XmlEvent::end_element().into(),
|
||||||
writer::XmlEvent::end_element().into(),
|
writer::XmlEvent::end_element().into(),
|
||||||
writer::XmlEvent::end_element().into(),
|
writer::XmlEvent::end_element().into(),
|
||||||
|
Loading…
Reference in New Issue
Block a user