From c966d88e4c003b043c22fca0cf71ea8d14b1cb97 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 27 Feb 2020 20:38:34 +1000 Subject: [PATCH] add support for embedding the qt translations --- rslib/build.rs | 22 +++++++++++++++------- rspy/Makefile | 13 +++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/rslib/build.rs b/rslib/build.rs index bf365568f..e92358a03 100644 --- a/rslib/build.rs +++ b/rslib/build.rs @@ -4,6 +4,7 @@ use std::path::Path; use fluent_syntax::ast::{Entry::Message, ResourceEntry}; use fluent_syntax::parser::parse; +use std::collections::HashMap; fn get_identifiers(ftl_text: &str) -> Vec { let res = parse(ftl_text).unwrap(); @@ -126,29 +127,36 @@ fn main() -> std::io::Result<()> { prost_build::compile_protos(&["../proto/backend.proto"], &["../proto"]).unwrap(); // write the other language ftl files - // fixme: doesn't currently support extra dirs let mut ftl_lang_dirs = vec!["./ftl/repo/core".to_string()]; - if let Ok(paths) = std::env::var("FTL_LANG_DIRS") { + if let Ok(paths) = std::env::var("FTL_LOCALE_DIRS") { ftl_lang_dirs.extend(paths.split(",").map(|s| s.to_string())); } + let mut langs = HashMap::new(); for ftl_dir in ftl_lang_dirs { for ftl_dir in fs::read_dir(ftl_dir)? { - let ftl_dir = ftl_dir?; - if ftl_dir.file_name() == "templates" { + let lang_dir = ftl_dir?; + if lang_dir.file_name() == "templates" { continue; } let mut buf = String::new(); - let lang = ftl_dir.file_name().into_string().unwrap(); - for entry in fs::read_dir(ftl_dir.path())? { + let lang_name = lang_dir.file_name().into_string().unwrap(); + for entry in fs::read_dir(lang_dir.path())? { let entry = entry?; let fname = entry.file_name().into_string().unwrap(); let path = entry.path(); println!("cargo:rerun-if-changed=./ftl/{}", fname); buf += &fs::read_to_string(path)?; } - fs::write(format!("src/i18n/ftl/{}.ftl", lang), buf)?; + langs + .entry(lang_name) + .or_insert_with(|| String::new()) + .push_str(&buf) } } + for (lang, text) in langs { + fs::write(format!("src/i18n/ftl/{}.ftl", lang), text)?; + } + Ok(()) } diff --git a/rspy/Makefile b/rspy/Makefile index 787857e90..76285d577 100644 --- a/rspy/Makefile +++ b/rspy/Makefile @@ -12,7 +12,8 @@ OUTDIR := ../dist BUILDFLAGS := --release --strip RSPY_TARGET_DIR ?= target -QT_FTLS := ../qt/ftl +QT_FTL_TEMPLATES := ../qt/ftl +QT_FTL_LOCALES := ../qt/ftl/repo/desktop .PHONY: all develop build check fix clean @@ -20,19 +21,23 @@ all: develop develop: .build/develop -DEPS := .build/tools .build/vernum ../meta/buildhash $(wildcard $(QT_FTLS)/*.ftl) \ +DEPS := .build/tools .build/vernum ../meta/buildhash \ + $(wildcard $(QT_FTL_TEMPLATES)/*.ftl) \ + $(wildcard $(QT_FTL_LOCALES)/*/*.ftl) \ $(shell ${FIND} ../rslib/src -name '*.rs') $(wildcard ../proto/*) \ $(shell ${FIND} ../rslib/ftl -type f) .build/develop: $(DEPS) touch ../proto/backend.proto - FTL_TEMPLATE_DIRS="$(QT_FTLS)" CARGO_TARGET_DIR="$(RSPY_TARGET_DIR)" maturin develop + FTL_TEMPLATE_DIRS="$(QT_FTL_TEMPLATES)" FTL_LOCALE_DIRS="$(QT_FTL_LOCALES)" \ + CARGO_TARGET_DIR="$(RSPY_TARGET_DIR)" maturin develop touch $@ build: $(DEPS) rm -rf $(OUTDIR)/ankirspy* touch ../proto/backend.proto - FTL_TEMPLATE_DIRS="$(QT_FTLS)" maturin build -i $(shell which python3) -o $(OUTDIR) $(BUILDFLAGS) + FTL_TEMPLATE_DIRS="$(QT_FTL_TEMPLATES)" FTL_LOCALE_DIRS="$(QT_FTL_LOCALES)" \ + maturin build -i $(shell which python3) -o $(OUTDIR) $(BUILDFLAGS) check: .build/check