DevExtreme jQuery/JS - Localization
Localization adapts your application to linguistic and regional differences. DevExtreme allows you to localize:
- Messages (using dictionaries)
- Numbers, dates, and currencies (using Intl or Globalize).
DevExtreme also supports right-to-left layout.
Dictionaries
Dictionaries contain localized strings for different languages. The strings are key/value pairs and are shipped as JavaScript or JSON files (depending on the package you use).
All dictionaries are contributed and curated by the community. The list of dictionaries is available on GitHub.
You can find all the dictionaries on your local machine in the DevExtreme installation folder's or ZIP archive's Lib\js\localization directory. These dictionaries are also available on CDN.
Use the <script>
tag to link the required dictionaries, and place the links after a link to the DevExtreme library:
- <head>
- <!-- ... -->
- <!-- DevExtreme library -->
- <script src="https://cdn3.devexpress.com/jslib/24.2.3/js/dx.all.js"></script>
- <!-- Dictionary files for German language -->
- <script src="https://cdn3.devexpress.com/jslib/24.2.3/js/localization/dx.messages.de.js"></script>
- </head>
- <body>
- <script>
- DevExpress.localization.locale(navigator.language);
- // ...
- // DevExtreme UI components are configured here
- // ...
- </script>
- </body>
Create a New Dictionary
To make a dictionary for a new locale:
- Copy one of the available dictionaries.
- Rename it according to the new locale.
- Translate the strings in it and change the locale key.
You can submit JSON dictionaries to our repository on GitHub. You should refer to our Contribution Guide before submitting content.
Add Strings to a Dictionary
In the following example, the loadMessages(messages) method adds a string with the greetingMessage
key to the English and German dictionaries. The formatMessage(key, value) method then uses this key to retrieve the string from the dictionary that corresponds to the locale set by the locale(locale) method.
- $(function() {
- var userName = "John";
- DevExpress.localization.loadMessages({
- "en": {
- "greetingMessage": "Good morning, {0}!"
- },
- "de": {
- "greetingMessage": "Guten morgen, {0}!"
- }
- });
- DevExpress.localization.locale(navigator.language);
- $("#greeting").text(
- DevExpress.localization.formatMessage("greetingMessage", userName)
- )
- })
- <h1 id="greeting"></h1>
You can also see this approach in one of our demos:
Override Strings in a Dictionary
To override a string, find its key in any dictionary and use it to specify the new string value.
In the following code, we override two strings from the English dictionary:
- $(function() {
- DevExpress.localization.loadMessages({
- "en": {
- "dxDataGrid-editingDeleteRow": "Remove",
- "dxDataGrid-editingUndeleteRow": "Recover"
- }
- });
- });
See Also
Using Intl
Intl is the short name used to refer to a particular ECMAScript Internationalization API object. DevExtreme supports this API out of the box. All you need to do is set the locale:
- DevExpress.localization.locale(navigator.language);
- // ...
- // DevExtreme UI components are configured here
- // ...
- <head>
- <!-- ... -->
- <!-- DevExtreme library -->
- <script src="https://cdn3.devexpress.com/jslib/24.2.3/js/dx.all.js"></script>
- <!-- Dictionary files for German language -->
- <script src="https://cdn3.devexpress.com/jslib/24.2.3/js/localization/dx.messages.de.js"></script>
- <script src="index.js"></script>
- </head>
If you want to format and localize strings, numbers, dates, and currencies automatically according to the specified locale, define the format.type property. You can also specify a currency other than USD globally. For this purpose, use the defaultCurrency or currency settings:
- $(function() {
- // Specifying a currency globally
- DevExpress.config({ defaultCurrency: "EUR" });
- $("#dataGridContainer").dxDataGrid({
- // ...
- columns: [{
- dataField: "Price",
- // Specifying a currency in a format definition
- format: {
- type: "currency",
- currency: "RUB"
- }
- }]
- });
- });
You can use structures compatible with the Intl API for value formatting. Refer to the Intl Formats section in the Value Formatting article for more information.
Using Globalize
The Globalize package is outdated and potentially insecure. Reports from the Snyk security checker highlight vulnerabilities associated with this package.
Use Globalize at your own risk. In v25.1, we will remove Globalize from our installation, templates, and demos. We recommend switching to Intl for a more secure solution.
The following files are required to activate Globalize in your project:
- Globalize library
- CLDR library
- CLDR data
To include these components, you can use CDN or npm.
CDN or local files
Specify the Globalize and CLDR libraries using
<script>
tags as shown below. In this example, the German dictionary is included. Note that the order in which you include the libraries is important. Then, set the locale using theGlobalize.locale()
method:npm
Install the
devextreme-cldr-data
andglobalize
packages:- npm install --save-dev devextreme-cldr-data globalize
Then, include Globalize, CLDR, and language-specific CLDR data using the
import
orrequire
statement—the statement depends on the syntax for working with modules. The code below shows ECMAScript 6 and CommonJS syntaxes. These examples include the German dictionary.
You can format and localize strings, numbers, dates, and currencies automatically according to a locale. For this, apply the format.type property. You can also use a currency other than USD (see the last example in the Using Intl topic).
In addition, you can now format values using structures accepted by numberFormatter, currencyFormatter, and dateFormatter, for example:
- $(function() {
- $("#dataGridContainer").dxDataGrid({
- // ...
- columns: [{
- dataField: "OrderDate",
- format: { skeleton: "yMMMd" }
- }, {
- dataField: "SaleAmount",
- format: { currency: "EUR", maximumFractionDigits: 2 }
- }]
- });
- });
See Also
Localize Custom Values
DevExtreme provides an API for localizing messages, dates, and numbers in your app.
To localize a message, add it to a dictionary as shown in the Add Strings to a Dictionary article.
To localize a custom date or number, apply a format to it as shown in the Format Custom Values article.
Right-to-Left Support
Right-to-left (RTL) support allows the UI component to adapt its content to right-to-left locales.
RTL layout can be specified for an individual UI component using its rtlEnabled property:
- $(function() {
- $("#sliderContainer").dxSlider({
- // ...
- rtlEnabled: true
- });
- });
To apply RTL to your entire application, set the same property globally using the config() function:
- $(function() {
- DevExpress.config({ rtlEnabled: true });
- // ...
- });
See Also
- RTL Support Demo: DataGrid | Navigation Components | Editors
If you have technical questions, please create a support ticket in the DevExpress Support Center.