Split up i18n-generated into i18n-{translate,modules}

This commit is contained in:
Henrik Giesel 2021-10-03 02:45:22 +02:00
parent 7170bee37e
commit 58a4190abb
12 changed files with 54 additions and 48 deletions

View file

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

View file

@ -6,7 +6,7 @@
*/
import { ChangeNotetypeState, getChangeNotetypeInfo, getNotetypeNames } from "./lib";
import { setupI18n, tr } from "../lib/i18n";
import { setupI18n, ModuleName } from "../lib/i18n";
import { checkNightMode } from "../lib/nightmode";
import ChangeNotetypePage from "./ChangeNotetypePage.svelte";
import { nightModeKey } from "../components/context-keys";
@ -20,7 +20,7 @@ export async function changeNotetypePage(
getChangeNotetypeInfo(oldNotetypeId, newNotetypeId),
getNotetypeNames(),
setupI18n({
modules: [tr.ModuleName.ACTIONS, tr.ModuleName.CHANGE_NOTETYPE],
modules: [ModuleName.ACTIONS, ModuleName.CHANGE_NOTETYPE],
}),
]);

View file

@ -2,14 +2,14 @@
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { getCongratsInfo } from "./lib";
import { setupI18n, tr } from "../lib/i18n";
import { setupI18n, ModuleName } from "../lib/i18n";
import { checkNightMode } from "../lib/nightmode";
import CongratsPage from "./CongratsPage.svelte";
export async function congrats(target: HTMLDivElement): Promise<void> {
checkNightMode();
await setupI18n({ modules: [tr.ModuleName.SCHEDULING] });
await setupI18n({ modules: [ModuleName.SCHEDULING] });
const info = await getCongratsInfo();
const page = new CongratsPage({
target,

View file

@ -8,7 +8,7 @@
import "../sveltelib/export-runtime";
import { getDeckOptionsInfo, DeckOptionsState } from "./lib";
import { setupI18n, tr } from "../lib/i18n";
import { setupI18n, ModuleName } from "../lib/i18n";
import { checkNightMode } from "../lib/nightmode";
import DeckOptionsPage from "./DeckOptionsPage.svelte";
import { nightModeKey, touchDeviceKey, modalsKey } from "../components/context-keys";
@ -21,9 +21,9 @@ export async function deckOptions(
getDeckOptionsInfo(deckId),
setupI18n({
modules: [
tr.ModuleName.SCHEDULING,
tr.ModuleName.ACTIONS,
tr.ModuleName.DECK_CONFIG,
ModuleName.SCHEDULING,
ModuleName.ACTIONS,
ModuleName.DECK_CONFIG,
],
}),
]);

View file

@ -13,7 +13,7 @@ import type EditorToolbar from "./EditorToolbar.svelte";
import type TagEditor from "./TagEditor.svelte";
import { filterHTML } from "../html-filter";
import { setupI18n, tr } from "../lib/i18n";
import { setupI18n, ModuleName } from "../lib/i18n";
import { isApplePlatform } from "../lib/platform";
import { registerShortcut } from "../lib/shortcuts";
import { bridgeCommand } from "../lib/bridgecommand";
@ -200,10 +200,10 @@ export function setTags(tags: string[]): void {
export const i18n = setupI18n({
modules: [
tr.ModuleName.EDITING,
tr.ModuleName.KEYBOARD,
tr.ModuleName.ACTIONS,
tr.ModuleName.BROWSING,
ModuleName.EDITING,
ModuleName.KEYBOARD,
ModuleName.ACTIONS,
ModuleName.BROWSING,
],
});

View file

@ -3,7 +3,7 @@
import type { SvelteComponent } from "svelte/internal";
import { setupI18n, tr } from "../lib/i18n";
import { setupI18n, ModuleName } from "../lib/i18n";
import { checkNightMode } from "../lib/nightmode";
import GraphsPage from "./GraphsPage.svelte";
@ -33,8 +33,7 @@ export function graphs(
): void {
const nightMode = checkNightMode();
setupI18n({ modules: [tr.ModuleName.STATISTICS, tr.ModuleName.SCHEDULING] }).then(
() => {
setupI18n({ modules: [ModuleName.STATISTICS, ModuleName.SCHEDULING] }).then(() => {
new GraphsPage({
target,
props: {
@ -45,6 +44,5 @@ export function graphs(
controller,
},
});
}
);
});
}

View file

@ -6,8 +6,13 @@ load("@rules_python//python:defs.bzl", "py_binary")
load("@py_deps//:requirements.bzl", "requirement")
load("//ts:jest.bzl", "jest_test")
_generated = [
"i18n-generated.ts",
_i18n_files = [
"i18n-translate.ts",
"i18n-modules.ts",
]
_generated = _i18n_files + [
"backend_proto.d.ts",
]
protobufjs_library(
@ -29,8 +34,8 @@ py_binary(
genrule(
name = "fluent_gen",
outs = ["i18n-generated.ts"],
cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $@",
outs = _i18n_files,
cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $(OUTS)",
tools = [
"genfluent",
"//rslib/i18n:strings.json",

View file

@ -7,7 +7,7 @@ from typing import List, Literal, TypedDict
import stringcase
strings_json, outfile = sys.argv[1:]
strings_json, translate_out, modules_out = sys.argv[1:]
modules = json.load(open(strings_json, encoding="utf8"))
@ -101,17 +101,17 @@ def module_names() -> str:
return buf
out = ""
out += methods()
out += module_names()
open(outfile, "wb").write(
def write(outfile, out) -> None:
open(outfile, "wb").write(
(
"""// Copyright: Ankitects Pty Ltd and contributors
f"""// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
"""
+ out
).encode("utf8")
)
)
write(translate_out, str(methods()))
write(modules_out, str(module_names()))

View file

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

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

@ -79,7 +79,7 @@ export class I18n {
// global singleton
export const i18n = new I18n();
import type { ModuleName } from "./i18n-generated";
import type { ModuleName } from "./i18n-modules";
export async function setupI18n(args: { modules: ModuleName[] }): Promise<void> {
const resp = await fetch("/_anki/i18nResources", {
@ -103,4 +103,5 @@ export async function setupI18n(args: { modules: ModuleName[] }): Promise<void>
i18n.langs = json.langs;
}
export * as tr from "./i18n-generated";
export { ModuleName } from "./i18n-modules";
export * as tr from "./i18n-translate";