synacor / preact-i18n

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

Are you aware of any nice, programmatic way to analyze the codebase and extract text to be translated? #24

Closed HenrikJoreteg closed 6 years ago

billneff79 commented 6 years ago

I am not aware of anything out of the box. It's a pretty difficult problem. I recently looked at eslint-plugin-m6web-i18n which seemed promising as an eslint plugin for React apps. It does a good job recognizing react nodes with text node children, but as of now can't ignore nodes like <Text/> to allow them to use fallback text like we do. I think a small pull request could fix that (or don't use fallback text) and that gets you a long way toward what you are looking for.

preact-i18n does provide a way to look at the running system and visually identify strings that aren't internationalized or that are, but are using the fallback text, by providing the mark attribute to <IntlProvider>. You can provide that programmatically, or you can add a parameter of intl=show to your browser's URL set that attribute: https://github.com/synacor/preact-i18n/blob/10c6749a3c469ddb90e00372233488c15af3b3d8/src/components/intl-provider.js#L5 https://github.com/synacor/preact-i18n/blob/10c6749a3c469ddb90e00372233488c15af3b3d8/src/components/intl-provider.js#L48-L50