🧑‍💻 Update i18next types (#1453)

This commit is contained in:
Luke Vella 2024-12-01 23:51:49 +00:00 committed by GitHub
parent ca207a913e
commit 40df1ff9da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 30 deletions

View file

@ -4,15 +4,13 @@ import type emails from "@rallly/emails/locales/emails.json";
import type app from "../public/locales/en/app.json";
interface I18nNamespaces {
app: typeof app;
emails: typeof emails;
}
declare module "i18next" {
interface CustomTypeOptions {
defaultNS: "app";
resources: I18nNamespaces;
returnNull: false;
resources: {
app: typeof app;
emails: typeof emails;
};
}
}

View file

@ -1,11 +1,9 @@
import { Trans as BaseTrans } from "react-i18next";
import { Trans as BaseTrans, useTranslation } from "react-i18next";
import { useTranslation } from "@/i18n/client";
import type { I18nNamespaces } from "../../declarations/i18next";
import type { TxKeyPath } from "../i18n/types";
export const Trans = (props: {
i18nKey: keyof I18nNamespaces["app"];
i18nKey: TxKeyPath;
defaults?: string;
values?: Record<string, string | number | boolean | undefined>;
children?: React.ReactNode;

View file

@ -1,16 +1,11 @@
import type { Namespace } from "i18next";
import { defaultNS } from "@/i18n/settings";
import { initI18next } from "./i18n";
export async function getTranslation(
locale: string,
ns: Namespace = defaultNS,
) {
const i18nextInstance = await initI18next(locale, ns);
export async function getTranslation(locale: string) {
const i18nextInstance = await initI18next(locale, defaultNS);
return {
t: i18nextInstance.getFixedT(locale, Array.isArray(ns) ? ns[0] : ns),
t: i18nextInstance.getFixedT(locale, defaultNS),
i18n: i18nextInstance,
};
}

View file

@ -0,0 +1,3 @@
import type app from "../../public/locales/en/app.json";
export type TxKeyPath = keyof typeof app;