How can I get the DatePicker (and DateRangePicker) to use the default date format of the browser, instead of overriding it?
My browser is set as en-gb and everything uses the date format dd/mm/yyyy except for the Syncfusion controls, which all use the US format (mm/dd/yyyy). I don't want to set the locale of the control to en-gb as if an American logs onto our system they will have mismatched formats.
Everywhere else in our product we use .toLocaleDateString() so everything else just displays in the user's date format. Is there a way to get Syncfusion controls to just do the same?
This feels like quite basic functionality and I'm confused as to why they don't do this by default.
Hi Scott Moxham,
Thank you for reaching out to us!
By default, the en-US culture is applied to the DatePicker and DateRangePicker components. If you would like to use a different culture based on the browser's language, you can achieve this by updating the locale property and loading the corresponding CLDR data.
To assist you further, we’ve prepared a sample demonstrating how to load the en-GB culture for the DatePicker component:
<template>
<div id="app">
<div class="wrapper">
<ejs-datepicker id="datepicker" locale="en-GB"></ejs-datepicker>
</div>
</div>
</template>
<script>
import { loadCldr, L10n } from "@syncfusion/ej2-base";
import { DatePickerComponent } from "@syncfusion/ej2-vue-calendars";
// Ensure `require` is accessible in your environment
declare var require: any;
export default {
components: {
"ejs-datepicker": DatePickerComponent,
},
mounted() {
// Load CLDR data required for localization
loadCldr(
require("../cldr-data/numbers.json"),
require("../cldr-data/ca-gregorian.json"),
require("../cldr-data/numberingSystems.json"),
require("../cldr-data/timeZoneNames.json")
);
// Load localization strings
L10n.load({
"en-GB": {
datepicker: {
today: "Today",
},
},
});
},
};
</script>
Sample: https://stackblitz.com/edit/7hxzvxtu-ht9ezbbb?file=src%2FApp.vue
For more information about localization, please refer the below UG documentation
https://ej2.syncfusion.com/vue/documentation/datepicker/globalization
Regards,
Priyanka K
Hi,
Do I have to specify the locale on EVERY control that I include in my app or is there a global setting?
The loadCldr in your example appears to be invalid; The localization link that you included has working code - the data is all in locale specific folders within cldr-data.
So if I'm understanding this correctly, to get a site that adapts to the user's locale, I need to:
const locale = navigator.language;
const localeFolder = locale === 'en-US' ? 'en-US-POSIX' : locale;
const [numberingSystems, gregorian, numbers, timeZoneNames, weekData] = await Promise.all([
import('../../node_modules/cldr-data/supplemental/numberingSystems.json'),
import(`../../node_modules/cldr-data/main/${localeFolder}/ca-gregorian.json`),
import(`../../node_modules/cldr-data/main/${localeFolder}/numbers.json`),
import(`../../node_modules/cldr-data/main/${localeFolder}/timeZoneNames.json`),
import('../../node_modules/cldr-data/supplemental/weekdata.json') // To load the culture based first day of week
]);
loadCldr(numberingSystems, gregorian, numbers, timeZoneNames, weekData);
Hi Scott Moxham,
Thank you for providing the update and sharing your code snippet. To set the culture globally across your application, you can utilize the setCulture method from the ej.base namespace. This method ensures that the desired culture is applied consistently to all UI text elements in your application.
For example, to set the culture globally, you can follow the approach outlined in the code snippet below. Additionally, the loadCldr method is used to load the necessary CLDR (Unicode Common Locale Data Repository) files to support localization for the selected culture:
<template>
<script>
L10n.load({
const locale = navigator.language;
import en_GB_ca from '../node_modules/cldr-data/main/ar/ca-gregorian.json';
loadCldr(
export default { |
ar). The files include data for calendar, timezone names, numbers, and currencies.setCulture method is used to define the culture globally, ensuring consistent localization for all Syncfusion components in the application.L10n.load method to provide specific localization data.
Regards,
Priyanka K