diff --git a/ts/.prettierignore b/ts/.prettierignore index d3ac072af..74bfe61c1 100644 --- a/ts/.prettierignore +++ b/ts/.prettierignore @@ -1,4 +1,5 @@ licenses.json vendor -i18n-generated.ts +i18n-translate.ts +i18n-modules.ts backend_proto.d.ts diff --git a/ts/change-notetype/index.ts b/ts/change-notetype/index.ts index 654ce852c..3133fb06a 100644 --- a/ts/change-notetype/index.ts +++ b/ts/change-notetype/index.ts @@ -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], }), ]); diff --git a/ts/congrats/index.ts b/ts/congrats/index.ts index 13d8dfe1f..4c4c4c79d 100644 --- a/ts/congrats/index.ts +++ b/ts/congrats/index.ts @@ -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 { checkNightMode(); - await setupI18n({ modules: [tr.ModuleName.SCHEDULING] }); + await setupI18n({ modules: [ModuleName.SCHEDULING] }); const info = await getCongratsInfo(); const page = new CongratsPage({ target, diff --git a/ts/deck-options/index.ts b/ts/deck-options/index.ts index 5998ca0c1..8f68c20fd 100644 --- a/ts/deck-options/index.ts +++ b/ts/deck-options/index.ts @@ -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, ], }), ]); diff --git a/ts/editor/index.ts b/ts/editor/index.ts index 41a6081bf..6101098ef 100644 --- a/ts/editor/index.ts +++ b/ts/editor/index.ts @@ -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, ], }); diff --git a/ts/graphs/index.ts b/ts/graphs/index.ts index 436f101e8..bee33dd83 100644 --- a/ts/graphs/index.ts +++ b/ts/graphs/index.ts @@ -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,18 +33,16 @@ export function graphs( ): void { const nightMode = checkNightMode(); - setupI18n({ modules: [tr.ModuleName.STATISTICS, tr.ModuleName.SCHEDULING] }).then( - () => { - new GraphsPage({ - target, - props: { - graphs, - nightMode, - initialSearch: search, - initialDays: days, - controller, - }, - }); - } - ); + setupI18n({ modules: [ModuleName.STATISTICS, ModuleName.SCHEDULING] }).then(() => { + new GraphsPage({ + target, + props: { + graphs, + nightMode, + initialSearch: search, + initialDays: days, + controller, + }, + }); + }); } diff --git a/ts/lib/BUILD.bazel b/ts/lib/BUILD.bazel index 105ff7e4c..19d0b493a 100644 --- a/ts/lib/BUILD.bazel +++ b/ts/lib/BUILD.bazel @@ -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", diff --git a/ts/lib/genfluent.py b/ts/lib/genfluent.py index d2ca94b9e..ca89ef7c2 100644 --- a/ts/lib/genfluent.py +++ b/ts/lib/genfluent.py @@ -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( - ( - """// Copyright: Ankitects Pty Ltd and contributors +def write(outfile, out) -> None: + open(outfile, "wb").write( + ( + f"""// Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html """ - + out - ).encode("utf8") -) + + out + ).encode("utf8") + ) + + +write(translate_out, str(methods())) +write(modules_out, str(module_names())) diff --git a/ts/lib/i18n-generated.ts b/ts/lib/i18n-generated.ts deleted file mode 120000 index b41e33779..000000000 --- a/ts/lib/i18n-generated.ts +++ /dev/null @@ -1 +0,0 @@ -../../bazel-bin/ts/lib/i18n-generated.ts \ No newline at end of file diff --git a/ts/lib/i18n-modules.ts b/ts/lib/i18n-modules.ts new file mode 120000 index 000000000..4255166e6 --- /dev/null +++ b/ts/lib/i18n-modules.ts @@ -0,0 +1 @@ +../../bazel-bin/ts/lib/i18n-modules.ts \ No newline at end of file diff --git a/ts/lib/i18n-translate.ts b/ts/lib/i18n-translate.ts new file mode 120000 index 000000000..960a367e6 --- /dev/null +++ b/ts/lib/i18n-translate.ts @@ -0,0 +1 @@ +../../bazel-bin/ts/lib/i18n-translate.ts \ No newline at end of file diff --git a/ts/lib/i18n.ts b/ts/lib/i18n.ts index a49dba1b9..5fad548df 100644 --- a/ts/lib/i18n.ts +++ b/ts/lib/i18n.ts @@ -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 { const resp = await fetch("/_anki/i18nResources", { @@ -103,4 +103,5 @@ export async function setupI18n(args: { modules: ModuleName[] }): Promise i18n.langs = json.langs; } -export * as tr from "./i18n-generated"; +export { ModuleName } from "./i18n-modules"; +export * as tr from "./i18n-translate";