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

These expressions are not detected #239

Open gbshbrosjo opened 3 years ago

gbshbrosjo commented 3 years ago

Hello Kim, Thanks for ngx-translate-extract! Great Work!

While examining carefully we found out that these kinds of expressions are not detected and extracted:

  1. It would be nice if conditional (ternary) operators (using only strings in both cases) are supported. So we could write <p translate>{{ switch ? "Move up" : "Move down" }}</p> (currently not detected) instead of <p>{{ switch ? ("Move up" | translate) : ("Move down" | translate) }}</p> (detected)

  2. In this very special scenario ngx-translate-extract won't find the word "Cuckoo": demo.component.ts

    
    import { Chart } from './chart.service';
    import { TranslateService } from '@ngx-translate/core';

@Component({ selector: 'app-demo', templateUrl: './demo.component.html', styleUrls: ['./demo.component.scss'] }) export class Demo {

constructor( protected translate: TranslateService ) { }

public chart: Chart = new Chart({ translate: this.translate });

public ngOnInit(): void { this.output = this.chart.getDescription(); } }


chart.service.ts
```javascript
import { BaseComponent } from './base.component';

export class Chart extends BaseComponent {

  constructor({ ...param }) {
    super(param);
  }

  public getDescription() {
    return this.translate.instant("Cuckoo");
  }

}

base.component.ts

import { TranslateService } from '@ngx-translate/core';

export abstract class BaseComponent {
  protected translate: TranslateService;

  protected constructor({
    translate }: any) {
    this.translate = translate;
  }

}
AmirSavand commented 3 years ago

I guess this could work for a shorter version of what's working.

<p>{{ (switch ? "Move up" : "Move down") | translate }}</p>