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

Can't extract from angular template component input attributes #31

Open konuch opened 5 years ago

konuch commented 5 years ago

I have the following angular template:

<div [myAngularInput]="__('Click to Import')">{{__('Import')}}</div>

The 'Import' string is successfully extracted using your lib, but the 'Click to Import' text is ignored. I assume this happens because the latter is not enclosed in double curly braces. Is there a way we could make this work?

Thanks in advance.

This is my core extractor code:

const ALLOWED_METHODS = ['[this].__', '__', '[this].translate.getInstant', 'TranslateService.getInstant'];

let extractor = new GettextExtractor();

extractor
    .createJsParser([
        JsExtractors.callExpression(ALLOWED_METHODS, {
            arguments: {
                text: 0,
                context: 1
            }
        }),
        JsExtractors.callExpression(ALLOWED_METHODS, {
            arguments: {
                text: 1,
                textPlural: 2,
                context: 3
            }
        })
    ])
    .parseFilesGlob('./src/app/**/*.@(js|jsx|ts|html)');
lukasgeiter commented 5 years ago

The fact that 'Import' is extracted is actually kind of surprising to me because you're effectively running HTML through the TypeScript parser. My guess is that the parser treats the HTML as JSX and is therefore able to find code that's contained within curly braces.

Unfortunately extracting such messages is not supported at the moment. The good news is that the next major release will include full support for angular templates out of the box. This includes your example. I will update this issue as soon as the release is out.

jotoeri commented 3 years ago

Hey @lukasgeiter,

slight and polite ping! 🙈 Any news on your rewrite? On nextcloud-vue we have similar problems with webpack & vue: nextcloud-vue/SettingsSection.vue#L51

Greets! 🙂 Jonas

lukasgeiter commented 3 years ago

@jotoeri Thanks for your interest!

I'm sorry that the rewrite is taking longer than expected. For a quite a while I was not able to work on the project at all. Now I'm back at it though and making steady progress... Thank you for your patience 🙏

sorinfratila commented 3 years ago

Hi @lukasgeiter , any news on updates about this new release to support angular template ?

lukasgeiter commented 3 years ago

Hi @sorinfratila!

Sorry, I don't have any news at this time. I'm currently unable to spend time on the project and don't want to make any promises. I'll let you know once that changes. Thanks for understanding.