transloco
transloco copied to clipboard
Bug(selectTranslateObject): It doesn't load the file, missing translation
Is there an existing issue for this?
- [X] I have searched the existing issues
Which Transloco package(s) are the source of the bug?
Transloco
Is this a regression?
No
Current behavior
Right now if you use selectTranslateObject
for a file that has not been loaded yet you get "missing translation".
The doc says:
selectTranslateObject() Load the translation file (if not loaded yet) and behaves the same as translateObject. The only difference is that this method returns an observable to which you can subscribe.
The subscribe is executed and no translation file is loaded.
Expected behavior
It should load the file if it isn't loaded.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/ngneat-transloco-gt9vdw?file=src%2Fapp%2Fapp.module.ts
Transloco Config
No response
Please provide the environment you discovered this bug in
No response
Browser
No response
Additional context
No response
I would like to make a pull request for this bug
No
I also ran into this. I don't get any message about "missing translation", the subscription just returns the object key I requested.
As of 4.3.0 this is still a bug. If you supply a scope in your providers:
{
provide: TRANSLOCO_SCOPE,
useValue: {
scope: 'myScope',
loader: translocoScopeLoader((language: string) => {
console.log(`loaded language ${language}`);
return import(`./i18n/${language}.json`);
}),
},
},
It seems that on the first load attempt you get missing translation for XYZ
.
Then after a while I get the console log loaded language
but I will have to manually retry fetching the translation or use the events$
.
I think the expected behaviour of the transloco directive, pipe and selectTranslateObject
is that it should wait for importing the language of the specified scope. So when I query for the key myScope.myPage.myTitle
you can infer the scope from the first part of the key.
If anyone knows of any workarounds or hacks, that would be great.