Skip to content

Commit

Permalink
Changed type of options in translate function of i18nProvider
Browse files Browse the repository at this point in the history
Example with `options: any` gives me the following error:

```
Type '(key: string, options?: any) => string | TFunctionDetailedResult<string, any>' is not assignable to type 'TranslateFunction'.
  Type 'string | TFunctionDetailedResult<string, any>' is not assignable to type 'string'.
    Type 'TFunctionDetailedResult<string, any>' is not assignable to type 'string'.ts(2322)
```

I found solution in a following file that fixes the error:

https://github.com/Fgruntjes/WFK-Finance/blob/7b6c817b913f89db6197c705d34e260aaf7ed726/frontend/src/i18n-provider/useI18nProvider.ts#L5
  • Loading branch information
bzhn committed Apr 19, 2024
1 parent 815c445 commit 5bb5e87
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions documentation/docs/guides-concepts/i18n/index.md
Expand Up @@ -131,13 +131,15 @@ import type { I18nProvider } from "@refinedev/core";
import { Refine } from "@refinedev/core";
// highlight-next-line
import { useTranslation } from "react-i18next";
// highlight-next-line
import { $Dictionary } from "i18next/typescript/helpers";

const App: React.FC = () => {
// highlight-start
const { t, i18n } = useTranslation();

const i18nProvider: I18nProvider = {
translate: (key: string, options?: any) => t(key, options),
translate: (key: string, options?: $Dictionary<unknown>) => t(key, options),
changeLocale: (lang: string) => i18n.changeLanguage(lang),
getLocale: () => i18n.language,
};
Expand Down Expand Up @@ -276,6 +278,7 @@ import { Refine, Resource } from "@refinedev/core";
import { ThemedLayoutV2 } from "@refinedev/antd";

import { useTranslation } from "react-i18next";
import { $Dictionary } from "i18next/typescript/helpers";

import "./i18n";

Expand All @@ -286,7 +289,7 @@ const App: React.FC = () => {
const { t, i18n } = useTranslation();

const i18nProvider = {
translate: (key: string, options?: any) => t(key, options),
translate: (key: string, options?: $Dictionary<unknown>) => t(key, options),
changeLocale: (lang: string) => i18n.changeLanguage(lang),
getLocale: () => i18n.language,
};
Expand Down

0 comments on commit 5bb5e87

Please sign in to comment.