use std::path::PathBuf;
fn main() {
let locale = std::env::var("AQL_LOCALE").unwrap_or_else(|_| "en".to_string());
let workspace_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.canonicalize()
.expect("workspace root must exist");
let locale_file = workspace_root.join(format!("locales/{locale}.toml"));
if !locale_file.exists() {
panic!(
"Locale file not found: {}\n Set AQL_LOCALE to an available locale or add the file.",
locale_file.display()
);
}
let content = std::fs::read_to_string(&locale_file)
.unwrap_or_else(|e| panic!("Failed to read {}: {e}", locale_file.display()));
content
.parse::<toml::Table>()
.unwrap_or_else(|e| panic!("Invalid TOML in {}: {e}", locale_file.display()));
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR must be set"));
std::fs::write(out_dir.join("messages.toml"), &content)
.unwrap_or_else(|e| panic!("Failed to write messages.toml to OUT_DIR: {e}"));
println!("cargo:rerun-if-changed={}", locale_file.display());
println!("cargo:rerun-if-env-changed=AQL_LOCALE");
}