Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit b9a2be6

Browse files
authored
Merge pull request #248 from TriliumNext/feature/i18n_first_steps
i18n: First steps
2 parents 997da1c + ece343a commit b9a2be6

File tree

11 files changed

+147
-12
lines changed

11 files changed

+147
-12
lines changed

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"lokalise.i18n-ally"
4+
]
5+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# An array of strings which contain Language Ids defined by VS Code
2+
# You can check available language ids here: https://code.visualstudio.com/docs/languages/identifiers
3+
languageIds:
4+
- javascript
5+
- typescript
6+
7+
# An array of RegExes to find the key usage. **The key should be captured in the first match group**.
8+
# You should unescape RegEx strings in order to fit in the YAML file
9+
# To help with this, you can use https://www.freeformatter.com/json-escape.html
10+
usageMatchRegex:
11+
# The following example shows how to detect `t("your.i18n.keys")`
12+
# the `{key}` will be placed by a proper keypath matching regex,
13+
# you can ignore it and use your own matching rules as well
14+
- "[^\\w\\d]t\\(['\"`]({key})['\"`]"
15+
16+
# A RegEx to set a custom scope range. This scope will be used as a prefix when detecting keys
17+
# and works like how the i18next framework identifies the namespace scope from the
18+
# useTranslation() hook.
19+
# You should unescape RegEx strings in order to fit in the YAML file
20+
# To help with this, you can use https://www.freeformatter.com/json-escape.html
21+
scopeRangeRegex: "useTranslation\\(\\s*\\[?\\s*['\"`](.*?)['\"`]"
22+
23+
# An array of strings containing refactor templates.
24+
# The "$1" will be replaced by the keypath specified.
25+
refactorTemplates:
26+
- t("$1")
27+
28+
29+
# If set to true, only enables this custom framework (will disable all built-in frameworks)
30+
monopoly: true

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22
"editor.formatOnSave": false,
33
"editor.defaultFormatter": "esbenp.prettier-vscode",
44
"files.eol": "\n",
5-
"typescript.tsdk": "node_modules/typescript/lib"
5+
"typescript.tsdk": "node_modules/typescript/lib",
6+
"i18n-ally.sourceLanguage": "en",
7+
"i18n-ally.keystyle": "nested",
8+
"i18n-ally.localesPaths": [
9+
"./src/public/translations"
10+
],
611
}

package-lock.json

Lines changed: 42 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
"html2plaintext": "2.1.4",
7878
"http-proxy-agent": "7.0.2",
7979
"https-proxy-agent": "^7.0.5",
80+
"i18next": "^23.12.2",
81+
"i18next-http-backend": "^2.5.2",
8082
"image-type": "4.1.0",
8183
"ini": "^4.1.3",
8284
"is-animated": "2.0.2",

src/public/app/services/i18n.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import library_loader from "./library_loader.js";
2+
3+
await library_loader.requireLibrary(library_loader.I18NEXT);
4+
5+
await i18next
6+
.use(i18nextHttpBackend)
7+
.init({
8+
lng: "en",
9+
debug: true,
10+
backend: {
11+
loadPath: `/${window.glob.assetPath}/translations/{{lng}}/{{ns}}.json`
12+
}
13+
});
14+
15+
export const t = i18next.t;

src/public/app/services/library_loader.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ const MARKJS = {
7272
]
7373
};
7474

75+
const I18NEXT = {
76+
js: [
77+
"node_modules/i18next/i18next.min.js",
78+
"node_modules/i18next-http-backend/i18nextHttpBackend.min.js"
79+
]
80+
};
81+
7582
async function requireLibrary(library) {
7683
if (library.css) {
7784
library.css.map(cssUrl => requireCss(cssUrl));
@@ -129,5 +136,6 @@ export default {
129136
FORCE_GRAPH,
130137
MERMAID,
131138
EXCALIDRAW,
132-
MARKJS
139+
MARKJS,
140+
I18NEXT
133141
}

src/public/app/widgets/dialogs/about.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import server from "../../services/server.js";
22
import utils from "../../services/utils.js";
3+
import { t } from "../../services/i18n.js";
34
import BasicWidget from "../basic_widget.js";
45

56
const TPL = `
67
<div class="about-dialog modal fade mx-auto" tabindex="-1" role="dialog">
78
<div class="modal-dialog modal-lg" role="document">
89
<div class="modal-content">
910
<div class="modal-header">
10-
<h5 class="modal-title mr-auto">About TriliumNext Notes</h5>
11+
<h5 class="modal-title mr-auto">${t("about.title")}</h5>
1112
1213
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="margin-left: 0;">
1314
<span aria-hidden="true">&times;</span>
@@ -16,33 +17,33 @@ const TPL = `
1617
<div class="modal-body">
1718
<table class="table table-borderless">
1819
<tr>
19-
<th>Homepage:</th>
20+
<th>${t("about.homepage")}</th>
2021
<td><a href="https://github.com/TriliumNext/Notes" class="external">https://github.com/TriliumNext/Notes</a></td>
2122
</tr>
2223
<tr>
23-
<th>App version:</th>
24+
<th>${t("about.app_version")}</th>
2425
<td class="app-version"></td>
2526
</tr>
2627
<tr>
27-
<th>DB version:</th>
28+
<th>${t("about.db_version")}</th>
2829
<td class="db-version"></td>
2930
</tr>
3031
<tr>
31-
<th>Sync version:</th>
32+
<th>${t("about.sync_version")}</th>
3233
<td class="sync-version"></td>
3334
</tr>
3435
<tr>
35-
<th>Build date:</th>
36+
<th>${t("about.build_date")}</th>
3637
<td class="build-date"></td>
3738
</tr>
3839
3940
<tr>
40-
<th>Build revision:</th>
41+
<th>${t("about.build_revision")}</th>
4142
<td><a href="" class="build-revision external" target="_blank"></a></td>
4243
</tr>
4344
4445
<tr>
45-
<th>Data directory:</th>
46+
<th>${t("about.data_directory")}</th>
4647
<td class="data-directory"></td>
4748
</tr>
4849
</table>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"about": {
3+
"title": "About TriliumNext Notes",
4+
"homepage": "Homepage:",
5+
"app_version": "App version:",
6+
"db_version": "DB version:",
7+
"sync_version": "Sync version:",
8+
"build_date": "Build date:",
9+
"build_revision": "Build revision:",
10+
"data_directory": "Data directory:"
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"about": {
3+
"title": "Despre TriliumNext Notes",
4+
"homepage": "Site web:",
5+
"app_version": "Versiune aplicație:",
6+
"db_version": "Versiune bază de date:",
7+
"sync_version": "Versiune sincronizare:",
8+
"build_date": "Data compilării:",
9+
"build_revision": "Revizia compilării:",
10+
"data_directory": "Directorul de date:"
11+
}
12+
}

0 commit comments

Comments
 (0)