fs.readFile(`${translationDir}${baseLanguage}.json`, "utf8", (_, fileStr) => {
const keys = Object.keys(JSON.parse(fileStr));
- const data = `import * as i18n from "i18next";
-
-type I18nKeys =
-${keys.map(key => ` | "${key}"`).join("\n")};
+ const data = `import { i18n } from "i18next";
declare module "i18next" {
- export interface TFunction {
+ export type I18nKeys =
+${keys.map(key => ` | "${key}"`).join("\n")};
+
+ export interface TFunctionTyped {
// basic usage
<
TResult extends TFunctionResult = string,
- TInterpolationMap extends object = StringMap
+ TInterpolationMap extends Record<string, unknown> = StringMap
>(
key: I18nKeys | I18nKeys[],
options?: TOptions<TInterpolationMap> | string
// overloaded usage
<
TResult extends TFunctionResult = string,
- TInterpolationMap extends object = StringMap
+ TInterpolationMap extends Record<string, unknown> = StringMap
>(
key: I18nKeys | I18nKeys[],
defaultValue?: string,
options?: TOptions<TInterpolationMap> | string
): TResult;
}
+
+ export interface i18nTyped extends i18n {
+ t: TFunctionTyped;
+ }
}
`;
-import i18next from "i18next";
+import i18next, { i18nTyped } from "i18next";
import { getLanguage } from "./utils";
import { en } from "./translations/en";
import { el } from "./translations/el";
interpolation: { format },
});
-export { i18next as i18n, resources };
+export const i18n = i18next as i18nTyped;
+
+export { resources };