martinkr/next-export-i18n

Translation fails silently when the key contains a dot '.' character

zmilonas opened this issue · 1 comments

Hey,
firstly thanks so much for this package, saved me a headache.

As to the issue i can elaborate, add tests, reproducement scenarios and contribute later, but I want to point out that it seems to be when i tried using your package for some longer texts having them as keys, like full sentences, whenver there was a . in the key it would fail.

Example:

index.ts:

<p>{t('A long sentence with some words, divided with a comma')}</p>

<p>{t('A long sentence with some words. Divided with a dot')}</p>

gb.json:

{
  "A long sentence with some words, divided with a comma": "Comma translation",
  "A long sentence with some words. Divided with a dot": "Dot translation"
}

Outputs:

Comma translation
A long sentence with some words. Divided with a dot

While I expected:

Comma translation
Dot translation

The problem is especially concerning that there is no error message, not in the console, not anywhere about not finding the key, or that the key in the JSON contains what I might assume are disallowed characters. I also guess that the dot is reserved for drilling down the objects in the JSON, right? I didn't find that mentioned in the documentation and it left me confused.

Hi zmilonas,

Thank you for reaching out.

Yes, you refer nested keys with a dot: "nested.key" for {nested: { key: "value" }. If there is no value for a key, the module returns the key so you can see where you are missing a translation.

I updated the documentation to clarify this behaviour.

Cheers!