Contents
- Loading translations
- See Also
Having trouble getting help?
Contact Support
Contact Support
Localization in Angular Combo box component
27 Apr 20244 minutes to read
The Localization library allows you to localize static text content of the
noRecordsTemplate and actionFailureTemplate properties according to the culture currently assigned to the ComboBox.
Locale key | en-US (default) |
---|---|
noRecordsTemplate | No records found |
actionFailureTemplate | The request failed |
Loading translations
To load translation object to your application, use load function of the L10n class.
In the following sample, French culture is set to the ComboBox and no data is loaded. Hence, the noRecordsTemplate
property displays its text in French culture initially, and if the sample is run offline, the actionFailureTemplate
property displays its text appropriately.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { ComboBoxModule } from '@syncfusion/ej2-angular-dropdowns'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, OnInit } from '@angular/core';
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { L10n } from '@syncfusion/ej2-base';
@Component({
imports: [
FormsModule, ReactiveFormsModule, ComboBoxModule,ButtonModule
],
standalone: true,
selector: 'app-root',
// specifies the template string for the ComboBox component
template: `<ejs-combobox id='comboelement' #samples [dataSource]='data' [query]='query' [fields]='fields' [placeholder]='text' [locale]='locale'></ejs-combobox>`
})
export class AppComponent implements OnInit {
constructor() {
}
//set the placeholder text in french to ComboBox input
public text: string = "Sélectionnez un élément";
// bind remotedata to showcase actionFailureTemplate in offline
public data: DataManager = new DataManager({
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Customers',
adaptor: new ODataV4Adaptor,
crossDomain: true
});
// map appropriate column
public fields: Object = { text: 'ContactName', value: 'CustomerID' };
// take 0 item to showcase noRecordsTemplate property
public query: Query = new Query().select(['ContactName', 'CustomerID']).take(0);
//set culture to ComboBox component
public locale: string = 'fr-BE';
ngOnInit(): void {
L10n.load({
'fr-BE': {
'dropdowns': {
'noRecordsTemplate': "Aucun enregistrement trouvé",
'actionFailureTemplate': "Modèle d'échec d'action"
}
}
});
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));