-
-
Notifications
You must be signed in to change notification settings - Fork 766
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
Is there a way to get t
function outside functional component, or without hook ?
#1437
Comments
Can you explain more? |
Yes I can explain
and i18n.t was undefined
I have a normal ts file that needs to translate some strings. |
Check the value of |
Why is the app not initializing then to create i18n, app is the first thing running, then importing this utility file.... Will check once more, but flow is like this, a page is importing the util file, and the page is imported by _app.tsx so i18n should exist at that time |
I checked sometimes i18n is not null other times null. Is there a way to listen for i18n status ? maybe by registering a callback event or something like that I traced how my util file is called, which tries to access
So first below is _app.ts called, then Header component then this one is including single/index.ts which exports one At this moment i18n is null, then after some seconds is not null anymore |
still can't get this work done |
@bryantobing12 import { i18n } from 'next-i18next'; // Import
i18n?.init() // Initialize i18n
i18n?.t('translate_key') // get something from your translation json file using current Language |
This does not work. |
@micktg did you manage to resolve this? we are facing the same issue |
I used https://github.com/JCQuintas/ni18n for this. |
for future reference, here is how i fixed it with async. `import i18next from "i18next"; const t_hook = (async ()=>{ export default t_hook;` |
I think we should reopen this issue. It seems that there is no good way to solve this problem. |
can you show how to use this particular library outside the component? |
Hi,
I was looking for a way to get
t
function outside functional component context or without using hook(as was described here #983) but at the moment could not find such.
I have a utils file utils.ts, and export there a dialog function, and need to add t func there to translate from common namespace
export const salert = new Alert(Swal, // need T function here);
How can I get t fn there
I tried this
but did not work
The text was updated successfully, but these errors were encountered: