aboutsummaryrefslogtreecommitdiff
path: root/locale/tools/src
diff options
context:
space:
mode:
Diffstat (limited to 'locale/tools/src')
-rw-r--r--locale/tools/src/main.rs50
1 files changed, 34 insertions, 16 deletions
diff --git a/locale/tools/src/main.rs b/locale/tools/src/main.rs
index 19f58b39..56b81f86 100644
--- a/locale/tools/src/main.rs
+++ b/locale/tools/src/main.rs
@@ -20,6 +20,12 @@ enum Args {
input: PathBuf,
output: PathBuf,
},
+ ExportJson {
+ #[arg(long)]
+ fallback: Option<PathBuf>,
+ input: PathBuf,
+ output: PathBuf,
+ },
ExportGodotCsv {
input_dir: PathBuf,
output: PathBuf,
@@ -52,32 +58,44 @@ static NATIVE_LANGUAGE_NAMES: &[(&str, &str)] = &[
("pt", "Português"),
];
+fn export_load(input: &Path, fallback: Option<PathBuf>) -> Result<BTreeMap<String, String>> {
+ let mut ini = load_ini(&input)?;
+ 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);
+ }
+ }
+ }
+ for &(code, name) in NATIVE_LANGUAGE_NAMES {
+ ini.insert(format!("c.settings.ui.language.{code}"), name.to_owned());
+ }
+ Ok(ini)
+}
+
fn main() -> Result<()> {
let args = Args::parse();
match args {
+ Args::ExportJson {
+ fallback,
+ input,
+ output,
+ } => {
+ let ini = export_load(&input, fallback)?;
+ File::create(output)?.write_all(serde_json::to_string(&ini)?.as_bytes())?;
+ Ok(())
+ }
Args::ExportPo {
remap_ids: id_map,
input,
output,
fallback,
} => {
- let mut ini = load_ini(&input)?;
+ let ini = export_load(&input, fallback)?;
let id_map = id_map.map(|path| load_ini(&path)).transpose()?;
- 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);
- }
- }
- }
-
- for &(code, name) in NATIVE_LANGUAGE_NAMES {
- ini.insert(format!("c.settings.ui.language.{code}"), name.to_owned());
- }
-
File::create(output)?.write_all(
format!(
r#"