React 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.

import { formatDate } from "devextreme/localization"
Parameters:
value:

Date

A Date object to be converted.

format:

Format

The format to be used for conversion.

Return Value:

String

The formatted string.

jQuery
index.js
const dateString = DevExpress.localization.formatDate(new Date(2018, 4, 7), "longDate");
console.log(dateString); // logs "Monday, May 7, 2018"

// ===== or when using modules =====
import { formatDate } from "devextreme/localization";

const dateString = formatDate(new Date(2018, 4, 7), "longDate");
console.log(dateString); // logs "Monday, May 7, 2018"
Angular
app.component.ts
import { formatDate } from "devextreme/localization";

const dateString = formatDate(new Date(2018, 4, 7), "longDate");
console.log(dateString); // logs "Monday, May 7, 2018"
Vue
App.vue
import { formatDate } from "devextreme/localization";

const dateString = formatDate(new Date(2018, 4, 7), "longDate");
console.log(dateString); // logs "Monday, May 7, 2018"
React
App.js
import { formatDate } from "devextreme/localization";

const dateString = formatDate(new Date(2018, 4, 7), "longDate");
console.log(dateString); // logs "Monday, May 7, 2018"
See Also

formatMessage(key, value)

Substitutes the provided value(s) for placeholders in a message that the key specifies.

import { formatMessage } from "devextreme/localization"
Parameters:
key:

String

The key that identifies the message in a dictionary.

value:

String

|

Array<String>

One or several values used to fill placeholders in the message. This parameter is optional.

Return Value:

String

The formatted message.

Refer to the following help topic for a code example: Add Strings to a Dictionary.

formatNumber(value, format)

Converts a numeric value to a string using the specified format.

import { formatNumber } from "devextreme/localization"
Parameters:
value:

Number

A numeric value to be converted.

format:

Format

The format to be used for conversion.

Return Value:

String

The formatted string.

jQuery
index.js
const numberString = DevExpress.localization.formatNumber(0.25, "percent");
console.log(numberString); // logs "25%"

// ===== or when using modules =====
import { formatNumber } from "devextreme/localization";

const numberString = formatNumber(0.25, "percent");
console.log(numberString); // logs "25%"
Angular
app.component.ts
import { formatNumber } from "devextreme/localization";

const numberString = formatNumber(0.25, "percent");
console.log(numberString); // logs "25%"
Vue
App.vue
import { formatNumber } from "devextreme/localization";

const numberString = formatNumber(0.25, "percent");
console.log(numberString); // logs "25%"
React
App.js
import { formatNumber } from "devextreme/localization";

const numberString = formatNumber(0.25, "percent");
console.log(numberString); // logs "25%"
See Also

loadMessages(messages)

Loads localized messages.

import { loadMessages } from "devextreme/localization"
Parameters:
messages:

Object

The messages to be loaded.

Refer to the following help topic for a code example: Add Strings to a Dictionary.

NOTE
It is necessary to reload the page each time you load new messages.

locale()

Gets the current locale identifier.

import { locale } from "devextreme/localization"
Return Value:

String

The identifier.

See Also

locale(locale)

Sets the current locale identifier.

import { locale } from "devextreme/localization"
Parameters:
locale:

String

The required locale identifier.

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)

Parses a string into a Date object.

import { parseDate } from "devextreme/localization"
Parameters:
text:

String

A string value to be parsed.

format:

Format

The format of the string to be parsed.

Return Value:

Date

A Date object equivalent to the specified string.

Refer to the following help topic for a code example: Format Custom Values.

parseNumber(text, format)

Parses a string into a numeric value.

import { parseNumber } from "devextreme/localization"
Parameters:
text:

String

A string value to be parsed.

format:

Format

The format of the string to be parsed.

Return Value:

Number

A numeric value equivalent to the specified string.