anki/rslib/i18n_helpers/BUILD.bazel
RumovZ 0efa3f944f
Garbage collect unused Fluent strings (#1482)
* Canonify import of i18n module

Should always be imported as `tr`, or `tr2` if there is a name collision
(Svelte).

* Add helper for garbage collecting ftl strings

Also add a serializer for ftl asts.

* Add helper for filter-mapping `DirEntry`s

* Fix `i18n_helpers/BUILD.bazel`

* run cargo-raze

* Refactor `garbage_collection.rs`

- Improve helper for file iterating
- Remove unused terms as well
- Fix issue with checking for nested messages by switching to a regex-
based approach (which runs before deleting)
- Some more refactorings and lint fixes

* Fix lints in `serialize.rs`

* Write json pretty and sorted

* Update `serialize.rs` and fix header

* Fix doc and remove `dbg!`

* Add binaries for ftl garbage collection

Also relax type constraints and strip debug tests.

* add rust_binary targets for i18n helpers (dae)

* add scripts to update desktop usage/garbage collect (dae)

Since we've already diverged from 2.1.49, we won't gain anything
from generating a stable json just yet. But once 2.1.50 is released,
we should run 'ftl/update-desktop-usage.sh stable'.

* add keys from AnkiMobile (dae)

* Mention caveats in `remove-unused.sh`
2021-11-12 18:19:01 +10:00

62 lines
1.4 KiB
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
load("@rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")
load("@rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
load("//rslib:rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
# Library
#######################
rust_library(
name = "anki_i18n_helpers",
srcs = glob(
[
"src/**/*.rs",
],
exclude = ["src/bin/**"],
),
visibility = ["//rslib:__subpackages__"],
deps = [
"//rslib/i18n_helpers/cargo:fluent_syntax",
"//rslib/i18n_helpers/cargo:lazy_static",
"//rslib/i18n_helpers/cargo:regex",
"//rslib/i18n_helpers/cargo:serde_json",
"//rslib/i18n_helpers/cargo:walkdir",
],
)
rust_binary(
name = "write_ftl_json",
srcs = ["src/bin/write_ftl_json.rs"],
deps = [":anki_i18n_helpers"],
)
rust_binary(
name = "garbage_collect_ftl_entries",
srcs = ["src/bin/garbage_collect_ftl_entries.rs"],
deps = [":anki_i18n_helpers"],
)
# Tests
#######################
rust_test(
name = "i18n_helpers_tests",
crate = ":anki_i18n_helpers",
)
rustfmt_test(
name = "format_check",
srcs = glob([
"**/*.rs",
]),
)
rustfmt_fix(
name = "format",
srcs = glob([
"**/*.rs",
]),
)