anki/rslib/i18n/build/main.rs
Damien Elmes 9aece2a7b8 rework translation handling
Instead of generating a fluent.proto file with a giant enum, create
a .json file representing the translations that downstream consumers
can use for code generation.

This enables the generation of a separate method for each translation,
with a docstring that shows the actual text, and any required arguments
listed in the function signature.

The codebase is still using the old enum for now; updating it will need
to come in future commits, and the old enum will need to be kept
around, as add-ons are referencing it.

Other changes:

- move translation code into a separate crate
- store the translations on a per-file/module basis, which will allow
us to avoid sending 1000+ strings on each JS page load in the future
- drop the undocumented support for external .ftl files, that we weren't
using
- duplicate strings in translation files are now checked for at build
time
- fix i18n test failing when run outside Bazel
- drop slog dependency in i18n module
2021-03-26 09:41:32 +10:00

31 lines
846 B
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
mod check;
mod extract;
mod gather;
mod write_strings;
use std::{fs, path::PathBuf};
use check::check;
use extract::get_modules;
use gather::get_ftl_data;
use write_strings::write_strings;
// fixme: check all variables are present in translations as well?
fn main() {
// generate our own requirements
let map = get_ftl_data();
check(&map);
let modules = get_modules(&map);
write_strings(&map, &modules);
// put a json file into OUT_DIR that the write_json tool can read
let meta_json = serde_json::to_string_pretty(&modules).unwrap();
let dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let path = dir.join("strings.json");
fs::write(path, meta_json).unwrap();
}