biesbjerg / ngx-translate-extract

Extract translatable (using ngx-translate) strings and save as a JSON or Gettext pot file
MIT License
524 stars 196 forks source link

Dynamic string in translate instant #254

Open Skaaala opened 2 years ago

Skaaala commented 2 years ago

Hello there,

I'm currently using ngx-translate-extract and found a problem with dynamic translations.

Let's say we have 2 variables

const a = 'First';
const b = 'Second';

and you want to use final translate string like const c = '${translate.instant(a)} ${translate.instant(b)}';

Everything works correctly and you can see that in variable c there is translated string 'First Second'. But when you will try to run ngx-translate-extract it will shows error:

We cannot extract variable values passed to TranslateService

because into translate.instant you put variable instead of string.

Is there any fix or workaround? I found only that when you use translate['instant'] it will works correctly and not extract it, but it is not elegant solution at all :)

Maybe there will be good feature to create some expected comment like // ngx-translate-extract prevent-next-line to prevent next line from beeing extracted.

Kind regards Jan