Search results

Globalization

Globalization is the combination of internalization and localization. You can adapt the component to various languages by parsing and formatting the date or number Internationalization and also add culture specific customization and translation to the text localization.

By default, DateRangePicker date format 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 the culture specific CLDR JSON data. 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 all the CLDR JSON data). To known 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, import the installed CLDR JSON data into the app.ts file. To import JSON data we need to install the JSON plugin loader. Here we have used the systemJS JSON plugin loader.
npm install systemjs-plugin-json --save-dev
  • Once the package installed, you can find the culture specific JSON data under the location \node_modules\cldr-data.

  • Now import the installed CLDR JSON data into the app.ts file. To import JSON data we need to install the JSON plugin loader. Here we have used the SystemJS JSON plugin loader.

npm install systemjs-plugin-json --save-dev
  • Once installed, configure the system.config.js configuration settings as like below to map the systemjs-plugin-json loader.
/**
 * System configuration for React samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
System.config({
    paths: {
        'npm:': './node_modules/',
        'syncfusion:': 'npm:@syncfusion/'

    },
    map: {
        app: 'app',
        //Syncfusion packages mapping
      "@syncfusion/ej2-base": "syncfusion:ej2-base/dist/ej2-base.umd.min.js",
      "@syncfusion/ej2-data": "syncfusion:ej2-data/dist/ej2-data.umd.min.js",
      "@syncfusion/ej2-calendars": "syncfusion:ej2-calendars/dist/ej2-calendars.umd.min.js",
      "@syncfusion/ej2-react-base": "syncfusion:ej2-react-base/dist/ej2-react-base.umd.min.js",
      "@syncfusion/ej2-react-calendars": "syncfusion:ej2-react-calendars/dist/ej2-react-calendars.umd.min.js",
      "@syncfusion/ej2-inputs": "syncfusion:ej2-inputs/dist/ej2-inputs.umd.min.js",
      "@syncfusion/ej2-buttons": "syncfusion:ej2-buttons/dist/ej2-buttons.umd.min.js",
      "@syncfusion/ej2-splitbuttons": "syncfusion:ej2-splitbuttons/dist/ej2-splitbuttons.umd.min.js",
      "@syncfusion/ej2-lists": "syncfusion:ej2-lists/dist/ej2-lists.umd.min.js",
      "@syncfusion/ej2-popups": "syncfusion:ej2-popups/dist/ej2-popups.umd.min.js",
      "cldr-data": 'npm:cldr-data',
      "plugin-json": "https://cdnjs.cloudflare.com/ajax/libs/systemjs-plugin-json/0.3.0/json.min.js"
    },
    meta: {
        '*.json': { loader: 'plugin-json' }
    },
    packages: {
        'app': { main: 'app', defaultExtension: 'js' },
        'cldr-data': { main: 'index.js', defaultExtension: 'js' }
    }
});
}
System.import('app');
  • Now use the loadCldr method to load the culture specific CLDR JSON data from the installed location to app.ts file as like the below code example.
import { loadCldr } from "@syncfusion/ej2-base";

declare var require: any;

loadCldr(
  require("cldr-data/main/de/numbers.json"),
  require("cldr-data/main/de/ca-gregorian.json"),
  require("cldr-data/supplemental/numberingSystems.json"),
  require("cldr-data/main/de/timeZoneNames.json")
);

The Localization library allows you to localize default text content of the DateRangePicker. The DateRangePicker 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
placeholder Hint to describe expected value in input element.
startLabel Label to represent the start date.
endLabel Label to represent the end date.
applyText Text present in the apply button.
cancelText Text present in the cancel button.
selectedDays Text to represent selected days.
days Text represents days.
customRange Text present in the custom range button in presets container.
  • Before changing to a culture other than English, ensure that locale text for the concerned culture is loaded through load method of L10n class.
//Load the L10n, loadCldr from ej2-base
import { loadCldr, L10n } from "@syncfusion/ej2-base";

//load the locale object to set the localized placeholder value
L10n.load({
    'de': {
        'daterangepicker': {
          placeholder: 'Wählen Sie einen Bereich aus',
          startLabel: 'Wählen Sie Startdatum',
          endLabel: 'Wählen Sie Enddatum',
          applyText: 'Sich bewerben',
          cancelText: 'Stornieren',
          selectedDays: 'Ausgewählte Tage',
          days: 'Tage',
          customRange: 'benutzerdefinierten Bereich'
        }
    }
});
  • Set the culture by using the locale property.

The following example demonstrates the DateRangePicker in German culture.

Source
Preview
index.tsx
index.html
import * as React from "react";
import * as ReactDOM from "react-dom";
//Load the L10n, loadCldr from ej2-base
import { loadCldr, L10n } from '@syncfusion/ej2-base';
import { DateRangePickerComponent } from '@syncfusion/ej2-react-calendars';

//load the CLDR data files.
import * as numberingSystems from './numberingSystems.json';
import * as gregorian from './ca-gregorian.json';
import * as numbers from './numbers.json';
import * as deTimeZoneNames from './timeZoneNames.json';

loadCldr(numberingSystems, gregorian, numbers, deTimeZoneNames);

L10n.load({
    'de': {
        'daterangepicker': {
    placeholder: 'Wählen Sie einen Bereich aus',
    startLabel: 'Wählen Sie Startdatum',
    endLabel: 'Wählen Sie Enddatum',
    applyText: 'Sich bewerben',
    cancelText: 'Stornieren',
    selectedDays: 'Ausgewählte Tage',
    days: 'Tage',
    customRange: 'benutzerdefinierten Bereich'
    }
    }
});
//import the daterangepicker component
class App extends React.Component<{}, {}> {
    render() {
        return <DateRangePickerComponent id="daterangepicker" locale='de'/>
    }
};
ReactDOM.render(<App />, document.getElementById('element'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React DateRangePicker</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-lists/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-calendars/styles/material.css" rel="stylesheet" />
    <link href="styles.css" rel="stylesheet" />
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.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='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>

</html>

Right-To-Left

The DateRangePicker supports right-to-left functionality for languages like Arabic, Hebrew, etc. To display the text in the right-to-left direction, use enableRtl property.

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

Source
Preview
index.tsx
index.html
import * as React from "react";
import * as ReactDOM from "react-dom";
//Load the L10n, loadCldr from ej2-base
import { loadCldr, L10n } from '@syncfusion/ej2-base';
import { DateRangePickerComponent } from '@syncfusion/ej2-react-calendars';

//load the CLDR data files.
import * as numberingSystems from './numberingSystems.json';
import * as gregorian from './ca-gregorian.json';
import * as numbers from './numbers.json';
import * as heTimeZoneNames from './timeZoneNames.json';

loadCldr(numberingSystems, gregorian, numbers, heTimeZoneNames);

L10n.load({
    'he': {
        'daterangepicker': { placeholder: 'בחר טווח',
        startLabel: 'תווית התחלה',
        endLabel: 'ח',
        applyText: 'להחיל טקסט',
        cancelText: 'בטל טקסט',
        selectedDays: 'ימים נבחרים',
        days: 'أימים',
        customRange: 'טווח מותאם אישית'
        }

    }
});
//import the datrangeepicker component
class App extends React.Component<{}, {}> {

    private rtl:boolean=true;

    render() {
        return <DateRangePickerComponent id="daterangepicker" locale='he' enableRtl={this.rtl} />
    }
};
ReactDOM.render(<App />, document.getElementById('element'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React DateRangePicker</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-lists/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-calendars/styles/material.css" rel="stylesheet" />
    <link href="styles.css" rel="stylesheet" />
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.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='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>

</html>

Date Format

Date format is a way of representing the start date, end date strings in different string format in the textbox.

By default, the DateRangePicker’s start and end date string format is based on the culture. You can also set the own custom format by using the format property.

Once the date format property has been defined it will be common to all the cultures.

To know more about the date format standards, refer to the Internationalization Date Format section.

The following example demonstrates the DateRangePicker with the custom format (yyyy-MM-dd). Also, here the separator of the date values is changed to string “to”.

Source
Preview
index.tsx
index.html
import * as React from "react";
import * as ReactDOM from "react-dom";
//import the daterangepicker component
import { DateRangePickerComponent } from '@syncfusion/ej2-react-calendars';
class App extends React.Component<{}, {}> {
    render() {
        return <DateRangePickerComponent id="daterangepicker"  format='yyyy-MM-dd' separator='to' placeholder='Select a range' />
    }
};
ReactDOM.render(<App />, document.getElementById('element'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React DateRangePicker</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-lists/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-calendars/styles/material.css" rel="stylesheet" />
    <link href="styles.css" rel="stylesheet" />
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.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='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>

</html>