swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

How is the localization of the texts make. #1116

Open IngoManthey opened 7 years ago

IngoManthey commented 7 years ago

Hello, I read: Static messages in the table you can override for localization. emptyMessage: 'No data to display', totalMessage: 'total'

I try: import { NgxDatatableModule } from '@swimlane/ngx-datatable';

ngOnInit() { NgxDatatableModule. but there are no emptyMessage or totalMessage properties for change the text.

Thanks for your help.

regards

jeroenwijdemans commented 6 years ago

The messages are bound to a field which by default is called messages. This object has emptyMessage etc as fields. These are read by the ngx-datatable.

You can override this default messages as such:

  <ngx-datatable
    [messages]="my_messages"

you can then populate the object in the component:

  my_messages = {
    'emptyMessage': '',
    'totalMessage': ''
  };

  constructor(private translate: TranslateService) {
    translate.get('LIST_TOTAL', {value: ''})
      .subscribe((res: string) => this.my_messages.totalMessage = res);
    translate.get('LIST_NO_RESULTS', {value: ''})
      .subscribe((res: string) => this.my_messages.emptyMessage = res);
  }
}

where LIST_TOTAL is a key in the messages

jeroenwijdemans commented 6 years ago

Even better, it can be done in the markup. See: https://github.com/swimlane/ngx-datatable/issues/589#issuecomment-300906484

julkue commented 3 years ago

@jeroenwijdemans Your example only applies to ngx-datatable, it doesn't work that way with Angular's built-in i18n (that I'm using). We'd need to have a DOM element to apply the i18n directive on it.