Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't extract comments #89

Open
SeanHayes opened this issue Jan 26, 2022 · 6 comments · May be fixed by #101
Open

Can't extract comments #89

SeanHayes opened this issue Jan 26, 2022 · 6 comments · May be fixed by #101

Comments

@SeanHayes
Copy link

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
Copy link
Author

SeanHayes commented Jan 26, 2022

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
Copy link
Collaborator

Hi Sean,

Could you create a repo that reproduces this issue?

@markkdev
Copy link

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

@markkdev
Copy link

markkdev commented Oct 26, 2023

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

@alexanderwallin
Copy link
Collaborator

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

@markkdev
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants