Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
electron: Fix loading of i18n
Elian Doran68042994e0c2
diff --git a/bin/build-server.sh b/bin/build-server.shindex a0357b0462..be00cf5922 100755--- a/bin/build-server.sh+++ b/bin/build-server.sh@@ -22,7 +22,7 @@ rm -r $PKG_DIR/node/lib/node_modules/npmrm -r $PKG_DIR/node/include/noderm -r $PKG_DIR/node_modules/electron*-rm -r $PKG_DIR/electron.js+rm -r $PKG_DIR/electron*.jsprintf "#!/bin/sh\n./node/bin/node src/www" > $PKG_DIR/trilium.shchmod 755 $PKG_DIR/trilium.shdiff --git a/bin/copy-trilium.sh b/bin/copy-trilium.shindex 25b881dd79..ca2acf6748 100755--- a/bin/copy-trilium.sh+++ b/bin/copy-trilium.sh@@ -37,11 +37,11 @@ for f in 'package.json' 'package-lock.json' 'README.md' 'LICENSE' 'config-sampledone# Patch package.json main-sed -i 's/.\/dist\/electron.js/electron.js/g' "$DIR/package.json"+sed -i 's/.\/dist\/electron-main.js/electron-main.js/g' "$DIR/package.json"script_dir=$(realpath $(dirname $0))cp -R "$script_dir/../build/src" "$DIR"-cp "$script_dir/../build/electron.js" "$DIR"+cp "$script_dir/../build/electron-main.js" "$DIR"# run in subshell (so we return to original dir)(cd $DIR && npm install --omit=dev)diff --git a/electron-main.ts b/electron-main.tsnew file mode 100644index 0000000000..6fff6ae6bf--- /dev/null+++ b/electron-main.ts@@ -0,0 +1,4 @@+import { initializeTranslations } from "./src/services/i18n.js";++await initializeTranslations();+await import("./electron.js")\ No newline at end of filediff --git a/package-lock.json b/package-lock.jsonindex 1b2f392ebe..99eae360ad 100644--- a/package-lock.json+++ b/package-lock.json@@ -99,7 +99,7 @@"yauzl": "^3.1.3"},"bin": {- "trilium": "src/www.js"+ "trilium": "src/main.js"},"devDependencies": {"@electron-forge/cli": "^7.4.0",diff --git a/package.json b/package.jsonindex 9c2d773f18..d75f90ae29 100644--- a/package.json+++ b/package.json@@ -4,7 +4,7 @@"description": "Build your personal knowledge base with TriliumNext Notes","version": "0.90.6-beta","license": "AGPL-3.0-only",- "main": "./dist/electron.js",+ "main": "./dist/electron-main.js","author": {"name": "TriliumNext Notes Team","email": "[email protected]",@@ -25,7 +25,7 @@"start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts","start-test-server": "npm run switch-server; rimraf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 ts-node src/main.ts","qstart-server": "npm run switch-server && npm run start-server",- "start-electron": "npm run prepare-dist && cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./dist/electron.js --inspect=5858 .",+ "start-electron": "npm run prepare-dist && cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./dist/electron-main.js --inspect=5858 .","start-electron-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .","qstart-electron": "npm run switch-electron && npm run start-electron","switch-server": "rimraf ./node_modules/better-sqlite3 && npm install",diff --git a/src/main.ts b/src/main.tsindex 2878ca8182..c38b85933a 100644--- a/src/main.ts+++ b/src/main.ts@@ -1,22 +1,9 @@-import i18next from "i18next";-import Backend from "i18next-fs-backend";/** Make sure not to import any modules that depend on localized messages via i18next here, as the initializations* are loaded later and will result in an empty string.*/-async function initializeTranslations() {- // Initialize translations- await i18next.use(Backend).init({- lng: "ro",- fallbackLng: "en",- ns: "server",- backend: {- loadPath: "translations/{{lng}}/{{ns}}.json"- },- debug: true- });-}+import { initializeTranslations } from "./services/i18n.js";async function startApplication() {await import("./www.js");diff --git a/src/services/i18n.ts b/src/services/i18n.tsnew file mode 100644index 0000000000..9cd5e75624--- /dev/null+++ b/src/services/i18n.ts@@ -0,0 +1,15 @@+import i18next from "i18next";+import Backend from "i18next-fs-backend";++export async function initializeTranslations() {+ // Initialize translations+ await i18next.use(Backend).init({+ lng: "ro",+ fallbackLng: "en",+ ns: "server",+ backend: {+ loadPath: "translations/{{lng}}/{{ns}}.json"+ },+ debug: true+ });+}\ No newline at end of file