From 33d6d51d59dcb7bc1a762516a6d7e7a39b85d7c4 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 20 Jul 2024 09:24:16 +0300 Subject: [PATCH 01/12] i18n: Set up i18next --- package-lock.json | 31 +++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 32 insertions(+) diff --git a/package-lock.json b/package-lock.json index 9f7814ddf..683413b85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,6 +42,7 @@ "html2plaintext": "2.1.4", "http-proxy-agent": "7.0.2", "https-proxy-agent": "7.0.4", + "i18next": "^23.12.2", "image-type": "4.1.0", "ini": "3.0.1", "is-animated": "2.0.2", @@ -7457,6 +7458,28 @@ "ms": "^2.0.0" } }, + "node_modules/i18next": { + "version": "23.12.2", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-23.12.2.tgz", + "integrity": "sha512-XIeh5V+bi8SJSWGL3jqbTEBW5oD6rbP5L+E7dVQh1MNTxxYef0x15rhJVcRb7oiuq4jLtgy2SD8eFlf6P2cmqg==", + "funding": [ + { + "type": "individual", + "url": "https://locize.com" + }, + { + "type": "individual", + "url": "https://locize.com/i18next.html" + }, + { + "type": "individual", + "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" + } + ], + "dependencies": { + "@babel/runtime": "^7.23.2" + } + }, "node_modules/iconv-corefoundation": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/iconv-corefoundation/-/iconv-corefoundation-1.1.7.tgz", @@ -19154,6 +19177,14 @@ "ms": "^2.0.0" } }, + "i18next": { + "version": "23.12.2", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-23.12.2.tgz", + "integrity": "sha512-XIeh5V+bi8SJSWGL3jqbTEBW5oD6rbP5L+E7dVQh1MNTxxYef0x15rhJVcRb7oiuq4jLtgy2SD8eFlf6P2cmqg==", + "requires": { + "@babel/runtime": "^7.23.2" + } + }, "iconv-corefoundation": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/iconv-corefoundation/-/iconv-corefoundation-1.1.7.tgz", diff --git a/package.json b/package.json index 9165cc5d2..6d4b0cc08 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "html2plaintext": "2.1.4", "http-proxy-agent": "7.0.2", "https-proxy-agent": "7.0.4", + "i18next": "^23.12.2", "image-type": "4.1.0", "ini": "3.0.1", "is-animated": "2.0.2", From 10ec7d6b2bf9b43b36f9a8e01ad38abbcf8fe367 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 20 Jul 2024 09:32:56 +0300 Subject: [PATCH 02/12] i18n: Set up client dependency to i18next --- src/public/app/services/i18n.js | 5 +++++ src/public/app/services/library_loader.js | 5 ++++- src/routes/assets.ts | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/public/app/services/i18n.js diff --git a/src/public/app/services/i18n.js b/src/public/app/services/i18n.js new file mode 100644 index 000000000..7fab4af92 --- /dev/null +++ b/src/public/app/services/i18n.js @@ -0,0 +1,5 @@ +import library_loader from "./library_loader.js"; + +await library_loader.requireLibrary(library_loader.I18NEXT); + +export const t = i18next.t; \ No newline at end of file diff --git a/src/public/app/services/library_loader.js b/src/public/app/services/library_loader.js index 6860795ca..aa8ffe984 100644 --- a/src/public/app/services/library_loader.js +++ b/src/public/app/services/library_loader.js @@ -72,6 +72,8 @@ const MARKJS = { ] }; +const I18NEXT = { js: [ "node_modules/i18next/i18next.min.js" ] }; + async function requireLibrary(library) { if (library.css) { library.css.map(cssUrl => requireCss(cssUrl)); @@ -129,5 +131,6 @@ export default { FORCE_GRAPH, MERMAID, EXCALIDRAW, - MARKJS + MARKJS, + I18NEXT } diff --git a/src/routes/assets.ts b/src/routes/assets.ts index 6ebfd8313..475940e32 100644 --- a/src/routes/assets.ts +++ b/src/routes/assets.ts @@ -69,6 +69,8 @@ function register(app: express.Application) { app.use(`/${assetPath}/node_modules/split.js/dist/`, persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/split.js/dist/'))); app.use(`/${assetPath}/node_modules/panzoom/dist/`, persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/panzoom/dist/'))); + + app.use(`/${assetPath}/node_modules/i18next/`, persistentCacheStatic(path.join(srcRoot, "..", 'node_modules/i18next/'))) } export = { From 0dbe6702ff1faf750ac7982a5b23c52f0db40408 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 20 Jul 2024 09:42:55 +0300 Subject: [PATCH 03/12] i18n: Translate about page --- src/public/app/services/i18n.js | 21 +++++++++++++++++++++ src/public/app/widgets/dialogs/about.js | 17 +++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/public/app/services/i18n.js b/src/public/app/services/i18n.js index 7fab4af92..29a778cdc 100644 --- a/src/public/app/services/i18n.js +++ b/src/public/app/services/i18n.js @@ -2,4 +2,25 @@ import library_loader from "./library_loader.js"; await library_loader.requireLibrary(library_loader.I18NEXT); +i18next.init({ + lng: "en", + debug: true, + resources: { + en: { + translation: { + about: { + title: "About TriliumNext Notes", + homepage: "Homepage:", + app_version: "App version:", + db_version: "DB version:", + sync_version: "Sync version:", + build_date: "Build date:", + build_revision: "Build revision:", + data_directory: "Data directory:" + } + } + } + } +}); + export const t = i18next.t; \ No newline at end of file diff --git a/src/public/app/widgets/dialogs/about.js b/src/public/app/widgets/dialogs/about.js index 9bf98e098..672dab563 100644 --- a/src/public/app/widgets/dialogs/about.js +++ b/src/public/app/widgets/dialogs/about.js @@ -1,5 +1,6 @@ import server from "../../services/server.js"; import utils from "../../services/utils.js"; +import { t } from "../../services/i18n.js"; import BasicWidget from "../basic_widget.js"; const TPL = ` @@ -7,7 +8,7 @@ const TPL = `