Globalization in Vue Datepicker component
25 Apr 20259 minutes to read
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, DatePicker date format, week and month names are specific to 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 and it allows to load the culture specific CLDR JSON data by using loadCldr method
The DatePicker component supports only the Gregorian type of calendar. All the Essential® JS 2 component are specific to English cultur (‘en-US’). If you want to go with the different culture other than English, follow the below steps.
-
Install the
CLDR-Datapackage by using the below command (it installs the CLDR JSON data). To know more about CLDR-Data refer the
CLDR-Datalink.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.vuefile. -
Now use the
loadCldrmethod to load the culture specific CLDR JSON data from the installed location toapp.vuefile. -
DatePicker displayed
Sundayas the first day of week based on default culture (“en-US”). If you want to display the DatePicker with loaded culture’s first day of week, you need to importweekdata.jsonfile from thecldr-data/suppementalas given in the code example.
//Load the loadCldr from ej2-base
import { loadCldr } from '@syncfusion/ej2-base';
import * as numberingSystems from 'cldr-data/supplemental/numberingSystems.json';
import * as gregorian from 'cldr-data/main/de/ca-gregorian.json';
import * as numbers from 'cldr-data/main/de/numbers.json';
import * as timeZoneNames from 'cldr-data/main/de/timeZoneNames.json';
import * as weekData from 'cldr-data/supplemental/weekdata.json';// To load the culture based first day of week
loadCldr(numberingSystems, gregorian, numbers, timeZoneNames, weekData);The
Localizationlibrary allows you to localize default text content of the DatePicker. The DatePicker component has static text for today feature that can be changed to other cultures (Arabic, Deutsch, French, etc.) by defining thelocalevalue 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 the culture other than
English, ensure that locale text for the concerned culture is loaded throughloadmethod of
L10n class.
//Load the L10n from ej2-base
import { L10n } from '@syncfusion/ej2-base';
//load the locale object to set the localized placeholder value
L10n.load({
'de': {
'datepicker': { placeholder: 'Wählen Sie ein Datum aus', today: 'heute' }
}
});- Set the culture by using the
localeproperty. The following example demonstrates the DatePicker inGermanculture.
<template>
<div id="app">
<div class='wrapper'>
<ejs-datepicker id="datepicker" locale='de'></ejs-datepicker>
</div>
</div>
</template>
<script setup>
import { loadCldr, L10n } from '@syncfusion/ej2-base';
import { DatePickerComponent as EjsDatepicker } from "@syncfusion/ej2-vue-calendars";
// 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';
import * as timeZoneNames from './timeZoneNames.json';
loadCldr(numberingSystems, gregorian, numbers, timeZoneNames);
L10n.load({
'de': {
'datepicker': {
placeholder: "Wählen Sie Datum und Uhrzeit",
today: "heute"
}
}
});
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrapper {
margin: 0px auto;
width: 240px;
}
</style><template>
<div id="app">
<div class='wrapper'>
<ejs-datepicker id="datepicker" locale='de'></ejs-datepicker>
</div>
</div>
</template>
<script>
import { loadCldr, L10n } from '@syncfusion/ej2-base';
import { DatePickerComponent } from "@syncfusion/ej2-vue-calendars";
// 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';
import * as timeZoneNames from './timeZoneNames.json';
loadCldr(numberingSystems, gregorian, numbers, timeZoneNames);
L10n.load({
'de': {
'datepicker': {
placeholder: "Wählen Sie Datum und Uhrzeit",
today: "heute"
}
}
});
export default {
name: "App",
components: {
"ejs-datepicker": DatePickerComponent
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrapper {
margin: 0px auto;
width: 240px;
}
</style>Right-To-Left
The DatePicker supports right-to-left functionality for languages like Arabic, Hebrew to displays the text in the right-to-left direction. Use
enableRtl property to set the RTL direction.
<template>
<div id="app">
<div class='wrapper'>
<ejs-datepicker id="datepicker" :locale="locale" :enableRtl="rtl"></ejs-datepicker>
</div>
</div>
</template>
<script setup>
import { loadCldr, L10n } from '@syncfusion/ej2-base';
import { DatePickerComponent as EjsDatepicker } from "@syncfusion/ej2-vue-calendars";
// 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';
import * as timeZoneNames from './timeZoneNames.json';
loadCldr(numberingSystems, gregorian, numbers, timeZoneNames);
L10n.load({
'he': {
'datepicker': {
placeholder: 'הזן תאריך',
today: 'היו'
}
}
});
const locale = "he";
const rtl = true;
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrapper {
margin: 0px auto;
width: 240px;
}
</style><template>
<div id="app">
<div class='wrapper'>
<ejs-datepicker id="datepicker" :locale="locale" :enableRtl="rtl"></ejs-datepicker>
</div>
</div>
</template>
<script>
import { loadCldr, L10n } from '@syncfusion/ej2-base';
import { DatePickerComponent } from "@syncfusion/ej2-vue-calendars";
// 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';
import * as timeZoneNames from './timeZoneNames.json';
loadCldr(numberingSystems, gregorian, numbers, timeZoneNames);
L10n.load({
'he': {
'datepicker': {
placeholder: 'הזן תאריך',
today: 'היו'
}
}
});
export default {
name: "App",
components: {
"ejs-datepicker": DatePickerComponent
},
data() {
return {
locale: "he",
rtl: true
}
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrapper {
margin: 0px auto;
width: 240px;
}
</style>