transloco icon indicating copy to clipboard operation
transloco copied to clipboard

Bug(selectTranslateObject): It doesn't load the file, missing translation

Open Leemonn opened this issue 3 years ago • 2 comments

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

Leemonn avatar Nov 16 '21 13:11 Leemonn

I also ran into this. I don't get any message about "missing translation", the subscription just returns the object key I requested.

elliottregan avatar Feb 24 '22 19:02 elliottregan

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.

zeroregard avatar Jun 28 '23 08:06 zeroregard