Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): the last circular dependency

Elian Doranc4d3e776a15d
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 1508ade084..7019617714 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -1,6 +1,6 @@
import type { CKTextEditor } from "@triliumnext/ckeditor5";
import type CodeMirror from "@triliumnext/codemirror";
-import { SqlExecuteResponse } from "@triliumnext/commons";
+import { type LOCALE_IDS, SqlExecuteResponse } from "@triliumnext/commons";
import type { NativeImage, TouchBar } from "electron";
import { ColumnComponent } from "tabulator-tables";
@@ -564,7 +564,7 @@ export class AppContext extends Component {
*/
async earlyInit() {
await options.initializedPromise;
- await initLocale();
+ await initLocale((options.get("locale") || "en") as LOCALE_IDS);
}
setLayout(layout: Layout) {
diff --git a/apps/client/src/services/i18n.ts b/apps/client/src/services/i18n.ts
index 8790bd6fc9..0743596731 100644
--- a/apps/client/src/services/i18n.ts
+++ b/apps/client/src/services/i18n.ts
@@ -1,16 +1,14 @@
-import options from "./options.js";
+import { LOCALE_IDS, LOCALES, setDayjsLocale } from "@triliumnext/commons";
import i18next from "i18next";
import i18nextHttpBackend from "i18next-http-backend";
-import { LOCALE_IDS, LOCALES, setDayjsLocale } from "@triliumnext/commons";
import { initReactI18next } from "react-i18next";
/**
* A deferred promise that resolves when translations are initialized.
*/
-export let translationsInitializedPromise = $.Deferred();
+export const translationsInitializedPromise = $.Deferred();
-export async function initLocale() {
- const locale = ((options.get("locale") as string) || "en") as LOCALE_IDS;
+export async function initLocale(locale: LOCALE_IDS = "en") {
i18next.use(initReactI18next);
await i18next.use(i18nextHttpBackend).init({
diff --git a/apps/client/src/services/server.ts b/apps/client/src/services/server.ts
index a52fa0fd3f..2d9d8273ae 100644
--- a/apps/client/src/services/server.ts
+++ b/apps/client/src/services/server.ts
@@ -1,3 +1,4 @@
+import { t } from "./i18n.js";
import utils, { isShare } from "./utils.js";
import ValidationError from "./validation_error.js";
@@ -343,9 +344,8 @@ async function reportError(method: string, url: string, statusCode: number, resp
} catch (e) {}
}
- // Dynamic imports to avoid circular dependency (toast/i18n → app_context → options → server).
+ // Dynamic import to avoid circular dependency (toast → app_context → options → server).
const toastService = (await import("./toast.js")).default;
- const { t } = await import("./i18n.js");
const messageStr = (typeof message === "string" ? message : JSON.stringify(message)) || "-";