Translate dropdown options

UI Components for Angular
Post Reply
AngieSp
Posts: 1
Joined: 18 Mar 2019, 15:52

18 Mar 2019, 15:55

I use PrimeNG v5 and I want to translate the oprions of a dropdown.

this.sortOptions = [
{ label: 'All', value: 'name' },
{ label: 'Enabled', value: '!enabled' },
{ label: 'Not enabled', value: 'enabled' }
];

How can I translate the labels?

geza.tomboly
Posts: 2
Joined: 08 May 2018, 14:25

02 Apr 2019, 15:47

If you use ngx-translate:

1. You have to write your tranlsation keys in your options variable:

this.sortOptions = [
{ label: 'TRANSLATE.FOO', value: 'name' },
{ label: 'TRANSLATE.BOO': '!enabled' },
{ label: 'TRANSLATE.KOO', value: 'enabled' }
];

2. Templating your p-dropDown
<p-dropdown
[(ngModel)]="choosedOption"
[options]="sortOptions ">
<ng-template pTemplate="item" let-item>
{{item.label | translate}}
</ng-template>
<ng-template let-selectedItem pTemplate="selectedItem">
{{item.selectedItem | translate}}
</ng-template>
</p-dropdown>

geza.tomboly
Posts: 2
Joined: 08 May 2018, 14:25

02 Apr 2019, 15:47

If you use ngx-translate:

1. You have to write your tranlsation keys in your options variable:

this.sortOptions = [
{ label: 'TRANSLATE.FOO', value: 'name' },
{ label: 'TRANSLATE.BOO': '!enabled' },
{ label: 'TRANSLATE.KOO', value: 'enabled' }
];

2. Templating your p-dropDown
<p-dropdown
[(ngModel)]="choosedOption"
[options]="sortOptions ">
<ng-template pTemplate="item" let-item>
{{item.label | translate}}
</ng-template>
<ng-template let-selectedItem pTemplate="selectedItem">
{{item.selectedItem | translate}}
</ng-template>
</p-dropdown>

anhtuan96a8
Posts: 1
Joined: 10 Mar 2020, 06:47

10 Mar 2020, 06:49

<p-dropdown [(ngModel)]="type" [options]="dropdownType ">
<ng-template pTemplate="item" let-item>
{{item.label | translate}}
</ng-template>
<ng-template pTemplate="selectedItem" let-item>
{{item.label | translate}}
</ng-template>
</p-dropdown>
;) ;) ;)

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 18 guests