Localization in TypeScript Charts

Localization translates the Chart’s default text content (for example, zoom toolbar labels) into a target language. The translation is provided as a key/value object, loaded with L10n.load(), and then activated by setting the Chart’s locale property to the matching culture code.

Locale keys

The Chart uses the following keys when looking up translated strings. Each key is replaced by the value you supply in the translation object.

Locale key Default text
Zoom Zoom
ZoomIn ZoomIn
ZoomOut ZoomOut
Reset Reset
Pan Pan
ResetZoom Reset Zoom

Loading translations

Pass a translation object to L10n.load(). The object shape is { culture: { component: { key: 'translation' } } }, where component must match the component name (chart for the Chart control) and culture is the culture code you will assign to the Chart’s locale property.

After loading translations, set the locale property on the Chart to the same culture code used in L10n.load(). This binds the translations to the chart instance. For right-to-left languages such as Arabic and Hebrew, also set enableRtl: true on the chart.

For a complete list of L10n options, see the L10n class API.

The following example translates the zoom toolbar labels into Arabic:

import { Chart, ColumnSeries, DataLabel, Zoom } from '@syncfusion/ej2-charts';
Chart.Inject(ColumnSeries, DataLabel, Zoom);
import { L10n } from '@syncfusion/ej2-base';

let chartData: Object[] = [
    { x: 1900, y: 4, y1: 2.6 }, { x: 1920, y: 3.0, y1: 2.8 },
    { x: 1940, y: 3.8, y1: 2.6 }, { x: 1960, y: 3.4, y1: 3 },
    { x: 1980, y: 3.2, y1: 3.6 }, { x: 2000, y: 3.9, y1: 3 }
]
L10n.load({
    'ar-AR': {
        'chart': {
            ZoomIn: 'تكبير',
            ZoomOut: 'تصغير',
            Zoom: 'زوم',
            Pan: 'مقلاة',
            Reset: 'إعادة تعيين',
            ResetZoom: ' زومإعادة تعيين'
        },
    }
});
let chart: Chart = new Chart({
    primaryXAxis: {
        title: 'Year',
        edgeLabelPlacement: 'Shift'
    },
    primaryYAxis: {
        title: 'Sales Amount in Millions',
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        name: 'Product X', type: 'Column',
        marker: { dataLabel: { visible: true } }
    }, {
        dataSource: chartData,
        xName: 'x', yName: 'y1',
        name: 'Product Y', type: 'Column',
        marker: { dataLabel: { visible: true } }
    }],
    title: 'Average Sales Comparison',
    locale: 'ar-AR',
    enableRtl: true,
    zoomSettings: {
        enableMouseWheelZooming: true,
        enableDeferredZooming: true,
        enablePinchZooming: true,
        enableSelectionZooming: true
    },
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Troubleshooting

  • Translations are not applied: Confirm that the component key in the translation object matches the component name (chart for the Chart control) and that the locale property is set to the same culture code.
  • L10n is undefined in an ES5 (script-tag) setup: Make sure the ej2-base script is loaded before the chart scripts and the page scripts, and use the ej.base.L10n namespace.
  • RTL text does not render right-to-left: Set enableRtl: true on the Chart.

See also