Angular Common - utils - localization
An object that serves as a namespace for the methods that are used to localize an application.
formatDate(value, format)
Converts a Date object to a string using the specified format.
The formatted string.
jQuery
var dateString = DevExpress.localization.formatDate(new Date(2018, 4, 7), "longDate"); console.log(dateString); // logs "Monday, May 7, 2018"
Angular
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)
Substitutes the provided value(s) for placeholders in a message that the key specifies.
The formatted message.
jQuery
// 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
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)
Converts a numeric value to a string using the specified format.
The formatted string.
jQuery
var numberString = DevExpress.localization.formatNumber(0.25, "percent"); console.log(numberString); // logs "25%"
Angular
import { formatNumber } from "devextreme/localization";
// ...
export class AppComponent {
constructor() {
let numberString = formatNumber(0.25, "percent");
console.log(numberString); // logs "25%"
}
}loadMessages(messages)
Loads localized messages.
The messages to be loaded.
jQuery
DevExpress.localization.loadMessages({
"en": {
"Yes": "Yes",
"No": "No",
// ...
},
"es": {
"Yes": "Si",
"No": "No",
// ...
}
});Angular
import { localization } from "devextreme";
// ...
export class AppComponent {
constructor() {
localization.loadMessages({
"en": {
"Yes": "Yes",
"No": "No",
// ...
},
"es": {
"Yes": "Si",
"No": "No",
// ...
}
});
}
}locale()
Gets the current locale identifier.
The identifier.
locale(locale)
Sets the current locale identifier.
The required locale identifier.
parseDate(text, format)
Parses a string into a Date object.
A Date object equivalent to the specified string.
parseNumber(text, format)
Parses a string into a numeric value.
A numeric value equivalent to the specified string.
If you have technical questions, please create a support ticket in the DevExpress Support Center.