Globalization in ASP.NET MVC Grid control

21 Dec 202221 minutes to read

Localization

The Localization library allows you to localize default text content of the Grid. The grid component has static text on some features (like group drop area text, pager information text, etc.) that can be changed to other cultures (Arabic, Deutsch, French, etc.) by defining the Locale value and translation object.

The following list of properties and its values are used in the grid.

Locale keywords Text
EmptyRecord No records to display.
True true
False false
InvalidFilterMessage Invalid filter data.
GroupDropArea Drag a column header here to group its column.
UnGroup Click here to ungroup.
GroupDisable Grouping is disabled for this column.
FilterbarTitle \s filter bar cell.
EmptyDataSourceError DataSource must not be empty at initial load as columns are generated from the dataSource in AutoGenerate Column Grid.
Add Add
Edit Edit
Cancel Cancel
Update Update
Delete Delete
Print Print
Pdfexport PDF Export
Excelexport Excel Export
Wordexport Word Export
Csvexport CSV Export
Search Search
Columnchooser Columns
Save Save
Item item
Items items
EditOperationAlert No records selected for edit operation
DeleteOperationAlert No records selected for delete operation
SaveButton Save
OKButton OK
CancelButton Cancel
EditFormTitle Details of
AddFormTitle Add New Record
BatchSaveConfirm Are you sure you want to save changes?
BatchSaveLostChanges Unsaved changes will be lost. Are you sure you want to continue?
ConfirmDelete Are you sure you want to Delete Record?
CancelEdit Are you sure you want to Cancel the changes?
ChooseColumns Choose Column
SearchColumns search columns
Matchs No Matches Found
FilterButton Filter
ClearButton Clear
StartsWith Starts With
EndsWith Ends With
Contains Contains
Equal Equal
NotEqual Not Equal
LessThan Less Than
LessThanOrEqual Less Than Or Equal
GreaterThan Greater Than
GreaterThanOrEqual Greater Than Or Equal
ChooseDate Choose a Date
EnterValue Enter the value
Copy Copy
Group Group by this column
Ungroup Ungroup by this column
autoFitAll AutoFit all columns
autoFit AutoFit this column
Export Export
FirstPage First Page
LastPage Last Page
PreviousPage Previous Page
NextPage Next Page
SortAscending Sort Ascending
SortDescending Sort Descending
EditRecord Edit Record
DeleteRecord Delete Record
FilterMenu Filter
SelectAll Select All
Blanks Blanks
FilterTrue True
FilterFalse False
NoResult No Matches Found
ClearFilter Clear Filter
NumberFilter Number Filters
TextFilter Text Filters
DateFilter Date Filters
MatchCase Match Case
Between Between
CustomFilter Custom Filter
CustomFilterPlaceHolder Enter the value
CustomFilterDatePlaceHolder Choose a date
AND AND
OR OR
ShowRowsWhere Show rows where
currentPageInfo {0} of {1} pages
totalItemsInfo ({0} items)
firstPageTooltip Go to first page
lastPageTooltip Go to last page
nextPageTooltip Go to next page
previousPageTooltip Go to previous page
nextPagerTooltip Go to next pager items
previousPagerTooltip Go to previous pager items
pagerDropDown Items per page
pagerAllDropDown Items
All All

Loading translations

To load translation object in an application, use load function of the L10n class.

The following example demonstrates the Grid in Deutsch culture.

@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
{
    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").Add();
    col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
    col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();
    col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add();

}).AllowPaging().AllowGrouping().Locale("de-DE").PageSettings(page => page.PageSize(6)).Render()

<script>
    ej.base.L10n.load({
        'de-DE': {
            'grid': {
                'EmptyRecord': 'Keine Aufzeichnungen angezeigt',
                'GroupDropArea': 'Ziehen Sie einen Spaltenkopf hier, um die Gruppe ihre Spalte',
                'UnGroup': 'Klicken Sie hier, um die Gruppierung aufheben',
                'EmptyDataSourceError': 'DataSource darf bei der Erstauslastung nicht leer sein, da Spalten aus der dataSource im AutoGenerate Spaltenraster',
                'Item': 'Artikel',
                'Items': 'Artikel'
            },
            'pager': {
                'currentPageInfo': '{0} von {1} Seiten',
                'totalItemsInfo': '({0} Beiträge)',
                'firstPageTooltip': 'Zur ersten Seite',
                'lastPageTooltip': 'Zur letzten Seite',
                'nextPageTooltip': 'Zur nächsten Seite',
                'previousPageTooltip': 'Zurück zur letzten Seit',
                'nextPagerTooltip': 'Gehen Sie zu den nächsten Pager-Elementen',
                'previousPagerTooltip': 'Gehen Sie zu vorherigen Pager-Elementen'
            }
        }
    });
