Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct way to use i18n.t() inside index.ts files in React TypeScript application #2158

Closed
telam opened this issue Mar 11, 2024 · 3 comments
Closed

Comments

@telam
Copy link

telam commented Mar 11, 2024

// this ts error occurs only if resources are imported:

From the following file ^

// this ts error occurs only if resources are imported:
//   1) as const (ts file)
//   or
//   2) as interface (d.ts file)
// throws only with ts v5
// // @ts-expect-error
// i18next.t('inter', { valWrong: 'xx' });
@adrai
Copy link
Member

adrai commented Mar 11, 2024

?

@telam
Copy link
Author

telam commented Mar 11, 2024

Sorry, that was a horrible description.

Let me give you some more context. I am working on a React TypeScript application that also uses Vite. I've previously used i18next in a React JSX only application without issues. However, in the new project that I'm working on I have a handful of index.ts files that export routes for the main application that use the i18n.t() function for the titles of the routes. I'm sure it's something I'm doing wrong but I keep getting this warning: i18next: hasLoadedNamespace: i18next was not initialized because the i18n.t() is getting executed obviously before it's ready.

I came across the file after reading this issue: i18next/react-i18next#977

I believe my issue actually has something to do with the createBrowserRouter() in react router version 6.x.x. and the fact that it's initializing my routes before i18n is actually ready.

@telam telam closed this as completed Mar 11, 2024
@antonfrolovsky
Copy link

@telam you found solution with this problem? I catch the same behavior!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants