laget-se / react-gettext-parser

Extracts translatable strings from JS(X) source code to POT files
Apache License 2.0
43 stars 27 forks source link

Can't extract comments #89

Open SeanHayes opened 2 years ago

SeanHayes commented 2 years ago

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.

SeanHayes commented 2 years ago

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.

alexanderwallin commented 1 year ago

Hi Sean,

Could you create a repo that reproduces this issue?

markkdev commented 1 year ago

+1 I'm also running into this issue. Any plans to investigate @alexanderwallin? Not sure if this still waiting on a reproducible repo?

markkdev commented 1 year ago

This looks like it's broken in .tsx. Can confirm it works in .ts files

alexanderwallin commented 11 months ago

@markkdev Can you check and see if the branch from #101 works for you?

markkdev commented 11 months ago

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.