summaryrefslogtreecommitdiff
path: root/locale/tools
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-16 18:00:28 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-16 18:00:35 +0200
commit499f4994a6a8507dcca20ed820c851be9a2343c1 (patch)
tree9100c6c924e116e811d94d7188353f87819d02d3 /locale/tools
parent709fd5ddaaec290165e85b48b237cb82563b9e87 (diff)
downloadhurrycurry-499f4994a6a8507dcca20ed820c851be9a2343c1.tar
hurrycurry-499f4994a6a8507dcca20ed820c851be9a2343c1.tar.bz2
hurrycurry-499f4994a6a8507dcca20ed820c851be9a2343c1.tar.zst
fix all clippy things
Diffstat (limited to 'locale/tools')
-rw-r--r--locale/tools/src/main.rs76
1 files changed, 38 insertions, 38 deletions
diff --git a/locale/tools/src/main.rs b/locale/tools/src/main.rs
index 9b63a73e..4fe3c12c 100644
--- a/locale/tools/src/main.rs
+++ b/locale/tools/src/main.rs
@@ -3,6 +3,7 @@ use anyhow::{anyhow, Context, Result};
use clap::Parser;
use std::{
collections::BTreeMap,
+ fmt::Write as W2,
fs::{read_to_string, File},
io::Write,
path::{Path, PathBuf},
@@ -33,7 +34,7 @@ enum Args {
},
}
-static NATIVE_LANGUAGE_NAMES: &[(&'static str, &'static str)] = &[
+static NATIVE_LANGUAGE_NAMES: &[(&str, &str)] = &[
("en", "English"),
("de", "Deutsch"),
("fr", "Français"),
@@ -64,6 +65,7 @@ fn main() -> Result<()> {
if let Some(fallback) = fallback {
let f = load_ini(&fallback)?;
for (k, v) in f {
+ #[allow(clippy::map_entry)]
if !ini.contains_key(&k) {
eprintln!("fallback: key {k:?} is missing");
ini.insert(k, v);
@@ -88,19 +90,21 @@ msgstr ""
{}"#,
input.file_stem().unwrap().to_string_lossy(),
ini.into_iter()
- .map(|(mut key, value)| {
+ .fold(String::new(), |mut a, (mut key, value)| {
if let Some(id_map) = &id_map {
if let Some(new_id) = id_map.get(&key) {
key = new_id.to_owned()
}
}
- format!(
+ writeln!(
+ a,
"msgid {}\nmsgstr {}\n\n",
serde_json::to_string(&key).unwrap(),
serde_json::to_string(&value).unwrap(),
)
+ .unwrap();
+ a
})
- .collect::<String>()
)
.as_bytes(),
)?;
@@ -134,21 +138,21 @@ msgstr ""
}
File::create(output)?.write_all(
- format!(
- "id,{}\n{}",
- langs.join(","),
- tr_tr
- .into_iter()
- .map(|(k, v)| format!(
- "{k},{}\n",
+ tr_tr
+ .into_iter()
+ .fold(format!("id,{}\n", langs.join(",")), |mut a, (k, v)| {
+ writeln!(
+ a,
+ "{k},{}",
v.values()
.map(|s| serde_json::to_string(s).unwrap())
.collect::<Vec<_>>()
.join(",")
- ))
- .collect::<String>()
- )
- .as_bytes(),
+ )
+ .unwrap();
+ a
+ })
+ .as_bytes(),
)?;
Ok(())
}
@@ -196,7 +200,7 @@ msgstr ""
line = rest;
msgstr = String::new();
mode = 2;
- } else if let Some(_) = line.strip_prefix("msgctxt ") {
+ } else if line.starts_with("msgctxt ") {
mode = 0;
eprintln!("warning: msgctxt not implemented (line {})", i + 1);
continue;
@@ -212,14 +216,13 @@ msgstr ""
}
File::create(output)?.write_all(
- format!(
- "[hurrycurry]\n{}",
- outmap
- .into_iter()
- .map(|(k, v)| format!("{k}={v}\n"))
- .collect::<String>()
- )
- .as_bytes(),
+ outmap
+ .into_iter()
+ .fold("[hurrycurry]\n".to_string(), |mut a, (k, v)| {
+ writeln!(a, "{k}={v}").unwrap();
+ a
+ })
+ .as_bytes(),
)?;
Ok(())
@@ -248,10 +251,8 @@ msgstr ""
continue;
}
if let Some(rest) = line.strip_prefix("msgid ") {
- if !msgid.is_empty() {
- if !output_flip.contains_key(&msgid) {
- output_flip.insert(msgid.replace("\n", "\\n"), format!("unknown{i}"));
- }
+ if !msgid.is_empty() && !output_flip.contains_key(&msgid) {
+ output_flip.insert(msgid.replace("\n", "\\n"), format!("unknown{i}"));
}
line = rest;
id = true;
@@ -273,14 +274,13 @@ msgstr ""
.collect::<BTreeMap<_, _>>();
File::create(output)?.write_all(
- format!(
- "[hurrycurry]\n{}",
- output_unflip
- .into_iter()
- .map(|(k, v)| format!("{k}={v}\n"))
- .collect::<String>()
- )
- .as_bytes(),
+ output_unflip
+ .into_iter()
+ .fold("[hurrycurry]\n".to_string(), |mut a, (k, v)| {
+ writeln!(a, "{k}={v}").unwrap();
+ a
+ })
+ .as_bytes(),
)?;
Ok(())
@@ -289,12 +289,12 @@ msgstr ""
}
fn load_ini(path: &Path) -> Result<BTreeMap<String, String>> {
- Ok(read_to_string(path)?
+ read_to_string(path)?
.lines()
.skip(1)
.map(|l| {
let (k, v) = l.split_once("=").ok_or(anyhow!("'=' missing"))?;
Ok::<_, anyhow::Error>((k.to_owned(), v.replace("%n", "\n")))
})
- .try_collect()?)
+ .try_collect()
}