HenryLie / svelte-i18n-lingui

Use lingui for i18n in Svelte/Sveltekit projects
https://www.npmjs.com/package/svelte-i18n-lingui
MIT License
23 stars 2 forks source link

When deploying without `lingui extract`, placeholders in translated strings are not replaced #8

Open blinry opened 1 year ago

blinry commented 1 year ago

After running vite build and looking at the deployed version, translated strings for which lingui extract has not yet been run don't seem to have replaced placeholders. For example, they show up like this on the website: "Count: {0}"

In comparison, in the vite dev version, they show up correctly, like "Count: 0". So I'd expect this to happen in the deployed version, as well.

Can you reproduce this? Otherwise, I can also provide a minimal example!

And another question is whether this can/should be fixed. A workaround would be to always run lingui extract before vite build.

HenryLie commented 1 year ago

Hi @blinry, thanks for the report. I haven't tried building the bundle without extracting beforehand, but I'd say it's indeed expected to at least run lingui extract every time there is a new string so that the dictionary is updated and you can start filling in the translations. Do you have a use case for which you don't want to extract the strings before building/deploying them?

Since extraction is an important step in working with lingui, I'd suggest always running lingui extract, and set up some helpers to do this for you automatically on certain steps. I'd usually put it on a git pre-commit hook, and you can also have the hook cancel the commit if there are untranslated strings (which is usually the case if there are strings that haven't been extracted before.

ptmkenny commented 3 months ago

Lingui for React behaves the same way; you need to run lingui extract first. So if this was going to be fixed, it should be fixed in the main lingui repo, not the integration.