-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Translate in .ts file -> Cannot perform operation, astro-i18n is not initialized. #68
Comments
your repo is private |
oh yes, sorry - corrected. |
This is happening because the typescript files runs before the middleware. // old
t("my_key")
// new
() => ("my_key") I will try to document this and add methods to be able to initialize |
I investigated a bit, the TS modules run before everything because of vite which apparently initializes every module before the file that imports it runs. |
Hi Alexandre, I changed the occurences (they were mostly in a link element, in the nav and the footer) and so it was only about an hour of work to change it from link.asd -> t(link.asd), and now it fully works again. |
I have a related problem here, the only difference is that we are using server side render as default output, any updates here @Alexandre-Fernandez ? Can you provide a workaround until you give us a permanent solution? |
@perinazzoo If you are using the translations in the template the workaround is using getters instead. Otherwise as of now there is no workaround, as explained before, even if the translations were loaded you wouldn't be able to access the current route's translations because This is not a simple fix, first I have to make sure that the library is initialized before the module runs, then I need to add a way to fetch a translation from any group/page (since the current route will be unknown in the module) and I will probably also need to make every call to the This issue is on my priority list for sure and I will fix it as soon as I can, however I'm very busy at the moment and I can't afford to work on this, if this is a deal-breaker I'm sorry but I can't help you at the moment. |
Describe the bug
I cannot load a translation from a .ts file - something the previous i18n implementation allowed.
Do I have to change this behaviour? Suggestions on how to do it?
I tried to find the minimum attack surface for my project - it is attached.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
It should work ;)
Mandatory reproduction repository
https://github.com/Nkay/i18n-bug-reproduce-2
The text was updated successfully, but these errors were encountered: