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
docs(i18n): describe how to check a new language's Electron locale
Elian Dorandeb27ceb50bd
diff --git a/.claude/skills/adding-a-display-language/SKILL.md b/.claude/skills/adding-a-display-language/SKILL.mdnew file mode 100644index 0000000000..b0c7874375--- /dev/null+++ b/.claude/skills/adding-a-display-language/SKILL.md@@ -0,0 +1,106 @@+---+name: adding-a-display-language+description: Use when making a new language selectable in Trilium — "add Danish support", "enable <language>", "<language> is translated enough, ship it", or when the translation coverage gate fails because a language above 50% on Weblate is not offered. Covers checking the language is ready, registering it in `LOCALES` and every per-library mapping (dayjs, FullCalendar, Excalidraw, CKEditor, Univer, PDF.js), choosing its `electronLocale` and proving Electron ships that locale with the trim-locales spec, what to do when Chromium has no locale for the language, the website's separate list, and the tests to run. Translating the strings themselves is the translating-locales skill.+---++# Adding a display language++The translations arrive from Weblate on their own; what a maintainer adds is the **registration**: an+entry in `UNSORTED_LOCALES` (`packages/commons/src/lib/i18n.ts`) plus a mapping in every library that+renders its own UI. The step-by-step list is the Developer Guide page+`docs/Developer Guide/Developer Guide/Concepts/Internationalisation Translations/Adding a new locale.md`+— read it and follow it. This skill adds what the page leaves to judgement: readiness, the Electron+check, and verification.++## 1. Is the language ready?++```bash+node scripts/translation/check-translation-coverage.mts # Weblate: languages >50% but not offered+node .claude/skills/translating-locales/locale.mjs measure <id> # repo: client / entry / server coverage+```++- The Trilium id is the folder name under `apps/client/src/translations/` (and+ `apps/server/src/assets/translations/`), which Weblate creates. No folder means no translations yet.+- The bar is ~50% client coverage. Below it, stop and say so rather than registering a mostly-English UI.+- The **website** is a separate Weblate component with its own list (`apps/website/src/locales.ts`).+ Measure `apps/website/src/translations/<id>/translation.json` against `en` the same way and add it+ there only when it clears 50% too; otherwise leave it out and say why in the commit body.++## 2. Register it++Follow the guide's steps. After step 1 (`UNSORTED_LOCALES`), `pnpm typecheck` names every+`Record<DISPLAYABLE_LOCALE_IDS, …>` still missing the id, so the library mappings cannot be forgotten.+For each library, check the bundle exists before mapping it — a guessed import path fails only at+runtime:++| Mapping | Bundle to look for | No bundle → |+|---|---|---|+| `DAYJS_LOADER` (`commons/src/lib/dayjs.ts`) | `node_modules/dayjs/locale/<code>.js` | closest locale |+| calendar `LOCALE_MAPPINGS` | `node_modules/fullcalendar/locales/<code>.js` | `null` |+| canvas `LANGUAGE_MAPPINGS` | `@excalidraw/excalidraw/dist/prod/locales/<code>-*.js` | `null` |+| ckeditor5 `LOCALE_MAPPINGS` + the `it.each` in `i18n.spec.ts` | `ckeditor5/dist/translations/<code>.js` | `null` |+| spreadsheet `UNIVER_LOCALES` | `@univerjs/preset-sheets-core/lib/locales/<code>.js` | `null` (English) |+| PDF.js `LOCALE_MAPPINGS` (`pdfjs-viewer/scripts/build.ts`) | `packages/pdfjs-viewer/viewer/locale/<electronLocale>` | entry naming the nearest directory |++`node_modules` is pnpm's layout, so resolve through Node when a path is not where you expect it+(`require.resolve("<pkg>/package.json")` from the consuming package). Also pick the Tesseract code+(`tesseractCode`, ISO 639-2, e.g. `dan`) and add it to the union on `Locale` if it is new.++## 3. The Electron locale++`electronLocale` names the **Chromium locale** the desktop build keeps for the language. Two things read+it:++- `trimElectronLocales` (`apps/desktop/electron-forge/trim-locales.ts`) deletes every Chromium locale+ file not named by an `electronLocale`, and **throws** — failing the packaging — when one names a file+ Electron does not ship. It runs in the forge `postPackage` hook and in the Flathub manifest.+- The options page lists a locale as a **formatting locale** only when it has an `electronLocale`.++The files Electron ships are recorded in `apps/desktop/electron-forge/electron-locales.json`, read from+the pinned release by `pnpm chore:update-electron-locales`. Look the language up there:++```bash+node -e 'const f=require("./apps/desktop/electron-forge/electron-locales.json");+ console.log(f.electronVersion, f.linux.filter((p) => p.startsWith(process.argv[1])))' da+```++- **Found** (`da.pak`, `pt-BR.pak`): set `electronLocale` to that name with `_` for `-` (`da`, `pt_BR`;+ `en-US.pak` is `"en"`). The `electronLocale` union on `Locale` mirrors this list, so the name is already+ a member.+- **Not found** — Chromium has no UI for the language. Point `electronLocale` at the closest locale+ Chromium does ship; the precedent is Irish, `{ id: "ga", electronLocale: "en" }`. Chromium's own strings+ (native menus, built-in dialogs) then show in that language, and Trilium's in the new one. Never add a+ name to the union that the JSON does not list: the type would accept it and the packaging would throw.++Then prove it — the spec builds its fixtures from the real file lists, so a wrong name fails here+instead of in a release build:++```bash+pnpm --filter desktop test trim-locales+```++- `Locale <x> was not found in the packaged app` — `electronLocale` names a file Electron does not ship.+ Fix the name; do not edit the JSON by hand.+- `electron-locales.json is out of date` — Electron was bumped without regenerating it. Run+ `pnpm chore:update-electron-locales` (network: a few hundred KB of range requests against the release+ zips) and commit the JSON in its own commit.++`getElectronLocale()` (`apps/desktop/src/main.ts`) passes the Trilium id, or the formatting locale's id,+to Chromium's `--lang`, not the `electronLocale`. When Chromium's name and the Trilium id can match,+prefer the id that matches.++## 4. Verify++```bash+pnpm typecheck+pnpm --filter client test canvas/i18n spreadsheet/locales collections/calendar services/i18n utils/formatters+pnpm --filter @triliumnext/ckeditor5 test src/i18n.spec # browser mode: Chromium via Playwright+pnpm --filter desktop test trim-locales+```++## 5. Commit++One `feat(i18n): add <Language> as a display language` commit. The body states the coverage figures,+then one line per mapping and what it maps to, and names every `null` and why (no Univer bundle, no+website because it is below 50%). Precedents: `git log --grep "as a display language"`,+`git log --grep "enable Irish"`. No User Guide page lists the languages, so there are no docs to update.diff --git a/.claude/skills/developing-electron-desktop/SKILL.md b/.claude/skills/developing-electron-desktop/SKILL.mdindex 70331bdf01..b181c50264 100644--- a/.claude/skills/developing-electron-desktop/SKILL.md+++ b/.claude/skills/developing-electron-desktop/SKILL.md@@ -28,6 +28,9 @@ apps/desktop/electron-forge/ # packaging (forge.config.ts, icons, dmg, portable/safe-mode launchers)# flip-fuses.ts + trim-locales.ts are ALSO run as scripts by the# Flathub manifest — see the packaging-for-flathub skill before editing+ # electron-locales.json: the pinned Electron's locale files, which+ # trim-locales.spec.ts runs against; regenerate it on every Electron+ # bump with `pnpm chore:update-electron-locales` (adding-a-display-language)```## Process and security modeldiff --git a/.claude/skills/translating-locales/SKILL.md b/.claude/skills/translating-locales/SKILL.mdindex 2040202c5c..6c60d8d553 100644--- a/.claude/skills/translating-locales/SKILL.md+++ b/.claude/skills/translating-locales/SKILL.md@@ -7,7 +7,7 @@ description: Use when filling in or improving a lagging UI translation locale inTrilium's UI is localized with **i18next**. English is the source of truth; other locales are normally crowd-translated via **Hosted Weblate**. This skill is for the *maintainer* case: deliberately filling a locale that lags behind (the recurring one is Romanian, `ro`).-**Scope — this skill *fills* an already-registered locale.** To **add a brand-new locale** (e.g. Polish) you must first do the one-time registration and build wiring; that's a separate task. Follow `docs/Developer Guide/Developer Guide/Concepts/Internationalisation Translations/Adding a new locale.md` to register it, then come back here to translate the strings.+**Scope — this skill *fills* an already-registered locale.** To **add a brand-new locale** (e.g. Polish) you must first do the one-time registration and build wiring; that's a separate task. Load the **`adding-a-display-language`** skill to register it, then come back here to translate the strings.**`en-GB` is the exception and must never be filled.** The `en` catalogues are US English, and `en-GB`carries **only** the strings whose British spelling differs — `"color_type": "Colour"`,diff --git a/.claude/skills/working-with-translations/SKILL.md b/.claude/skills/working-with-translations/SKILL.mdindex 8fd65dc50e..12e930105d 100644--- a/.claude/skills/working-with-translations/SKILL.md+++ b/.claude/skills/working-with-translations/SKILL.md@@ -194,3 +194,4 @@ That is the repo's only translation test: valid JSON, no duplicate keys, plus th## Related- **translating-locales** — filling in a lagging non-English locale: measuring coverage, exporting work lists, placeholder validation, plural categories per locale, and how Weblate sync works. Use that skill, not this one, when the task is "bring `<locale>` to 100%".+- **adding-a-display-language** — making a new language selectable: registering it in `LOCALES`, the per-library mappings, and the Electron locale check.diff --git a/CLAUDE.md b/CLAUDE.mdindex e934e3bb15..186f22d8e2 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -177,7 +177,7 @@ SQLite (`better-sqlite3` on Node, `@sqlite.org/sqlite-wasm` on OPFS in standalon- **Multi-paragraph text is one message with `\n\n` between paragraphs**, never a key per paragraph, so the translation decides where paragraphs fall. Render it with `.pre-wrap-text` or split it on blank lines into `<p>` — see the `working-with-translations` skill.- Third-party components (mind-map context menu, …) still go through `t()` with their strings under a dedicated namespace (e.g. `"mind-map"`).- **Text editor (`packages/ckeditor5`)**: plugins call `editor.t("English text")` — the English text *is* the message id, the entry lives under `text-editor.ck` keyed by its slug, and `apps/client/src/services/i18n.spec.ts` fails on a missing or stale one. Rules (name it `t`, literal argument, don't shadow upstream strings, `MESSAGE_OVERRIDES`, `renderShortcut`): **`ckeditor5-plugin-development` skill**.-- New locale: `docs/Developer Guide/Developer Guide/Concepts/Internationalisation Translations/Adding a new locale.md`.+- New display language: load the **`adding-a-display-language` skill** (readiness, the per-library mappings, the Electron locale check); the step list is `docs/Developer Guide/Developer Guide/Concepts/Internationalisation Translations/Adding a new locale.md`.### Attribute Inheritancediff --git a/docs/Developer Guide/Developer Guide/Concepts/Internationalisation Translations/Adding a new locale.md b/docs/Developer Guide/Developer Guide/Concepts/Internationalisation Translations/Adding a new locale.mdindex b303757f12..dcf490c738 100644--- a/docs/Developer Guide/Developer Guide/Concepts/Internationalisation Translations/Adding a new locale.md+++ b/docs/Developer Guide/Developer Guide/Concepts/Internationalisation Translations/Adding a new locale.md@@ -13,6 +13,17 @@ To do so:Steps 1 to 6 are keyed by `DISPLAYABLE_LOCALE_IDS`, so `pnpm typecheck` reports each one still missing after step 1.+## The Electron locale++The `electronLocale` of the new entry names the Chromium locale the desktop application keeps for the language. When packaging, `trimElectronLocales` in `apps/desktop/electron-forge/trim-locales.ts` deletes every Chromium locale file no `electronLocale` names, and fails the build when one names a file Electron does not ship. The options page also lists a locale as a formatting locale only when it has an `electronLocale`.++The locale files of the Electron version the desktop application pins are recorded in `apps/desktop/electron-forge/electron-locales.json`:++* If the language is listed there (for example `da.pak` or `pt-BR.pak`), set `electronLocale` to that name, with an underscore in place of the hyphen (`da`, `pt_BR`). `en-US.pak` is `"en"`.+* If it is not listed, Chromium has no translation for the language. Set `electronLocale` to the closest locale it does ship, as Irish does with `"en"`; Chromium's own strings then appear in that language.++`pnpm --filter desktop test trim-locales` runs the trim against those files and fails with "Locale … was not found in the packaged app" when the name is wrong. The same spec fails when the file records another Electron version than the one pinned in `apps/desktop/package.json`; after an Electron update, regenerate it with `pnpm chore:update-electron-locales` and commit the result.+## The websiteThe website tracks its own Weblate component and its own list, so a locale added to the application above is not offered on [triliumnotes.org](https://triliumnotes.org) until it is added there too.