ast-i18n icon indicating copy to clipboard operation
ast-i18n copied to clipboard

handle params

Open sibelius opened this issue 5 years ago • 7 comments

Options (e.g. for pluralization, or adding context/screenshots for translators) are specified like this:

const thisManyApples = t('{user} ate {count} apples', {count: 3, user: '@sseraphini '})

sibelius avatar Feb 09 '19 21:02 sibelius

this could help https://gist.github.com/Munter/87ed1b35cf8a6f7c2e3d26ca7a618cea

we need more AST processing

sibelius avatar Feb 09 '19 23:02 sibelius

eslint rules

https://gist.github.com/Munter/87d476c490f6e6debccd02d5acd8e82a

sibelius avatar Feb 09 '19 23:02 sibelius

check here https://github.com/oliviertassinari/i18n-extract

sibelius avatar Feb 10 '19 01:02 sibelius

I think I almost have something working, but I have a question - why there is babel code that extracts resources and modifies code and there is jacodeshift script that only does the modification?

katilius avatar Mar 10 '19 08:03 katilius

Great question!

The Babel transformer is based on fbt, it run the transformer just to find all strings values in the code and generate the i18n key value dict, for now it will generate the dict in 18next format. It does not need to modify any code

The jscodeshift will run the same transform, but it will modify the code to the final code with i18n keys

sibelius avatar Mar 10 '19 09:03 sibelius

And maybe it would make sense to consolidate the two? For example if jscodeshift at the same time would write to some resource file as it modifies.

katilius avatar Mar 10 '19 09:03 katilius

not sure if we can do this using jscodeshift as it run all files in parallel, hard to consolidade all strings

but we can try

sibelius avatar Mar 10 '19 12:03 sibelius