</script>
public IActionResult Index()
{
    var orders = OrderDetails.GetAllRecords();
    ViewBag.datasource = orders;            
    return View();
}

Internationalization

The Internationalization library is used to globalize number, date, and time values in grid component using format strings in the Format.

@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
{
    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").Add();
    col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
    col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();
    col.Field("Freight").HeaderText("Ship Name").Format("C2").Width("150").Add();
    col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add();

}).AllowPaging().AllowGrouping().Locale("de-DE").PageSettings(page => page.PageSize(6)).Render()

<script>

    ej.base.setCurrencyCode('EUR');

    ej.base.L10n.load({
        'de-DE': {
            'grid': {
                'EmptyRecord': 'Keine Aufzeichnungen angezeigt',
                'GroupDropArea': 'Ziehen Sie einen Spaltenkopf hier, um die Gruppe ihre Spalte',
                'UnGroup': 'Klicken Sie hier, um die Gruppierung aufheben',
                'EmptyDataSourceError': 'DataSource darf bei der Erstauslastung nicht leer sein, da Spalten aus der dataSource im AutoGenerate Spaltenraster',
                'Item': 'Artikel',
                'Items': 'Artikel'
            },
            'pager': {
                'currentPageInfo': '{0} von {1} Seiten',
                'totalItemsInfo': '({0} Beiträge)',
                'firstPageTooltip': 'Zur ersten Seite',
                'lastPageTooltip': 'Zur letzten Seite',
                'nextPageTooltip': 'Zur nächsten Seite',
                'previousPageTooltip': 'Zurück zur letzten Seit',
                'nextPagerTooltip': 'Gehen Sie zu den nächsten Pager-Elementen',
                'previousPagerTooltip': 'Gehen Sie zu vorherigen Pager-Elementen'
            }
        }
    });
</script>
public IActionResult Index()
{
    var orders = OrderDetails.GetAllRecords();
    ViewBag.datasource = orders;            
    return View();
}

NOTE

In the above sample, Freight column is formatted by NumberFormatOptions.

By default, Locale value is en-US. If you want to change the en-US culture to a different culture, you have to change the Locale accordingly.

Right to left (RTL)

RTL provides an option to switch the text direction and layout of the Grid component from right to left. It improves the user experiences and accessibility for users who use right-to-left languages (Arabic, Farsi, Urdu, etc.). To enable RTL Grid, set the EnableRtl to true.

@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
{
    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").Add();
    col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
    col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();
    col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add();

}).AllowPaging().AllowGrouping().EnableRtl(true).Locale("de-DE").PageSettings(page => page.PageSize(6)).Render()

<script>
    ej.base.L10n.load({
        'de-DE': {
            'grid': {
                'EmptyRecord': 'Keine Aufzeichnungen angezeigt',
                'GroupDropArea': 'Ziehen Sie einen Spaltenkopf hier, um die Gruppe ihre Spalte',
                'UnGroup': 'Klicken Sie hier, um die Gruppierung aufheben',
                'EmptyDataSourceError': 'DataSource darf bei der Erstauslastung nicht leer sein, da Spalten aus der dataSource im AutoGenerate Spaltenraster',
                'Item': 'Artikel',
                'Items': 'Artikel'
            },
            'pager': {
                'currentPageInfo': '{0} von {1} Seiten',
                'totalItemsInfo': '({0} Beiträge)',
                'firstPageTooltip': 'Zur ersten Seite',
                'lastPageTooltip': 'Zur letzten Seite',
                'nextPageTooltip': 'Zur nächsten Seite',
                'previousPageTooltip': 'Zurück zur letzten Seit',
                'nextPagerTooltip': 'Gehen Sie zu den nächsten Pager-Elementen',
                'previousPagerTooltip': 'Gehen Sie zu vorherigen Pager-Elementen'
            }
        }
    });
</script>
public IActionResult Index()
{
    var orders = OrderDetails.GetAllRecords();
    ViewBag.datasource = orders;            
    return View();
}

See Also