valor-software / ng2-table

Simple table extension with sorting, filtering, paging... for Angular2 apps
http://valor-software.github.io/ng2-table/
MIT License
554 stars 336 forks source link

i18n doesn't work in filter inputs placeholders #596

Open jualoppaz opened 6 years ago

jualoppaz commented 6 years ago

Hi!

I'm introducing i18n in my ng-table with ngx-translate library.

When I change language by this:

this.translate.use(lang)

all texts are translated but filter inputs placeholders.

By the moment, the only way that allows me implement this feature is handling the language change and setting manually the texts:


// Previous code
let column1 = {
    name: 'first_name',
    sort: false,
    filtering: {
        filterString: '',
        placeholder: ''
    }
};

let column2 = {
    name: 'last_name',
    sort: false,
    filtering: {
        filterString: '',
        placeholder: ''
    }
};

let column3 = {
    name: 'email',
    sort: false,
    filtering: {
        filterString: '',
        placeholder: ''
    }
};

... // More code

// Important code
this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
    Observable.forkJoin(
          this.translate.get('List.Filter.First Name'),
          this.translate.get('List.Filter.Last Name'),
          this.translate.get('List.Filter.Email'),
    ).subscribe(result => {
          column1['filtering']['placeholder'] = result[0];
          column2['filtering']['placeholder'] = result[1];
          column3['filtering']['placeholder'] = result[2];

          this.columns = [column1, column2, column3];

          this.config = {
              paging: true,
              sorting: { columns: this.columns },
              filtering: { filterString: '' },
              className: ['table-striped', 'table-bordered']
        };
    });
});

Is there any way for translate filter inputs placeholders without handling language change event?

Thank you so much.