From 5f7bc2aff30c2e03c84e6d0271df5746792ebc01 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Thu, 19 Oct 2023 12:00:26 +0200 Subject: [PATCH] Typecheck & lint the i18next-parser config --- frontend/.eslintrc.cjs | 1 - frontend/i18next-parser.config.js | 18 ---------------- frontend/i18next-parser.config.ts | 36 +++++++++++++++++++++++++++++++ frontend/src/i18n.ts | 4 ++-- frontend/tsconfig.node.json | 3 ++- 5 files changed, 40 insertions(+), 22 deletions(-) delete mode 100644 frontend/i18next-parser.config.js create mode 100644 frontend/i18next-parser.config.ts diff --git a/frontend/.eslintrc.cjs b/frontend/.eslintrc.cjs index af121d4b0..7d0f73959 100644 --- a/frontend/.eslintrc.cjs +++ b/frontend/.eslintrc.cjs @@ -21,7 +21,6 @@ module.exports = { "**/coverage/**", "!.storybook", "*/gql/*.ts", - "i18next-parser.config.js", ], overrides: [ // General rules for JS/TS files diff --git a/frontend/i18next-parser.config.js b/frontend/i18next-parser.config.js deleted file mode 100644 index 7939c6792..000000000 --- a/frontend/i18next-parser.config.js +++ /dev/null @@ -1,18 +0,0 @@ -export default { - keySeparator: ".", - pluralSeparator: ":", - defaultNamespace: "frontend", - lexers: { - ts: [ - { - lexer: "JavascriptLexer", - functions: ["t", "translatedError"], - functionsNamespace: ["useTranslation", "withTranslation"], - }, - ], - }, - locales: ["en"], - output: "public/locales/$LOCALE.json", - input: ["src/**/*.{ts,tsx}"], - sort: true, -}; diff --git a/frontend/i18next-parser.config.ts b/frontend/i18next-parser.config.ts new file mode 100644 index 000000000..13ae39791 --- /dev/null +++ b/frontend/i18next-parser.config.ts @@ -0,0 +1,36 @@ +// Copyright 2023 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import type { UserConfig } from "i18next-parser"; + +const config: UserConfig = { + keySeparator: ".", + pluralSeparator: ":", + defaultNamespace: "frontend", + lexers: { + ts: [ + { + lexer: "JavascriptLexer", + functions: ["t", "translatedError"], + namespaceFunctions: ["useTranslation", "withTranslation"], + }, + ], + }, + locales: ["en"], + output: "public/locales/$LOCALE.json", + input: ["src/**/*.{ts,tsx}"], + sort: true, +}; + +export default config; diff --git a/frontend/src/i18n.ts b/frontend/src/i18n.ts index 26827493f..8a1de030b 100644 --- a/frontend/src/i18n.ts +++ b/frontend/src/i18n.ts @@ -14,7 +14,7 @@ import * as i18n from "i18next"; import LanguageDetector from "i18next-browser-languagedetector"; -import I18NextHttpBackend from "i18next-http-backend"; +import I18NextHttpBackend, { HttpBackendOptions } from "i18next-http-backend"; import { initReactI18next } from "react-i18next"; i18n @@ -30,7 +30,7 @@ i18n }, backend: { loadPath: "/locales/{{lng}}.json", - }, + } satisfies HttpBackendOptions, }); import.meta.hot?.on("locales-update", () => { diff --git a/frontend/tsconfig.node.json b/frontend/tsconfig.node.json index 301240227..053992522 100644 --- a/frontend/tsconfig.node.json +++ b/frontend/tsconfig.node.json @@ -16,6 +16,7 @@ "postcss.config.cjs", "tailwind.config.cjs", "tailwind.templates.config.cjs", - "codegen.ts" + "codegen.ts", + "i18next-parser.config.ts" ] }