Anki/pylib/anki/_backend/BUILD.bazel
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

103 lines
2 KiB
Text

load("@rules_python//python:defs.bzl", "py_binary")
load("@py_deps//:requirements.bzl", "requirement")
load("//pylib:protobuf.bzl", "py_proto_library_typed")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//lib:selects.bzl", "selects")
py_proto_library_typed(
name = "backend_pb2",
src = "//rslib:backend.proto",
visibility = [
"//visibility:public",
],
)
py_binary(
name = "genbackend",
srcs = [
"backend_pb2",
"genbackend.py",
],
deps = [
requirement("black"),
requirement("stringcase"),
requirement("protobuf"),
],
)
genrule(
name = "rsbackend_gen",
outs = ["generated.py"],
cmd = "$(location genbackend) $@",
tools = ["genbackend"],
)
py_binary(
name = "genfluent",
srcs = [
"genfluent.py",
],
deps = [
requirement("black"),
requirement("stringcase"),
],
)
genrule(
name = "fluent_gen",
outs = ["fluent.py"],
cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $@",
tools = [
"genfluent",
"//rslib/i18n:strings.json",
],
)
copy_file(
name = "rsbridge_unix",
src = "//pylib/rsbridge",
out = "rsbridge.so",
)
copy_file(
name = "rsbridge_win",
src = "//pylib/rsbridge",
out = "rsbridge.pyd",
)
alias(
name = "rsbridge",
actual = selects.with_or({
(
"@io_bazel_rules_rust//rust/platform:x86_64-pc-windows-msvc",
): ":rsbridge_win",
"//conditions:default": ":rsbridge_unix",
}),
)
_py_srcs = [
"genbackend.py",
"__init__.py",
]
# for format check
filegroup(
name = "py_source_files",
srcs = _py_srcs,
visibility = [
"//pylib:__subpackages__",
],
)
filegroup(
name = "_backend",
srcs = [
"__init__.py",
"rsbridge.pyi",
":backend_pb2",
":fluent_gen",
":rsbackend_gen",
":rsbridge",
],
visibility = ["//pylib:__subpackages__"],
)