tolgee / tolgee-js

Tolgee JavaScript libraries monorepo
https://tolgee.io
MIT License
219 stars 24 forks source link

i18n backend error when translations are missing completely in namespace #3282

Closed Megamannen closed 6 months ago

Megamannen commented 6 months ago

This function can return a undefined and will cause an exception

const translations = await tolgee.loadRecord({
      language,
      namespace: ns,
  });

So this line crashes: https://github.com/tolgee/tolgee-js/blob/91fa105da2279e5e3317091ef816b88b5f0a3dd8/packages/i18next/src/tolgeeBackend.ts#L15

This is maybe the wanted behaviour, but I don't know if you want to solve it "upstream"

  callback(null, translations ? Object.fromEntries(translations) : []);
stepan662 commented 6 months ago

Hey, I think it's wanted behavior. Because i18next can have multiple backends and it tries to load that until it gets something else than undefined from the backend.

There can be case, where you want to search for data elsewhere when Tolgee doesn't have them. If I'd return empty array, I block the fallback, which is IMHO undesired.

stepan662 commented 6 months ago

But I guess it shouldn't throw an error, that I'll fix

Megamannen commented 6 months ago

Yeah, in that case something like

const translations = await tolgee.loadRecord({
          language,
          namespace: ns,
        });
        callback(null, translations ? Object.fromEntries(translations) : undefined);