Create own directory for i18n

This commit is contained in:
Henrik Giesel 2021-10-03 22:59:39 +02:00
parent 402b56e5b1
commit 4083f16848
12 changed files with 47 additions and 36 deletions

View file

@ -1,5 +1,5 @@
licenses.json
vendor
i18n-translate.ts
i18n-modules.ts
lib/i18n/translate.ts
lib/i18n/modules.ts
backend_proto.d.ts

View file

@ -1,26 +1,11 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test")
load("//ts:protobuf.bzl", "protobufjs_library")
load("//ts:typescript.bzl", "typescript")
load("@rules_python//python:defs.bzl", "py_binary")
load("@py_deps//:requirements.bzl", "requirement")
load("//ts:jest.bzl", "jest_test")
_i18n_files = [
"i18n-translate.ts",
"i18n-modules.ts",
]
_generated = _i18n_files + [
"backend_proto.d.ts",
]
protobufjs_library(
name = "backend_proto",
proto = "//proto:backend_proto_lib",
visibility = ["//visibility:public"],
)
py_binary(
name = "genfluent",
srcs = [
@ -31,10 +16,14 @@ py_binary(
requirement("stringcase"),
],
)
_i18n_generated = [
"i18n/translate.ts",
"i18n/modules.ts",
]
genrule(
name = "fluent_gen",
outs = _i18n_files,
outs = _i18n_generated,
cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $(OUTS)",
tools = [
"genfluent",
@ -42,13 +31,24 @@ genrule(
],
)
protobufjs_library(
name = "backend_proto",
proto = "//proto:backend_proto_lib",
visibility = ["//visibility:public"],
)
_generated = [
"backend_proto.d.ts",
] + _i18n_generated
typescript(
name = "lib",
srcs = glob(
["*.ts"],
exclude = _generated,
),
generated = [":" + file for file in _generated],
exclude = _generated,
generated = [
":backend_proto.d.ts",
":i18n/translate.ts",
":i18n/modules.ts",
],
deps = [
":backend_proto",
"@npm//@fluent/bundle",
@ -63,9 +63,19 @@ typescript(
# Tests
################
prettier_test(exclude = _generated)
prettier_test(
srcs = glob(
["**/*.ts"],
exclude = _generated,
),
)
eslint_test(exclude = _generated)
eslint_test(
srcs = glob(
["**/*.ts"],
exclude = _generated,
),
)
jest_test(
deps = [

View file

@ -17,7 +17,7 @@ class Variable(TypedDict):
def methods() -> str:
out = [ 'import { translate } from "./i18n-bundles";' ]
out = [ 'import { translate } from "./bundles";' ]
for module in modules:
for translation in module["translations"]:
key = stringcase.camelcase(translation["key"].replace("-", "_"))

View file

@ -1 +0,0 @@
../../bazel-bin/ts/lib/i18n-modules.ts

View file

@ -1 +0,0 @@
../../bazel-bin/ts/lib/i18n-translate.ts

3
ts/lib/i18n/index.ts Normal file
View file

@ -0,0 +1,3 @@
export * from "./utils";
export * as tr from "./translate";
export { ModuleName } from "./modules";

1
ts/lib/i18n/modules.ts Symbolic link
View file

@ -0,0 +1 @@
../../../bazel-bin/ts/lib/i18n/modules.ts

1
ts/lib/i18n/translate.ts Symbolic link
View file

@ -0,0 +1 @@
../../../bazel-bin/ts/lib/i18n/translate.ts

View file

@ -4,8 +4,8 @@
import "intl-pluralrules";
import { FluentBundle, FluentResource } from "@fluent/bundle";
import { firstLanguage, setBundles } from "./i18n-bundles";
import type { ModuleName } from "./i18n-modules";
import { firstLanguage, setBundles } from "./bundles";
import type { ModuleName } from "./modules";
export function supportsVerticalText(): boolean {
const firstLang = firstLanguage();
@ -79,6 +79,3 @@ export async function setupI18n(args: { modules: ModuleName[] }): Promise<void>
setBundles(...newBundles);
langs.splice(0, langs.length, ...json.langs);
}
export { ModuleName } from "./i18n-modules";
export * as tr from "./i18n-translate";

View file

@ -1,6 +1,6 @@
{
"extends": "../tsconfig.json",
"include": ["*"],
"include": ["*", "i18n/*"],
"references": [],
"compilerOptions": {
"types": ["jest"]

View file

@ -4,12 +4,13 @@ load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "js_library")
def typescript(
name,
srcs = None,
exclude = [],
generated = [],
tsconfig = "tsconfig.json",
visibility = ["//visibility:public"],
**kwargs):
if not srcs:
srcs = native.glob(["**/*.ts"])
srcs = native.glob(["**/*.ts"], exclude = exclude)
# all tsconfig files must be in the bazel-out folder
copy_to_bin(