Getting started with Localization
31 Jan 20255 minutes to read
The Localization library in Syncfusion’s Angular UI Components enables you to display text content in languages other than English. This feature is essential for applications serving a global audience by providing a native language experience.
Loading translations
Translations can be loaded into your Angular application using the load
function from the @syncfusion/ej2-base
module. This function requires an object where language codes are keys, and the corresponding translation objects are values.
For instance, to load translations for English (en
) and French (fr
), the following implementation can be used:
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GridModule, GroupService, PageService } from '@syncfusion/ej2-angular-grids'
import { L10n, setCulture } from '@syncfusion/ej2-base';
import { Component, OnInit } from '@angular/core';
import { data } from './datasource';
import {PageSettingsModel } from '@syncfusion/ej2-angular-grids';
setCulture('de-DE');
L10n.load({
'de-DE': {
'grid': {
'EmptyRecord': 'Keine Aufzeichnungen angezeigt',
'GroupDropArea': 'Ziehen Sie einen Spaltenkopf hier, um die Gruppe ihre Spalte',
'UnGroup': 'Klicken Sie hier, um die Gruppierung aufheben',
'EmptyDataSourceError': 'DataSource darf bei der Erstauslastung nicht leer sein, da Spalten aus der dataSource im AutoGenerate Spaltenraster',
'Item': 'Artikel',
'Items': 'Artikel'
},
'pager':{
'currentPageInfo': '{0} von {1} Seiten',
'totalItemsInfo': '({0} Beiträge)',
'firstPageTooltip': 'Zur ersten Seite',
'lastPageTooltip': 'Zur letzten Seite',
'nextPageTooltip': 'Zur nächsten Seite',
'previousPageTooltip': 'Zurück zur letzten Seit',
'nextPagerTooltip': 'Zum nächsten Pager',
'previousPagerTooltip': 'Zum vorherigen Pager'
}
}
});
@Component({
imports: [
GridModule
],
providers: [GroupService, PageService],
standalone: true,
selector: 'app-root',
template: `<ejs-grid [dataSource]='data' [locale]='"de-DE"' [allowGrouping]='true' [allowPaging]='true' [pageSettings]='pageOptions' height='220px'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150></e-column>
<e-column field='ShipCity' headerText='Ship City' width=150></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
</e-columns>
</ejs-grid>`
})
export class AppComponent implements OnInit {
public data?: Object[];
public pageOptions?: PageSettingsModel;
ngOnInit(): void {
this.data = data;
this.pageOptions = { pageSize: 6 };
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Changing current locale
The current locale can be changed for all the Syncfusion Angular UI Components in your application by invoking setCulture
function with your desired culture name.
import { L10n, setCulture } from '@syncfusion/ej2-base';
L10n.load({
'fr-BE': {
'Button': {
'id': 'Numéro de commande',
'date': 'Date de commande'
}
}
});
setCulture('fr-BE');
Note: Before changing a culture globally, you need to ensure that locale text for the concerned culture is loaded through
L10n.load
function.