jQuery/JS Common - utils - localization
formatDate(value, format)
import { formatDate } from "devextreme/localization"
Parameters:
Return Value:
jQuery
JavaScript
var dateString = DevExpress.localization.formatDate(new Date(2018, 4, 7), "longDate"); console.log(dateString); // logs "Monday, May 7, 2018"
Angular
TypeScript
import { formatDate } from "devextreme/localization"; // ... export class AppComponent { constructor() { let dateString = formatDate(new Date(2018, 4, 7), "longDate"); console.log(dateString); // logs "Monday, May 7, 2018" } }
formatMessage(key, value)
import { formatMessage } from "devextreme/localization"
Parameters:
Return Value:
jQuery
JavaScript
// Load the "greeting" message for the "en" and "es" locales DevExpress.localization.loadMessages({ "en": { "greeting": "Hello, {0} {1}!", }, "es": { "greeting": "Hola, {0} {1}!", } }); // Set the current locale to "en" DevExpress.localization.locale("en"); console.log(DevExpress.localization.formatMessage("greeting", ["John", "Smith"])); // logs "Hello, John Smith!" // Set the current locale to "es" DevExpress.localization.locale("es"); console.log(DevExpress.localization.formatMessage("greeting", ["John", "Smith"])); // logs "Hola, John Smith!"
Angular
TypeScript
import { formatMessage, loadMessages, locale } from "devextreme/localization"; // ... export class AppComponent { constructor() { // Load the "greeting" message for the "en" and "es" locales loadMessages({ "en": { "greeting": "Hello, {0} {1}!", }, "es": { "greeting": "Hola, {0} {1}!", } }); // Set the current locale to "en" locale("en"); console.log(formatMessage("greeting", ["John", "Smith"])); // logs "Hello, John Smith!" // Set the current locale to "es" locale("es"); console.log(formatMessage("greeting", ["John", "Smith"])); // logs "Hola, John Smith!" } }
formatNumber(value, format)
import { formatNumber } from "devextreme/localization"
Parameters:
Return Value:
jQuery
JavaScript
var numberString = DevExpress.localization.formatNumber(0.25, "percent"); console.log(numberString); // logs "25%"
Angular
TypeScript
import { formatNumber } from "devextreme/localization"; // ... export class AppComponent { constructor() { let numberString = formatNumber(0.25, "percent"); console.log(numberString); // logs "25%" } }
loadMessages(messages)
import { loadMessages } from "devextreme/localization"
Parameters:
messages:
jQuery
JavaScript
DevExpress.localization.loadMessages({ "en": { "Yes": "Yes", "No": "No", // ... }, "es": { "Yes": "Si", "No": "No", // ... } });
Angular
TypeScript
import { localization } from "devextreme"; // ... export class AppComponent { constructor() { localization.loadMessages({ "en": { "Yes": "Yes", "No": "No", // ... }, "es": { "Yes": "Si", "No": "No", // ... } }); } }
NOTE
It is necessary to reload the page each time you load new messages.
locale(locale)
import { locale } from "devextreme/localization"
Parameters:
locale:
NOTE
This method should be called only once - at the application's launch. It is necessary to reload the page each time you need to set new locale.
See Also
parseDate(text, format)
import { parseDate } from "devextreme/localization"
Parameters:
Return Value:
parseNumber(text, format)
import { parseNumber } from "devextreme/localization"
Parameters:
Return Value:
Feel free to share topic-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.