mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	server: Set up early initialization of i18n
This commit is contained in:
		| @@ -70,4 +70,4 @@ electron.app.on("will-quit", () => { | ||||
| // this is to disable electron warning spam in the dev console (local development only) | ||||
| process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true"; | ||||
|  | ||||
| await import('./src/www.js'); | ||||
| await import('./src/main.js'); | ||||
|   | ||||
							
								
								
									
										16
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								package.json
									
									
									
									
									
								
							| @@ -12,7 +12,7 @@ | ||||
|   }, | ||||
|   "copyright": "", | ||||
|   "bin": { | ||||
|     "trilium": "src/www.js" | ||||
|     "trilium": "src/main.js" | ||||
|   }, | ||||
|   "repository": { | ||||
|     "type": "git", | ||||
| @@ -20,10 +20,10 @@ | ||||
|   }, | ||||
|   "type": "module", | ||||
|   "scripts": { | ||||
|     "start-server": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.ts", | ||||
|     "start-server-safe": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.ts", | ||||
|     "start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.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/www.ts", | ||||
|     "start-server": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", | ||||
|     "start-server-safe": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", | ||||
|     "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-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .", | ||||
| @@ -43,9 +43,9 @@ | ||||
|     "prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts", | ||||
|     "update-build-info": "tsx bin/update-build-info.ts", | ||||
|     "errors": "tsc --watch --noEmit", | ||||
|     "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts", | ||||
|     "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts", | ||||
|     "integration-mem-db-dev": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts", | ||||
|     "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", | ||||
|     "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", | ||||
|     "integration-mem-db-dev": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", | ||||
|     "generate-document": "cross-env nodemon src/tools/generate_document.ts 1000" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|   | ||||
							
								
								
									
										26
									
								
								src/main.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/main.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| 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 | ||||
|     }); | ||||
| } | ||||
|  | ||||
| async function startApplication() { | ||||
|     await import("./www.js"); | ||||
| } | ||||
|  | ||||
| await initializeTranslations(); | ||||
| await startApplication(); | ||||
| @@ -4,6 +4,7 @@ import optionService from "./options.js"; | ||||
| import log from "./log.js"; | ||||
| import utils from "./utils.js"; | ||||
| import { KeyboardShortcut } from './keyboard_actions_interface.js'; | ||||
| import { t } from "i18next"; | ||||
|  | ||||
| const isMac = process.platform === "darwin"; | ||||
| const isElectron = utils.isElectron(); | ||||
| @@ -19,7 +20,7 @@ const isElectron = utils.isElectron(); | ||||
|  | ||||
| const DEFAULT_KEYBOARD_ACTIONS: KeyboardShortcut[] = [ | ||||
|     { | ||||
|         separator: "Note navigation" | ||||
|         separator: t("keyboard-actions.note-navigation") | ||||
|     }, | ||||
|     { | ||||
|         actionName: "backInNoteHistory", | ||||
|   | ||||
							
								
								
									
										14
									
								
								src/www.ts
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/www.ts
									
									
									
									
									
								
							| @@ -1,4 +1,5 @@ | ||||
| #!/usr/bin/env node | ||||
|  | ||||
| import app from "./app.js"; | ||||
| import sessionParser from "./routes/session_parser.js"; | ||||
| import fs from "fs"; | ||||
| @@ -12,8 +13,6 @@ import utils from "./services/utils.js"; | ||||
| import port from "./services/port.js"; | ||||
| import host from "./services/host.js"; | ||||
| import semver from "semver"; | ||||
| import i18next from "i18next"; | ||||
| import Backend from "i18next-fs-backend"; | ||||
|  | ||||
| // setup basic error handling even before requiring dependencies, since those can produce errors as well | ||||
|  | ||||
| @@ -59,17 +58,6 @@ async function startTrilium() { | ||||
|         (await import('electron')).app.requestSingleInstanceLock(); | ||||
|     }    | ||||
|  | ||||
|     // Initialize translations | ||||
|     i18next.use(Backend).init({ | ||||
|         lng: "ro", | ||||
|         fallbackLng: "en", | ||||
|         ns: "server", | ||||
|         backend: { | ||||
|             loadPath: "translations/{{lng}}/{{ns}}.json" | ||||
|         }, | ||||
|         debug: true | ||||
|     }); | ||||
|  | ||||
|     log.info(JSON.stringify(appInfo, null, 2)); | ||||
|  | ||||
|     // for perf. issues it's good to know the rough configuration | ||||
|   | ||||
		Reference in New Issue
	
	Block a user