lukasgeiter / gettext-extractor

A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML.
MIT License
98 stars 21 forks source link

No extraction sometimes #55

Closed pooledge closed 2 years ago

pooledge commented 2 years ago

I've posted it in the svelte-specific fork, but quickly realisied I get same with a bare. Some strings do not get extracted as expected, so I've tried to narrow it down to the following:

<script lang="ts">
    import { __ } from '$lib/i18n';
</script>

<!-- These will be extracted: -->
<div>{@html __('More Settings')}</div>
<button type="button" aria-label="{__('I agree')}">{__('I agree')}</button>

<!-- These won't: -->
{__('Settings')}
<div>{__('Other Settings')}</div>
<button type="button">{__('I still agree')}</button>

Parser and config:

import { GettextExtractor, JsExtractors } from 'gettext-extractor';

let extractor = new GettextExtractor();

extractor
    .createJsParser([
        JsExtractors.callExpression('__', {
            arguments: {
                text: 0
            }
        })
    ])
    .parseFilesGlob('src/**/Test.svelte');

extractor.savePotFile('./src/translations/source.pot');
extractor.printStats();

Did I miss something in the config? Thanks in advance for looking into this!

lukasgeiter commented 2 years ago

Unfortunately svelte files are not supported. You say it's not a svelte specific problem, yet the example you show is clearly svelte code. I'm assuming the only reason some of them work is because the TypeScript parser tries to make the best of it and sometimes it works and sometimes it doesn't.

pooledge commented 2 years ago

Thank you, Lukas! So I'd be better off hacking into parser then, could you provide any special hints?

lukasgeiter commented 2 years ago

I would reopen your issue over at gettext-extractor-svelte, maybe someone there can help. Other than that, I don't have any hints sorry.