Skip to content

Build your personal knowledge base with Trilium Notes

electron: Solve server translation loading on macOS

Elian Doran849a6a3aef6e
diff --git a/forge.config.cjs b/forge.config.cjs
index 192bcbe3d2..91730ed432 100644
--- a/forge.config.cjs
+++ b/forge.config.cjs
@@ -10,7 +10,13 @@ module.exports = {
overwrite: true,
asar: true,
icon: "./images/app-icons/icon",
- extraResource: getExtraResourcesForPlatform(),
+ extraResource: [
+ // Moved to root
+ ...getExtraResourcesForPlatform(),
+
+ // Moved to resources (TriliumNext Notes.app/Contents/Resources on macOS)
+ "translations/"
+ ],
afterComplete: [(buildPath, _electronVersion, platform, _arch, callback) => {
const extraResources = getExtraResourcesForPlatform();
for (const resource of extraResources) {
@@ -77,8 +83,7 @@ module.exports = {
function getExtraResourcesForPlatform() {
let resources = [
'dump-db/',
- './bin/tpl/anonymize-database.sql',
- 'translations/'
+ './bin/tpl/anonymize-database.sql'
];
const scripts = ['trilium-portable', 'trilium-safe-mode', 'trilium-no-cert-check']
switch (process.platform) {
diff --git a/src/services/i18n.ts b/src/services/i18n.ts
index 5754bc4eb4..d7620cffd4 100644
--- a/src/services/i18n.ts
+++ b/src/services/i18n.ts
@@ -2,19 +2,34 @@ import i18next from "i18next";
import Backend from "i18next-fs-backend";
import options from "./options.js";
import sql_init from "./sql_init.js";
+import { fileURLToPath } from "url";
+import { dirname, join } from "path";
+import utils from "./utils.js";
+import env from "./env.js";
export async function initializeTranslations() {
+ const resourceDir = getResourceDir();
+
// Initialize translations
await i18next.use(Backend).init({
lng: getCurrentLanguage(),
fallbackLng: "en",
ns: "server",
+ debug: true,
backend: {
- loadPath: "translations/{{lng}}/{{ns}}.json"
+ loadPath: join(resourceDir, "translations/{{lng}}/{{ns}}.json")
}
});
}
+function getResourceDir() {
+ if (utils.isElectron() && !env.isDev()) {
+ return process.resourcesPath;
+ } else {
+ return join(dirname(fileURLToPath(import.meta.url)), "..", "..");
+ }
+}
+
function getCurrentLanguage() {
let language;
if (sql_init.isDbInitialized()) {