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

View file

@ -17,7 +17,7 @@ class Variable(TypedDict):
def methods() -> str: def methods() -> str:
out = [ 'import { translate } from "./i18n-bundles";' ] out = [ 'import { translate } from "./bundles";' ]
for module in modules: for module in modules:
for translation in module["translations"]: for translation in module["translations"]:
key = stringcase.camelcase(translation["key"].replace("-", "_")) 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 "intl-pluralrules";
import { FluentBundle, FluentResource } from "@fluent/bundle"; import { FluentBundle, FluentResource } from "@fluent/bundle";
import { firstLanguage, setBundles } from "./i18n-bundles"; import { firstLanguage, setBundles } from "./bundles";
import type { ModuleName } from "./i18n-modules"; import type { ModuleName } from "./modules";
export function supportsVerticalText(): boolean { export function supportsVerticalText(): boolean {
const firstLang = firstLanguage(); const firstLang = firstLanguage();
@ -79,6 +79,3 @@ export async function setupI18n(args: { modules: ModuleName[] }): Promise<void>
setBundles(...newBundles); setBundles(...newBundles);
langs.splice(0, langs.length, ...json.langs); 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", "extends": "../tsconfig.json",
"include": ["*"], "include": ["*", "i18n/*"],
"references": [], "references": [],
"compilerOptions": { "compilerOptions": {
"types": ["jest"] "types": ["jest"]

View file

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