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

Extract Parser error with Array.map & join #250

Open FirmYn opened 2 years ago

FirmYn commented 2 years ago

Hi, There is an issue with the extract parser with this code:

  get text(): string {
    const status = this.selectedStatus();
    if (status.length) {
      return status 
        .map(s => this.translateService.instant(s))
        .join(', ');
    } else {
      return this.translateService.instant('DEFAULT_STATUS');
    }
  }

The JSON output for this is:

{
    ", ": "",
    "DEFAULT_STATUS": ""
}

It expected result was:

{
    "DEFAULT_STATUS": ""
}

Changing the code to this fix the issue:

  get text(): string {
    const status = this.selectedStatus();
    if (status.length) {
      const translatedStatus = selectedStatus.map(status =>
        this.translateService.instant(status)
      );
      return translatedStatus.join(', ');
    } else {
      return this.translateService.instant('DEFAULT_STATUS');
    }
  }

Also, this.selectedStatus() returns other keys that are marked elsewhere.