Search results

Globalization

Globalization is the combination of adapting the component to various languages by means of parsing and formatting the date or number Internationalization, and also by adding cultural specific customizations and translating the text localization.

By default, the date format, week,time format ,month and meridian names are specific to the American English culture. It utilizes the Essential JavaScript 2 Internationalization package to parse and format the date object based on the culture by using the official UNICODE CLDR JSON data. It provides the loadCldr method to load culture specific CLDR JSON data.

  • Set the culture by using the locale property.

To go with the different culture other than English, follow the below steps.

  • Install the CLDR-Data package by using the below command (it installs the CLDR JSON data). To know more about CLDR-Data refer the CLDR-Data link.
npm install cldr-data --save

Once the package installed, you can find the culture specific JSON data under the location \node_modules\cldr-data.

  • Now use the loadCldr method to load the culture specific CLDR JSON data.

In ASP.NET MVC refer the culture files directly from \node_modules\cldr-data location. But in ASP.NET Core, the static file contents are should present under wwwroot folder. For this, manually copy the CLDR-Data from the node_modules folder and place inside the wwwroot folder and refer from the \wwwroot\cldr-data location as like the below code examples

Example for ASP.NET Core

function loadCultureFiles(name) {
        var files = ['ca-gregorian.json', 'numbers.json', 'timeZoneNames.json'];
        var loader = ej.base.loadCldr;
        var loadCulture = function (prop) {
            var val, ajax;
            ajax = new ej.base.Ajax(location.origin + location.pathname + '/../wwwroot/cldr-data/main/' + name + '/' + files[prop], 'GET', false);
            ajax.onSuccess = function (value) {
                val = value;
            };
            ajax.send();
            loader(JSON.parse(val));
        };
        for (var prop = 0; prop < files.length; prop++) {
            loadCulture(prop);
        }
    }

Example for ASP.NET MVC

    function loadCultureFiles(name) {
        var files = ['ca-gregorian.json', 'numbers.json', 'timeZoneNames.json'];
        var loader = ej.base.loadCldr;
        var loadCulture = function (prop) {
            var val, ajax;
            ajax = new ej.base.Ajax(location.origin + location.pathname + '/../node_modules/cldr-data/main/' + name + '/' + files[prop], 'GET', false);
            ajax.onSuccess = function (value) {
                val = value;
            };
            ajax.send();
            loader(JSON.parse(val));
        };
        for (var prop = 0; prop < files.length; prop++) {
            loadCulture(prop);
        }
    }

The Localization library allows you to localize default text content of the DateTimePicker. The DateTimePicker component has static text for today feature that can be changed to other cultures (Arabic, Deutsch, French, etc.) by defining the locale value and translation object.

Locale keywords Text
today Name of the button to choose Today date.
placeholder Hint to describe expected value in input element.
  • Before changing to a culture other than English, ensure that locale text for the concerned culture is loaded through load method of L10n class.
     var L10n = ej.base.L10n;
        L10n.load({
            'de': {
                'datetimepicker': { placeholder: "Wählen Sie ein Datum und eine Uhrzeit aus",
                 today:"heute"
                }
            }
        });

The following example demonstrates the DateTimePicker in German culture.

tagHelper
<ejs-datetimepicker id="datetimepicker"></ejs-datetimepicker>
		
<script>
    document.addEventListener('DOMContentLoaded', function () {
        datetimepicker = document.getElementById('datetimepicker').ej2_instances[0];
        var L10n = ej.base.L10n;
        L10n.load({
            'de': {
                'datetimepicker': { placeholder: 'Wählen Sie ein Datum und eine Uhrzeit aus',
                 today:'heute' }
            }
        });
        loadCultureFiles('de');
        datetimepicker.locale = 'de';
    });

    function loadCultureFiles(name) {
        var files = ['ca-gregorian.json', 'numbers.json', 'timeZoneNames.json'];
        if (name === 'ar') {
            files.push('numberingSystems.json');
        }
        var loader = ej.base.loadCldr;
        var loadCulture = function (prop) {
            var val, ajax;
             if (name === 'ar' && prop === files.length - 1) {
                ajax = new ej.base.Ajax(location.origin + location.pathname + '/../wwwroot/scripts/cldr-data/supplemental/' + files[prop], 'GET', false);
            } else {
                ajax = new ej.base.Ajax(location.origin + location.pathname + '/../wwwroot/scripts/cldr-data/main/' + name + '/' + files[prop], 'GET', false);
            }
            ajax.onSuccess = function (value) {
                val = value;
            };
            ajax.send();
            loader(JSON.parse(val));
        };
        for (var prop = 0; prop < files.length; prop++) {
            loadCulture(prop);
        }
    }

</script>

Right-To-Left

The DateTimePicker supports RTL (right-to-left) functionality for languages like Arabic and Hebrew to displays the text in the right-to-left direction. Use enableRtl property to set the RTL direction.

The following code example initialize the DateTimePicker component in Arabic culture and also explains how to set the localized text to the placeholder using load method of L10n class.

The following example demonstrates DateTimePicker in Arabic culture with right-to-left direction.

tagHelper
<ejs-datetimepicker id="datetimepicker" enableRtl=true></ejs-datetimepicker>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        datetimepicker = document.getElementById('datetimepicker').ej2_instances[0];
        var L10n = ej.base.L10n;
        L10n.load({
            'ar': {
              'datetimepicker': { placeholder: 'حدد التاريخ والوقت',
               today: 'اليوم' }
            }
        });
        loadCultureFiles("ar");
        datetimepicker.locale = 'ar';
    });

    function loadCultureFiles(name) {
        var files = ['ca-gregorian.json', 'numbers.json', 'timeZoneNames.json'];
        if (name === 'ar') {
            files.push('numberingSystems.json');
        }
        var loader = ej.base.loadCldr;
        var loadCulture = function (prop) {
            var val, ajax;
             if (name === 'ar' && prop === files.length - 1) {
                ajax = new ej.base.Ajax(location.origin + location.pathname + '/../wwwroot/scripts/cldr-data/supplemental/' + files[prop], 'GET', false);
            } else {
                ajax = new ej.base.Ajax(location.origin + location.pathname + '/../wwwroot/scripts/cldr-data/main/' + name + '/' + files[prop], 'GET', false);
            }
            ajax.onSuccess = function (value) {
                val = value;
            };
            ajax.send();
            loader(JSON.parse(val));
        };
        for (var prop = 0; prop < files.length; prop++) {
            loadCulture(prop);
        }
    }

</script>