How to translate object parameter in typescript file ngx-translate

Refresh

2 weeks ago

Views

4 time

0

I have defined a Header array that I am using in multiple components in order to reuse the datatable column names:

  OrderHeaders = [
  { key: 'orderNumber', header: 'ORDER', display: true, type: 'string' },
  { key: 'totalPositions', header: 'POSITION', display: true, type: 'string' },
  { key: 'receiverName', header: 'RECEIVER', display: true, type: 'string' }];

All the headers ORDER, POSITION, RECEIVER are defined in the json files for each language.

I want to translate columns header using the ngx-translate library like this:

 Headers.forEach(elem => {  
     this.cols.push({ field: elem.key, header: translate.get(elem.header)});      
    });

This approach is not working for translating the headers and I don't want to repeat myself by writing the headers directly in the html/template defined columns for each used datatable.

Is there any hint for solving this?

0 answers