react-gettext-parser
react-gettext-parser copied to clipboard
Can't extract comments
Using react-gettext-parser 1.16.0
Snippet form my gulpfile.js
process.chdir(`${localesDir}templates/LC_MESSAGES/`);
gulp.src(paths.scripts.src.map((path) => {
return `../../../${path}`;
}))
.pipe(reactGettextParser({
output: 'messages.pot',
funcArgumentsMap: {
gettextSub: ['msgid', 'comment'],
gettextSubComponent: ['msgid'],
gettext: ['msgid'],
dgettext: [null, 'msgid'],
ngettext: ['msgid', 'msgid_plural'],
dngettext: [null, 'msgid', 'msgid_plural'],
pgettext: ['msgctxt', 'msgid'],
dpgettext: [null, 'msgctxt', 'msgid'],
npgettext: ['msgctxt', 'msgid', 'msgid_plural'],
dnpgettext: [null, 'msgid', 'msgid_plural'],
},
}))
.pipe(gulp.dest('.'))
.on('error', reject)
.on('end', resolve);
Snippet of code I'm trying to translate:
// Translators: alt img text for a flag icon. This icon is used to allow users to flag content as being inappropriate.
const altText = gettextSub('flag icon', 'a comment');
Neither "alt img text..." or "a comment" is extracted to my .pot file.
In parse.js CallExpression -> enter I logged console.log('parent.leadingComments', parent.leadingComments); and it's always undefined.
If I log blocks instead, it gets the comment param:
block {
msgctxt: '',
msgid: 'flag icon',
msgstr: [ '' ],
comments: { reference: [], extracted: [] },
comment: 'a comment'
}
It gets the comment, but it's still not in the .pot file.
Hi Sean,
Could you create a repo that reproduces this issue?
+1 I'm also running into this issue. Any plans to investigate @alexanderwallin? Not sure if this still waiting on a reproducible repo?
This looks like it's broken in .tsx. Can confirm it works in .ts files
@markkdev Can you check and see if the branch from #101 works for you?
Hi @alexanderwallin ,
I ran a few tests on tsx files to extract comments. Here's what I'm seeing.
export default function GettextParserExample({ text }: Props) {
const { gettext, pgettext } = useContext(AppContext);
// Translators: test123
const withTranslatorComments = pgettext('ignore-me-test', 'gettextparserexample');
return (
<div className={styles.main}>
<p>
{
// Translators: test456
gettext('gettextparserexample')
}
</p>
{/* // Translators: test789 */}
<p>{gettext('gettextparserexample')}</p>
<h2>With Context: {withTranslatorComments}</h2>
</div>
);
}
My output file is only able to extract test456. The other two tests are not included.