Globalization is the combination of internationalization and localization. You can adapt the component to
various languages by means of parsing and formatting the date or
number internationalization
, and also add
culture specific customization and translation to the text
localization
.
By default, TimePicker time 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 culture specific CLDR JSON data. To go with the different culture other
than English
, follow the steps below.
CLDR-Data
package by using the following command (it installs all the CLDR JSON data). To
known more about CLDR-Data refer the CLDR-Data
link.npm install cldr-data --save
Once the package is installed, you can find the culture
specific JSON data under the location \node_modules\cldr-data
.
Import the installed CLDR JSON data into the app.ts
file.
Use the loadCldr
method
to load the culture specific CLDR JSON data
from the installed location to app.ts
file.
TimePicker displayed Sunday
as the first day of week based on default culture (“en-US”). If you want to display the TimePicker with loaded culture’s first day of week, you need to import weekdata.json
file from the cldr-data/suppemental
as given in the code example.
import { loadCldr } from '@syncfusion/ej2-base';
import { loadCldr } from "@syncfusion/ej2-base";
import * as gregorian from 'cldr-data/main/de/ca-gregorian.json';
import * as numbers from 'cldr-data/main/de/numbers.json';
import * as numberingSystems from 'cldr-data/supplemental/numberingSystems.json';
loadCldr(numberingSystems, gregorian, numbers);
if you are facing the error
/node_modules/cldr-data/main/de/*.json (1,1): unused expression, expected an assignment or function call
when you are adding the json files to render the culture sample, then add the below configuration in yourtslint.json
file
"linterOptions": {
"exclude": [
"*.json",
"**/*.json"
]
}
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': {
'timepicker': { placeholder: 'Wählen Sie Zeit'}
}
});
locale
property. In the following code example, the DateTimePicker is initialized
in German
culture with
corresponding localized text.The following example demonstrates the TimePicker in German
culture.
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 the ripple effect
import { enableRipple } from '@syncfusion/ej2-base';
//import the timepicker
import { TimePickerComponent } from '@syncfusion/ej2-react-calendars';
// enable ripple effect
enableRipple(true);
//load the CLDR data files.
// Here we have referred local json files for preview purpose
import * as numberingSystems from './numberingSystems.json';
import * as gregorian from './ca-gregorian.json';
import * as numbers from './numbers.json';
loadCldr(numberingSystems, gregorian, numbers);
L10n.load({
'de': {
'timepicker': { placeholder: 'Wählen Sie Zeit' }
}
});
//import the timepickercomponent
class App extends React.Component<{}, {}> {
render() {
return <TimePickerComponent id="time" locale='de'/>
}
};
ReactDOM.render(<App />, document.getElementById('timer'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React TimePicker</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-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-lists/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-react-calendars/styles/material.css" rel="stylesheet" />
<link href="style.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='timer'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>
The TimePicker 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 code example demonstrates the TimePicker component in Arabic
culture, also explains how to set the localized text to
the placeholder using L10n.load
method.
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 the ripple effect
import { enableRipple } from '@syncfusion/ej2-base';
//import the timepicker
import { TimePickerComponent } from '@syncfusion/ej2-react-calendars';
// enable ripple effect
enableRipple(true);
//load the CLDR data files.
// Here we have referred local json files for preview purpose
import * as numberingSystems from './numberingSystems.json';
import * as gregorian from './ca-gregorian.json';
import * as numbers from './numbers.json';
loadCldr(numberingSystems, gregorian, numbers);
L10n.load({
'ar': {
'timepicker': { placeholder: 'حدد الوقت' }
}
});
//import the timepickercomponent
class App extends React.Component<{}, {}> {
private rtl:boolean=true;
render() {
return <TimePickerComponent id="time" locale='ar' enableRtl={this.rtl} />
}
};
ReactDOM.render(<App />, document.getElementById('timer'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 TimePicker control</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" />
<!--style reference from the TimePicker component-->
<link href="//cdn.syncfusion.com/ej2/ej2-base/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-lists/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-react-calendars/styles/material.css" rel="stylesheet" />
<link href="style.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='timer'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>