Merge pull request #4029 from element-hq/johannes/i18next-cli

Replace deprecated i18next-parser with i18next-cli
This commit is contained in:
Johannes Marbach
2026-06-10 15:00:45 +02:00
committed by GitHub
7 changed files with 884 additions and 786 deletions

View File

@@ -1,32 +0,0 @@
import type { UserConfig } from "i18next-parser";
const config: UserConfig = {
keySeparator: ".",
namespaceSeparator: false,
contextSeparator: "|",
pluralSeparator: "_",
createOldCatalogs: false,
defaultNamespace: "app",
lexers: {
ts: [
{
lexer: "JavascriptLexer",
functions: ["t", "translatedError"],
namespaceFunctions: ["useTranslation", "withTranslation"],
},
],
tsx: [
{
lexer: "JsxLexer",
functions: ["t", "translatedError"],
namespaceFunctions: ["useTranslation", "withTranslation"],
},
],
},
locales: ["en"],
output: "locales/$LOCALE/$NAMESPACE.json",
input: ["src/**/*.{ts,tsx}"],
sort: true,
};
export default config;

20
i18next.config.ts Normal file
View File

@@ -0,0 +1,20 @@
import { defineConfig } from "i18next-cli";
export default defineConfig({
locales: ["en"],
extract: {
input: ["src/**/*.{ts,tsx}"],
output: "locales/{{language}}/{{namespace}}.json",
defaultNS: "app",
keySeparator: ".",
nsSeparator: false,
contextSeparator: "|",
extractFromComments: false,
functions: ["t", "*.t", "translatedError", "i18nKey"],
transComponents: ["Trans"],
},
types: {
input: ["locales/{{language}}/{{namespace}}.json"],
output: "src/types/i18next.d.ts",
},
});

View File

@@ -11,7 +11,7 @@ export default {
vite: {
config: ["vite.config.ts", "vite-embedded.config.ts", "vite-sdk.config.ts"],
},
entry: ["src/main.tsx", "i18next-parser.config.ts"],
entry: ["src/main.tsx", "i18next.config.ts"],
ignoreBinaries: [
// This is deprecated, so Knip doesn't actually recognize it as a globally
// installed binary. TODO We should switch to Compose v2:

View File

@@ -24,8 +24,8 @@
"lint:eslint-fix": "eslint --max-warnings 0 src playwright --fix",
"lint:knip": "knip",
"lint:types": "tsc",
"i18n": "i18next",
"i18n:check": "i18next --fail-on-warnings --fail-on-update",
"i18n": "npx i18next-cli extract",
"i18n:check": "npx i18next-cli extract --ci",
"test": "vitest",
"test:storybook": "vitest --project=storybook",
"test:unit": "vitest --project=unit",
@@ -108,7 +108,7 @@
"global-jsdom": "^26.0.0",
"i18next": "^25.0.0",
"i18next-browser-languagedetector": "^8.0.0",
"i18next-parser": "^9.1.0",
"i18next-cli": "^1.61.0",
"jsdom": "^26.0.0",
"knip": "^5.86.0",
"livekit-client": "^2.18.1",

1587
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,6 +8,8 @@ Please see LICENSE in the repository root for full details.
import { t } from "i18next";
import { type ConnectionError } from "livekit-client";
import { i18nKey } from "./i18n";
export enum ErrorCode {
/**
* Configuration problem due to no MatrixRTC backend/SFU is exposed via .well-known and no fallback configured.
@@ -251,9 +253,9 @@ export class PeerConnectionTimeoutError extends ElementCallError {
ErrorCode.SFU_ERROR,
ErrorCategory.NETWORK_CONNECTIVITY,
);
// Mark translation key for i18n extraction
// t("error.peer_connection_timeout_description");
this.localisedMessageKey = "error.peer_connection_timeout_description";
this.localisedMessageKey = i18nKey(
"error.peer_connection_timeout_description",
);
this.localisedMessageValues = {
linkUrl:
"https://docs.element.io/latest/element-server-suite-pro/configuring-components/configuring-matrix-rtc/#sfu-connectivity-troubleshooting",
@@ -268,9 +270,9 @@ export class LivekitConnectionError extends ElementCallError {
ErrorCode.SFU_ERROR,
ErrorCategory.NETWORK_CONNECTIVITY,
);
// Mark translation key for i18n extraction
// t("error.livekit_connection_error_description");
this.localisedMessageKey = "error.livekit_connection_error_description";
this.localisedMessageKey = i18nKey(
"error.livekit_connection_error_description",
);
this.localisedMessageValues = { reason: cause.reasonName };
}
}

9
src/utils/i18n.ts Normal file
View File

@@ -0,0 +1,9 @@
/*
Copyright 2026 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
// Custom marker function to allow i18next extraction
export const i18nKey = (key: string): string => key;