Closed tpoisseau closed 1 year ago
Hey, I think this is not a bug. But I guess it's a bit confusing.
Tolgee doesn't load language automatically when you call t
with the language property. It is stated in docs, that you have to load the language yourself. It will only override the current language set in tolgee and look at the cache.
Since the fallback language is set to en
if the translation is not present it will fallback to english. So if the French is not loaded, it will display english.
Hello,
So I think the wording of the documentation is unclear. My understanding of doc was tolgee will loadRecord if needed. And I thought it's a handy approach.
As a user of tolgee api, I think I should not have to worry about the cache (and advanced features) of tolgee, when I use the basic api to translate. So my suggestion to you is to take care of this usage so auto loadRecord if needed.
If for you the API is good like this, your product your rules and no problem, but please at least improve the wording of documentation. maybe something like
You have to load the language translations manually with tolgee.loadRecord.
The thing with auto loading is that it's not ready right away, so you would still had to solve the loading state in your app. Otherwise for a brief moment tolgee would display invalid translations anyway (english in case of fallback or just key names). So this is kinda design decision to force you to solve this yourself.
I was considering an edge case, because usually you have whole your app in one language and only rarely you need simultaneously display multiple languages, so it was considered ok, to keep it a bit more "manual".
I'll try to improve the docs about this.
Thank you
Hello,
You'll find a complete reproduce bug example here :
https://stackblitz.com/edit/gpbse5j-tolgee-language-param-wycsuw?file=src%2FApp.tsx
When you setup language option in
t()
or<T />
and this language is not cached by tolgee yet, it display the translation in language from tolgee context.My workaround is a hook calling
tolgee.loadRecord
in components where I need to display some translations from an entity language parameter. but it's quite annoying.SDK should take care of language param and call loadRecord if needed (as explained in doc)
https://tolgee.io/js-sdk/api/core_package/tolgee#t
Best regards,