Skip to content

Commit ba34417

Browse files
committed
feat: move locales build script to separate file and generate constants for locale keys
1 parent a6e8bdb commit ba34417

File tree

8 files changed

+292
-162
lines changed

8 files changed

+292
-162
lines changed

Cargo.lock

Lines changed: 36 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ harness = false
8888

8989
[build-dependencies]
9090
lazy_static = "1"
91+
proc-macro2 = "1.0.103"
92+
quote = "1.0.42"
9193
regex = "1"
9294
serde_json = "1"
9395
serde_yaml = "0.9"
96+
syn = "2.0.110"
9497
tera = { version = "1", default-features = false }
9598

9699
[target.'cfg(windows)'.build-dependencies]

build.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use regex::Regex;
22
use std::collections::HashMap;
33
use std::env;
44
use std::error::Error;
5-
use std::fs::{self, create_dir_all, read_to_string, File};
6-
use std::io::BufWriter;
7-
use std::io::Write;
8-
use std::path::{Path, PathBuf};
5+
use std::fs::{self, File};
6+
use std::path::Path;
97
use std::sync::LazyLock;
108
use tera::{Context, Tera};
119

10+
#[path = "locales/build.rs"]
11+
mod locales;
12+
1213
fn main() -> Result<(), Box<dyn Error>> {
1314
#[cfg(windows)]
1415
{
@@ -31,25 +32,8 @@ fn main() -> Result<(), Box<dyn Error>> {
3132
)?;
3233
fs::write(output_path, rust_code)?;
3334

34-
println!("cargo:rerun-if-changed=locales/");
35-
let locales_dir = PathBuf::from("locales").read_dir()?;
36-
let out_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("__locales_compiled");
37-
38-
for dir in locales_dir {
39-
let dir = dir?.path();
40-
let lang = dir.components().last().unwrap();
41-
42-
let out_dir = out_dir.join(lang);
43-
create_dir_all(&out_dir).unwrap();
44-
45-
let mut out_file = BufWriter::new(File::create(out_dir.join("onefetch.ftl"))?);
46-
47-
for ftl in dir.read_dir()? {
48-
let ftl = ftl?.path();
49-
let contents = read_to_string(&ftl)?;
50-
writeln!(out_file, "{contents}")?;
51-
}
52-
}
35+
locales::concat_locales()?;
36+
locales::generate_consts(&out_dir)?;
5337

5438
Ok(())
5539
}

0 commit comments

Comments
 (0)