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

support for ngx-translate #26

Open thomseno opened 5 years ago

thomseno commented 5 years ago

The last release of ngx-translate-extract for extracting translatables using ngx-translate is almost two years old, so I thought maybe this project can fill the gap.

The extraction of HTML, TypeScript & Javascript should working out of the box, the "only" feature missing is the "pipe" pattern:

<table>
    <thead>
    <tr>
        <th>{{'BOOKINGS.passengers' | translate}}</th>
        <th>{{'BOOKINGS.children' | translate:params}}</th>
        <th [title]="'BOOKINGS.bookingDate' | translate">#</th>
    </tr>
    </thead>
</table>

("translate" is the getText keyword for extracting messages, param is a TypeScript variable)

What do you think? Probably requires a new HTMLExtractor...

lukasgeiter commented 5 years ago

The reason why I haven't implemented such an extractor already, is because of the potential complexity of such expressions. Your examples would be quite simple to parse but in some cases it might contain ternary conditionals and other more complex expressions.

However, it would be interesting to see if Angular exposes its internal parser in a way in which it could be used for this package.

thomseno commented 5 years ago

I understand.

The parser from ngx-translate-extract is available here pipe.parser.ts

Maybe this helps.