From fcb3283a9dcc2afad8a669079eb02f3403ee4d21 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 18 Nov 2020 16:17:19 +1000 Subject: [PATCH] move ftl into top level ftl/ folder; make it source of truth for aqt This avoids the need to modify the external repo before new strings can be used in aqt. --- ftl/BUILD.bazel | 14 ++++++++++ {rslib/ftl => ftl/core}/actions.ftl | 0 {rslib/ftl => ftl/core}/adding.ftl | 0 {rslib/ftl => ftl/core}/browsing.ftl | 0 {rslib/ftl => ftl/core}/card-stats.ftl | 0 .../core}/card-template-rendering.ftl | 0 {rslib/ftl => ftl/core}/card-templates.ftl | 0 {rslib/ftl => ftl/core}/custom-study.ftl | 0 {rslib/ftl => ftl/core}/database-check.ftl | 0 {rslib/ftl => ftl/core}/deck-config.ftl | 0 {rslib/ftl => ftl/core}/decks.ftl | 0 {rslib/ftl => ftl/core}/editing.ftl | 0 {rslib/ftl => ftl/core}/empty-cards.ftl | 0 {rslib/ftl => ftl/core}/exporting.ftl | 0 {rslib/ftl => ftl/core}/fields.ftl | 0 {rslib/ftl => ftl/core}/filtering.ftl | 0 {rslib/ftl => ftl/core}/findreplace.ftl | 0 {rslib/ftl => ftl/core}/importing.ftl | 0 {rslib/ftl => ftl/core}/media-check.ftl | 0 {rslib/ftl => ftl/core}/media.ftl | 0 {rslib/ftl => ftl/core}/network.ftl | 0 {rslib/ftl => ftl/core}/notetypes.ftl | 0 {rslib/ftl => ftl/core}/preferences.ftl | 0 {rslib/ftl => ftl/core}/profiles.ftl | 0 {rslib/ftl => ftl/core}/scheduling.ftl | 0 {rslib/ftl => ftl/core}/search.ftl | 0 {rslib/ftl => ftl/core}/statistics.ftl | 0 {rslib/ftl => ftl/core}/studying.ftl | 0 {rslib/ftl => ftl/core}/sync.ftl | 0 {qt/ftl => ftl/qt}/about.ftl | 0 {qt/ftl => ftl/qt}/addons.ftl | 0 {qt/ftl => ftl/qt}/errors.ftl | 0 {qt/ftl => ftl/qt}/preferences.ftl | 0 {qt/ftl => ftl/qt}/profiles.ftl | 0 {qt/ftl => ftl/qt}/qt-accel.ftl | 0 {qt/ftl => ftl/qt}/qt-misc.ftl | 0 repos.bzl | 12 -------- rslib/BUILD.bazel | 17 ++++------- rslib/build/mergeftl.rs | 28 +++++++++++++++++-- scripts/synci18n.py | 14 ++++++++-- 40 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 ftl/BUILD.bazel rename {rslib/ftl => ftl/core}/actions.ftl (100%) rename {rslib/ftl => ftl/core}/adding.ftl (100%) rename {rslib/ftl => ftl/core}/browsing.ftl (100%) rename {rslib/ftl => ftl/core}/card-stats.ftl (100%) rename {rslib/ftl => ftl/core}/card-template-rendering.ftl (100%) rename {rslib/ftl => ftl/core}/card-templates.ftl (100%) rename {rslib/ftl => ftl/core}/custom-study.ftl (100%) rename {rslib/ftl => ftl/core}/database-check.ftl (100%) rename {rslib/ftl => ftl/core}/deck-config.ftl (100%) rename {rslib/ftl => ftl/core}/decks.ftl (100%) rename {rslib/ftl => ftl/core}/editing.ftl (100%) rename {rslib/ftl => ftl/core}/empty-cards.ftl (100%) rename {rslib/ftl => ftl/core}/exporting.ftl (100%) rename {rslib/ftl => ftl/core}/fields.ftl (100%) rename {rslib/ftl => ftl/core}/filtering.ftl (100%) rename {rslib/ftl => ftl/core}/findreplace.ftl (100%) rename {rslib/ftl => ftl/core}/importing.ftl (100%) rename {rslib/ftl => ftl/core}/media-check.ftl (100%) rename {rslib/ftl => ftl/core}/media.ftl (100%) rename {rslib/ftl => ftl/core}/network.ftl (100%) rename {rslib/ftl => ftl/core}/notetypes.ftl (100%) rename {rslib/ftl => ftl/core}/preferences.ftl (100%) rename {rslib/ftl => ftl/core}/profiles.ftl (100%) rename {rslib/ftl => ftl/core}/scheduling.ftl (100%) rename {rslib/ftl => ftl/core}/search.ftl (100%) rename {rslib/ftl => ftl/core}/statistics.ftl (100%) rename {rslib/ftl => ftl/core}/studying.ftl (100%) rename {rslib/ftl => ftl/core}/sync.ftl (100%) rename {qt/ftl => ftl/qt}/about.ftl (100%) rename {qt/ftl => ftl/qt}/addons.ftl (100%) rename {qt/ftl => ftl/qt}/errors.ftl (100%) rename {qt/ftl => ftl/qt}/preferences.ftl (100%) rename {qt/ftl => ftl/qt}/profiles.ftl (100%) rename {qt/ftl => ftl/qt}/qt-accel.ftl (100%) rename {qt/ftl => ftl/qt}/qt-misc.ftl (100%) diff --git a/ftl/BUILD.bazel b/ftl/BUILD.bazel new file mode 100644 index 000000000..5356aa65d --- /dev/null +++ b/ftl/BUILD.bazel @@ -0,0 +1,14 @@ +filegroup( + name = "ftl", + srcs = [ + "@rslib_ftl//:files", + "@extra_ftl//:files", + ] + glob(["**/*.ftl"]), + visibility = ["//rslib:__subpackages__"], +) + +# export this file as a way of locating the top level folder in $(location ...) +exports_files( + ["BUILD.bazel"], + visibility = ["//rslib:__subpackages__"], +) diff --git a/rslib/ftl/actions.ftl b/ftl/core/actions.ftl similarity index 100% rename from rslib/ftl/actions.ftl rename to ftl/core/actions.ftl diff --git a/rslib/ftl/adding.ftl b/ftl/core/adding.ftl similarity index 100% rename from rslib/ftl/adding.ftl rename to ftl/core/adding.ftl diff --git a/rslib/ftl/browsing.ftl b/ftl/core/browsing.ftl similarity index 100% rename from rslib/ftl/browsing.ftl rename to ftl/core/browsing.ftl diff --git a/rslib/ftl/card-stats.ftl b/ftl/core/card-stats.ftl similarity index 100% rename from rslib/ftl/card-stats.ftl rename to ftl/core/card-stats.ftl diff --git a/rslib/ftl/card-template-rendering.ftl b/ftl/core/card-template-rendering.ftl similarity index 100% rename from rslib/ftl/card-template-rendering.ftl rename to ftl/core/card-template-rendering.ftl diff --git a/rslib/ftl/card-templates.ftl b/ftl/core/card-templates.ftl similarity index 100% rename from rslib/ftl/card-templates.ftl rename to ftl/core/card-templates.ftl diff --git a/rslib/ftl/custom-study.ftl b/ftl/core/custom-study.ftl similarity index 100% rename from rslib/ftl/custom-study.ftl rename to ftl/core/custom-study.ftl diff --git a/rslib/ftl/database-check.ftl b/ftl/core/database-check.ftl similarity index 100% rename from rslib/ftl/database-check.ftl rename to ftl/core/database-check.ftl diff --git a/rslib/ftl/deck-config.ftl b/ftl/core/deck-config.ftl similarity index 100% rename from rslib/ftl/deck-config.ftl rename to ftl/core/deck-config.ftl diff --git a/rslib/ftl/decks.ftl b/ftl/core/decks.ftl similarity index 100% rename from rslib/ftl/decks.ftl rename to ftl/core/decks.ftl diff --git a/rslib/ftl/editing.ftl b/ftl/core/editing.ftl similarity index 100% rename from rslib/ftl/editing.ftl rename to ftl/core/editing.ftl diff --git a/rslib/ftl/empty-cards.ftl b/ftl/core/empty-cards.ftl similarity index 100% rename from rslib/ftl/empty-cards.ftl rename to ftl/core/empty-cards.ftl diff --git a/rslib/ftl/exporting.ftl b/ftl/core/exporting.ftl similarity index 100% rename from rslib/ftl/exporting.ftl rename to ftl/core/exporting.ftl diff --git a/rslib/ftl/fields.ftl b/ftl/core/fields.ftl similarity index 100% rename from rslib/ftl/fields.ftl rename to ftl/core/fields.ftl diff --git a/rslib/ftl/filtering.ftl b/ftl/core/filtering.ftl similarity index 100% rename from rslib/ftl/filtering.ftl rename to ftl/core/filtering.ftl diff --git a/rslib/ftl/findreplace.ftl b/ftl/core/findreplace.ftl similarity index 100% rename from rslib/ftl/findreplace.ftl rename to ftl/core/findreplace.ftl diff --git a/rslib/ftl/importing.ftl b/ftl/core/importing.ftl similarity index 100% rename from rslib/ftl/importing.ftl rename to ftl/core/importing.ftl diff --git a/rslib/ftl/media-check.ftl b/ftl/core/media-check.ftl similarity index 100% rename from rslib/ftl/media-check.ftl rename to ftl/core/media-check.ftl diff --git a/rslib/ftl/media.ftl b/ftl/core/media.ftl similarity index 100% rename from rslib/ftl/media.ftl rename to ftl/core/media.ftl diff --git a/rslib/ftl/network.ftl b/ftl/core/network.ftl similarity index 100% rename from rslib/ftl/network.ftl rename to ftl/core/network.ftl diff --git a/rslib/ftl/notetypes.ftl b/ftl/core/notetypes.ftl similarity index 100% rename from rslib/ftl/notetypes.ftl rename to ftl/core/notetypes.ftl diff --git a/rslib/ftl/preferences.ftl b/ftl/core/preferences.ftl similarity index 100% rename from rslib/ftl/preferences.ftl rename to ftl/core/preferences.ftl diff --git a/rslib/ftl/profiles.ftl b/ftl/core/profiles.ftl similarity index 100% rename from rslib/ftl/profiles.ftl rename to ftl/core/profiles.ftl diff --git a/rslib/ftl/scheduling.ftl b/ftl/core/scheduling.ftl similarity index 100% rename from rslib/ftl/scheduling.ftl rename to ftl/core/scheduling.ftl diff --git a/rslib/ftl/search.ftl b/ftl/core/search.ftl similarity index 100% rename from rslib/ftl/search.ftl rename to ftl/core/search.ftl diff --git a/rslib/ftl/statistics.ftl b/ftl/core/statistics.ftl similarity index 100% rename from rslib/ftl/statistics.ftl rename to ftl/core/statistics.ftl diff --git a/rslib/ftl/studying.ftl b/ftl/core/studying.ftl similarity index 100% rename from rslib/ftl/studying.ftl rename to ftl/core/studying.ftl diff --git a/rslib/ftl/sync.ftl b/ftl/core/sync.ftl similarity index 100% rename from rslib/ftl/sync.ftl rename to ftl/core/sync.ftl diff --git a/qt/ftl/about.ftl b/ftl/qt/about.ftl similarity index 100% rename from qt/ftl/about.ftl rename to ftl/qt/about.ftl diff --git a/qt/ftl/addons.ftl b/ftl/qt/addons.ftl similarity index 100% rename from qt/ftl/addons.ftl rename to ftl/qt/addons.ftl diff --git a/qt/ftl/errors.ftl b/ftl/qt/errors.ftl similarity index 100% rename from qt/ftl/errors.ftl rename to ftl/qt/errors.ftl diff --git a/qt/ftl/preferences.ftl b/ftl/qt/preferences.ftl similarity index 100% rename from qt/ftl/preferences.ftl rename to ftl/qt/preferences.ftl diff --git a/qt/ftl/profiles.ftl b/ftl/qt/profiles.ftl similarity index 100% rename from qt/ftl/profiles.ftl rename to ftl/qt/profiles.ftl diff --git a/qt/ftl/qt-accel.ftl b/ftl/qt/qt-accel.ftl similarity index 100% rename from qt/ftl/qt-accel.ftl rename to ftl/qt/qt-accel.ftl diff --git a/qt/ftl/qt-misc.ftl b/ftl/qt/qt-misc.ftl similarity index 100% rename from qt/ftl/qt-misc.ftl rename to ftl/qt/qt-misc.ftl diff --git a/repos.bzl b/repos.bzl index 8ee857c5a..d1a066db4 100644 --- a/repos.bzl +++ b/repos.bzl @@ -135,12 +135,6 @@ filegroup( exports_files(["l10n.toml"]) """ - # native.new_local_repository( - # name = "rslib_ftl", - # path = "../anki-i18n/core", - # build_file_content = i18n_build_content, - # ) - new_git_repository( name = "rslib_ftl", build_file_content = i18n_build_content, @@ -150,12 +144,6 @@ exports_files(["l10n.toml"]) ) if not native.existing_rule("extra_ftl"): - # native.new_local_repository( - # name = "extra_ftl", - # path = "../anki-i18n/qtftl", - # build_file_content = i18n_build_content, - # ) - new_git_repository( name = "extra_ftl", build_file_content = i18n_build_content, diff --git a/rslib/BUILD.bazel b/rslib/BUILD.bazel index fa63e2d3f..a1d1e190c 100644 --- a/rslib/BUILD.bazel +++ b/rslib/BUILD.bazel @@ -3,14 +3,6 @@ load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script") load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test") -# FTL file gathering -####################### - -all_ftl_files = [ - "@rslib_ftl//:files", - "@extra_ftl//:files", -] + glob(["ftl/*.ftl"]) - # Build script ####################### @@ -25,7 +17,8 @@ cargo_build_script( "BUILDINFO": "$(location //:buildinfo.txt)", }, crate_root = "build/main.rs", - data = all_ftl_files + [ + data = [ + "//ftl", "backend.proto", "//:buildinfo.txt", "@com_google_protobuf//:protoc", @@ -162,7 +155,9 @@ rust_binary( genrule( name = "fluent_proto", - srcs = all_ftl_files + [ + srcs = [ + "//ftl", + "//ftl:BUILD.bazel", "//cargo:fluent_syntax", "@rslib_ftl//:l10n.toml", "@extra_ftl//:l10n.toml", @@ -171,7 +166,7 @@ genrule( cmd = """\ RSLIB_FTL_ROOT="$(location @rslib_ftl//:l10n.toml)" \ EXTRA_FTL_ROOT="$(location @extra_ftl//:l10n.toml)" \ -FTL_SRC="$(location ftl/database-check.ftl)" \ +FTL_SRC="$(location //ftl:BUILD.bazel)" \ $(location :write_fluent_proto) $(location fluent.proto)""", tools = [ ":write_fluent_proto", diff --git a/rslib/build/mergeftl.rs b/rslib/build/mergeftl.rs index 5a131b40f..24a7481e1 100644 --- a/rslib/build/mergeftl.rs +++ b/rslib/build/mergeftl.rs @@ -124,6 +124,10 @@ fn get_ftl_data() -> FTLData { for entry in fs::read_dir(&outer_entry.path()).unwrap() { let entry = entry.unwrap(); if entry.file_name().to_str().unwrap() == "templates" { + if include_local_qt_templates() { + // ignore source ftl files, as we've already extracted them from the source tree + continue; + } data.add_template_folder(&entry.path()); } else { data.add_language_folder(&entry.path()); @@ -136,18 +140,27 @@ fn get_ftl_data() -> FTLData { data } +/// In a standard build, the ftl/qt folder is used as the source +/// of truth for @extra_ftl, making it easier to add new strings. +/// If the Qt templates are not desired, the NO_QT_TEMPLATES env +/// var can be set to skip them. +fn include_local_qt_templates() -> bool { + env::var("NO_QT_TEMPLATES").is_err() +} + /// Extracts English text from ftl folder in source tree. fn get_ftl_data_from_source_tree() -> FTLData { let mut templates: Vec = vec![]; - let dir = if let Ok(srcfile) = env::var("FTL_SRC") { + let ftl_base = if let Ok(srcfile) = env::var("FTL_SRC") { let mut path = PathBuf::from(srcfile); path.pop(); path } else { - PathBuf::from("ftl") + PathBuf::from("../ftl") }; + let dir = ftl_base.join("core"); for entry in fs::read_dir(dir).unwrap() { let entry = entry.unwrap(); let fname = entry.file_name().into_string().unwrap(); @@ -156,6 +169,17 @@ fn get_ftl_data_from_source_tree() -> FTLData { } } + if include_local_qt_templates() { + let dir = ftl_base.join("qt"); + for entry in fs::read_dir(dir).unwrap() { + let entry = entry.unwrap(); + let fname = entry.file_name().into_string().unwrap(); + if fname.ends_with(".ftl") { + templates.push(fs::read_to_string(entry.path()).unwrap()); + } + } + } + FTLData { templates, translations: Default::default(), diff --git a/scripts/synci18n.py b/scripts/synci18n.py index 1b4d8b2b6..b7378d6fb 100644 --- a/scripts/synci18n.py +++ b/scripts/synci18n.py @@ -35,12 +35,12 @@ modules = [ Module( name="core", repo="git@github.com:ankitects/anki-core-i18n", - ftl=("rslib/ftl", "core/templates"), + ftl=("ftl/core", "core/templates"), ), Module( name="qtftl", repo="git@github.com:ankitects/anki-desktop-ftl", - ftl=("qt/ftl", "desktop/templates"), + ftl=("ftl/qt", "desktop/templates"), ), ] @@ -122,7 +122,15 @@ def update_ftl_templates(): (source, dest) = ftl dest = os.path.join(module.folder(), dest) subprocess.run( - ["rsync", "-ai", "--delete", "--no-perms", source + "/", dest + "/"], + [ + "rsync", + "-ai", + "--delete", + "--no-perms", + "--no-times", + source + "/", + dest + "/", + ], check=True, ) commit_if_changed(module.folder())