synacor / preact-i18n

Simple localization for Preact.
BSD 3-Clause "New" or "Revised" License
205 stars 18 forks source link

Feature Request: generate en.json from fallback text #44

Open jliebrand opened 4 years ago

jliebrand commented 4 years ago

Perhaps this is already possible? But I'd like to have an en.json to give to translators so they can generate translations. Right now, that means copying the fallback text in to en.json but I dont like the fact the Fallback and en.json could get out of sync.

Is there anyway to generate the en.json from the fallback text? Perhaps by using the eslint plugin somehow?

jliebrand commented 4 years ago

Also, on a similar note - I'm using the fallback for english and not actually using en.json. The reason is that it would otherwise duplicate the amount of data the client needs to pull down.

The options I see are:

  1. use en.json and no fallback text - but this makes the jsx hard to read
  2. use fallback but no en.json - but this make pluralisation hard/impossible?

What is the recommended route here?

pl12133 commented 4 years ago

I think the original issue could be accomplished with a codemod that extracts all JSXText nodes inside of Text components out to a json file. That would be handy to have as a separate tool.

As for the issues of best practices with fallback text, I have found that after supporting more than 1 language I avoid using fallback text entirely because it makes it easier to end up with untranslated strings in the JSON language files, as well as the reasons you mentioned.