mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 09:16:38 -04:00
add support for launcher
rustcfg to trim translations
This commit is contained in:
parent
9f90f1c21f
commit
1cbcd244cb
3 changed files with 21 additions and 5 deletions
|
@ -23,10 +23,10 @@ use write_strings::write_strings;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
// generate our own requirements
|
// generate our own requirements
|
||||||
let map = get_ftl_data();
|
let mut map = get_ftl_data();
|
||||||
check(&map);
|
check(&map);
|
||||||
let modules = get_modules(&map);
|
let mut modules = get_modules(&map);
|
||||||
write_strings(&map, &modules);
|
write_strings(&map, &modules, "strings.rs");
|
||||||
|
|
||||||
typescript::write_ts_interface(&modules)?;
|
typescript::write_ts_interface(&modules)?;
|
||||||
python::write_py_interface(&modules)?;
|
python::write_py_interface(&modules)?;
|
||||||
|
@ -41,5 +41,15 @@ fn main() -> Result<()> {
|
||||||
write_file_if_changed(path, meta_json)?;
|
write_file_if_changed(path, meta_json)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allow passing in "--cfg launcher" for the launcher
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(launcher)");
|
||||||
|
|
||||||
|
// generate strings for the launcher
|
||||||
|
map.iter_mut()
|
||||||
|
.for_each(|(_, modules)| modules.retain(|module, _| module == "launcher"));
|
||||||
|
modules.retain(|module| module.name == "launcher");
|
||||||
|
write_strings(&map, &modules, "strings_launcher.rs");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,8 @@
|
||||||
|
|
||||||
#![allow(clippy::all)]
|
#![allow(clippy::all)]
|
||||||
|
|
||||||
|
#[cfg(not(launcher))]
|
||||||
include!(concat!(env!("OUT_DIR"), "/strings.rs"));
|
include!(concat!(env!("OUT_DIR"), "/strings.rs"));
|
||||||
|
|
||||||
|
#[cfg(launcher)]
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/strings_launcher.rs"));
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::extract::VariableKind;
|
||||||
use crate::gather::TranslationsByFile;
|
use crate::gather::TranslationsByFile;
|
||||||
use crate::gather::TranslationsByLang;
|
use crate::gather::TranslationsByLang;
|
||||||
|
|
||||||
pub fn write_strings(map: &TranslationsByLang, modules: &[Module]) {
|
pub fn write_strings(map: &TranslationsByLang, modules: &[Module], out_fn: &str) {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
// lang->module map
|
// lang->module map
|
||||||
|
@ -28,14 +28,16 @@ pub fn write_strings(map: &TranslationsByLang, modules: &[Module]) {
|
||||||
write_methods(modules, &mut buf);
|
write_methods(modules, &mut buf);
|
||||||
|
|
||||||
let dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
let dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||||
let path = dir.join("strings.rs");
|
let path = dir.join(out_fn);
|
||||||
fs::write(path, buf).unwrap();
|
fs::write(path, buf).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_methods(modules: &[Module], buf: &mut String) {
|
fn write_methods(modules: &[Module], buf: &mut String) {
|
||||||
buf.push_str(
|
buf.push_str(
|
||||||
r#"
|
r#"
|
||||||
|
#[allow(unused_imports)]
|
||||||
use crate::{I18n,Number};
|
use crate::{I18n,Number};
|
||||||
|
#[allow(unused_imports)]
|
||||||
use fluent::{FluentValue, FluentArgs};
|
use fluent::{FluentValue, FluentArgs};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue