diff options
author | metamuffin <metamuffin@disroot.org> | 2024-10-14 22:48:17 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-10-14 22:48:17 +0200 |
commit | 188c76572d8606cefd394945bbce789d55797ec6 (patch) | |
tree | 79ec4a52a5e2e7d81045583ef6922f2b7b2fc3c5 | |
parent | 5e39e1a9fa973dcc95c630b45c1cef99c68bbb19 (diff) | |
download | hurrycurry-188c76572d8606cefd394945bbce789d55797ec6.tar hurrycurry-188c76572d8606cefd394945bbce789d55797ec6.tar.bz2 hurrycurry-188c76572d8606cefd394945bbce789d55797ec6.tar.zst |
merge book locales
-rw-r--r-- | client/makefile | 6 | ||||
-rw-r--r-- | locale/tools/src/main.rs | 43 | ||||
-rw-r--r-- | test-client/makefile | 4 |
3 files changed, 21 insertions, 32 deletions
diff --git a/client/makefile b/client/makefile index 2c13b6c4..ca482d53 100644 --- a/client/makefile +++ b/client/makefile @@ -27,7 +27,7 @@ clean: rm -f icons/adaptive-foreground.png icons/adaptive-background.png .godot/import-finished: $(LOCALES) - godot --headless --import project.godot + if not test -e $@; then godot --headless --import project.godot; fi touch $@ $(LT): $(shell find ../locale/tools -type f) @@ -37,9 +37,9 @@ po/locales.csv: $(LT) @mkdir -p po $(LT) export-godot-csv ../locale $@ -po/%.po: ../locale/%.ini $(LT) ../locale/en.ini +po/%.po: $(LT) ../locale/%.ini ../book/locale/%.ini ../locale/en.ini ../book/locale/en.ini @mkdir -p po - $(LT) export-po $< $@ --fallback ../locale/en.ini + $(LT) export-po $@ $(wordlist 2,99,$(^)) icons/adaptive-background.png: ffmpeg -f lavfi -i "color=color=#E28142,scale=432x432" -frames:v 1 -y $@ diff --git a/locale/tools/src/main.rs b/locale/tools/src/main.rs index 9b39705b..0173138c 100644 --- a/locale/tools/src/main.rs +++ b/locale/tools/src/main.rs @@ -21,10 +21,8 @@ enum Args { output: PathBuf, }, ExportJson { - #[arg(long)] - fallback: Option<PathBuf>, - input: PathBuf, output: PathBuf, + inputs: Vec<PathBuf>, }, ExportGodotCsv { input_dir: PathBuf, @@ -33,10 +31,8 @@ enum Args { ExportPo { #[arg(long)] remap_ids: Option<PathBuf>, - #[arg(long)] - fallback: Option<PathBuf>, - input: PathBuf, output: PathBuf, + inputs: Vec<PathBuf>, }, } @@ -62,22 +58,15 @@ static NATIVE_LANGUAGE_NAMES: &[(&str, &str)] = &[ ("ru", "русский"), ]; -fn export_load(input: &Path, fallback: Option<PathBuf>) -> Result<BTreeMap<String, String>> { - let mut ini = load_ini(&input)?; - if let Some(fallback) = fallback { - let mut missing = 0; - let f = load_ini(&fallback)?; +fn export_load(inputs: &[PathBuf]) -> Result<BTreeMap<String, String>> { + let mut ini = BTreeMap::new(); + for path in inputs { + let f = load_ini(&path)?; for (k, v) in f { - #[allow(clippy::map_entry)] if !ini.contains_key(&k) { - if option_env!("SHOW_MISSING").is_some() { - eprintln!("fallback: key {k:?} is missing"); - } - missing += 1; ini.insert(k, v); } } - eprintln!("-- {missing} missing keys were substituted from fallback language") } for &(code, name) in NATIVE_LANGUAGE_NAMES { ini.insert(format!("c.settings.ui.language.{code}"), name.to_owned()); @@ -88,22 +77,17 @@ fn export_load(input: &Path, fallback: Option<PathBuf>) -> Result<BTreeMap<Strin fn main() -> Result<()> { let args = Args::parse(); match args { - Args::ExportJson { - fallback, - input, - output, - } => { - let ini = export_load(&input, fallback)?; + Args::ExportJson { inputs, output } => { + let ini = export_load(&inputs)?; File::create(output)?.write_all(serde_json::to_string(&ini)?.as_bytes())?; Ok(()) } Args::ExportPo { remap_ids: id_map, - input, output, - fallback, + inputs, } => { - let ini = export_load(&input, fallback)?; + let ini = export_load(&inputs)?; let id_map = id_map.map(|path| load_ini(&path)).transpose()?; File::create(output)?.write_all( format!( @@ -116,7 +100,12 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" {}"#, - input.file_stem().unwrap().to_string_lossy(), + inputs + .first() + .expect("at least one input required") + .file_stem() + .unwrap() + .to_string_lossy(), ini.into_iter() .fold(String::new(), |mut a, (mut key, value)| { if let Some(id_map) = &id_map { diff --git a/test-client/makefile b/test-client/makefile index d7bbb51a..fd007720 100644 --- a/test-client/makefile +++ b/test-client/makefile @@ -28,6 +28,6 @@ LT = ../target/release/localetool $(LT): $(shell find ../locale/tools -type f) { cd ..; cargo $(CARGOFLAGS) build --release --bin localetool; } -locale/%.json: ../locale/%.ini $(LT) ../locale/en.ini +locale/%.json: $(LT) ../locale/%.ini ../book/locale/%.ini ../locale/en.ini ../book/locale/en.ini @mkdir -p locale - $(LT) export-json $< $@ --fallback ../locale/en.ini + $(LT) export-json $@ $(wordlist 2,99,$(^)) |