mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-03 19:21:51 +02:00
🧑💻 Update i18next types (#1453)
This commit is contained in:
parent
ca207a913e
commit
40df1ff9da
7 changed files with 17 additions and 30 deletions
10
apps/web/declarations/i18next.d.ts
vendored
10
apps/web/declarations/i18next.d.ts
vendored
|
@ -4,15 +4,13 @@ import type emails from "@rallly/emails/locales/emails.json";
|
||||||
|
|
||||||
import type app from "../public/locales/en/app.json";
|
import type app from "../public/locales/en/app.json";
|
||||||
|
|
||||||
interface I18nNamespaces {
|
|
||||||
app: typeof app;
|
|
||||||
emails: typeof emails;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "i18next" {
|
declare module "i18next" {
|
||||||
interface CustomTypeOptions {
|
interface CustomTypeOptions {
|
||||||
defaultNS: "app";
|
defaultNS: "app";
|
||||||
resources: I18nNamespaces;
|
|
||||||
returnNull: false;
|
returnNull: false;
|
||||||
|
resources: {
|
||||||
|
app: typeof app;
|
||||||
|
emails: typeof emails;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 { TxKeyPath } from "../i18n/types";
|
||||||
|
|
||||||
import type { I18nNamespaces } from "../../declarations/i18next";
|
|
||||||
|
|
||||||
export const Trans = (props: {
|
export const Trans = (props: {
|
||||||
i18nKey: keyof I18nNamespaces["app"];
|
i18nKey: TxKeyPath;
|
||||||
defaults?: string;
|
defaults?: string;
|
||||||
values?: Record<string, string | number | boolean | undefined>;
|
values?: Record<string, string | number | boolean | undefined>;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
import type { Namespace } from "i18next";
|
|
||||||
|
|
||||||
import { defaultNS } from "@/i18n/settings";
|
import { defaultNS } from "@/i18n/settings";
|
||||||
|
|
||||||
import { initI18next } from "./i18n";
|
import { initI18next } from "./i18n";
|
||||||
|
|
||||||
export async function getTranslation(
|
export async function getTranslation(locale: string) {
|
||||||
locale: string,
|
const i18nextInstance = await initI18next(locale, defaultNS);
|
||||||
ns: Namespace = defaultNS,
|
|
||||||
) {
|
|
||||||
const i18nextInstance = await initI18next(locale, ns);
|
|
||||||
return {
|
return {
|
||||||
t: i18nextInstance.getFixedT(locale, Array.isArray(ns) ? ns[0] : ns),
|
t: i18nextInstance.getFixedT(locale, defaultNS),
|
||||||
i18n: i18nextInstance,
|
i18n: i18nextInstance,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
3
apps/web/src/i18n/types.ts
Normal file
3
apps/web/src/i18n/types.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import type app from "../../public/locales/en/app.json";
|
||||||
|
|
||||||
|
export type TxKeyPath = keyof typeof app;
|
8
packages/emails/i18next.d.ts
vendored
8
packages/emails/i18next.d.ts
vendored
|
@ -2,14 +2,12 @@ import "i18next";
|
||||||
|
|
||||||
import type emails from "./locales/en/emails.json";
|
import type emails from "./locales/en/emails.json";
|
||||||
|
|
||||||
interface I18nNamespaces {
|
|
||||||
emails: typeof emails;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "i18next" {
|
declare module "i18next" {
|
||||||
interface CustomTypeOptions {
|
interface CustomTypeOptions {
|
||||||
defaultNS: "emails";
|
defaultNS: "emails";
|
||||||
resources: I18nNamespaces;
|
resources: {
|
||||||
|
emails: typeof emails;
|
||||||
|
};
|
||||||
returnNull: false;
|
returnNull: false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ export type EmailContext = {
|
||||||
domain: string;
|
domain: string;
|
||||||
supportEmail: string;
|
supportEmail: string;
|
||||||
i18n: I18nInstance;
|
i18n: I18nInstance;
|
||||||
t: TFunction;
|
t: TFunction<"emails", undefined, "emails">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TemplateName = keyof EmailTemplates;
|
export type TemplateName = keyof EmailTemplates;
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
{
|
{
|
||||||
"extends": "@rallly/tsconfig/next.json",
|
"extends": "@rallly/tsconfig/next.json",
|
||||||
"compilerOptions": {
|
|
||||||
"strict": true,
|
|
||||||
"strictNullChecks": true,
|
|
||||||
"resolveJsonModule": true
|
|
||||||
},
|
|
||||||
"files": ["i18next.d.ts"],
|
"files": ["i18next.d.ts"],
|
||||||
"include": ["**/*.ts", "**/*.tsx"],
|
"include": ["**/*.ts", "**/*.tsx"],
|
||||||
"exclude": ["node_modules", ".react-email"]
|
"exclude": ["node_modules", ".react-email"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue