chore: parse translations at compile time

not finished but its much safer and nicer now
This commit is contained in:
Alexander Medvedev committed 2026-02-08 13:22:36 +01:00
1 parent abe01f3019
commit e45ab613f4
47 files changed
+339 -193

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use std::{collections::BTreeMap, fs};
pub(crate) fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/en_us.json");
let en_us: BTreeMap<String, String> = serde_json::from_str(
&fs::read_to_string("../assets/en_us.json").expect("en_us is missing"),
)
.unwrap();
let mut constants = TokenStream::new();
for (name, value) in &en_us {
let clean_name = name.to_uppercase().replace(['.', '-'], "_");
let ident = format_ident!("{}", clean_name);
if !value.is_empty() {
constants.extend(quote! {
#[doc = #value]
pub const #ident: &str = #name;
});
} else {
constants.extend(quote! {
pub const #ident: &str = #name;
});
}
}
quote! {
#constants
}
}