1

I've got ASP.NET MVC 2 application that actively uses jquery DataTable component. Well it's fine, but there is no localization support there. By localization I mean not only translating version rendering but correct translation of the DataTable based on what is current language is set in session object in session. How can I do it without setting cookie like Lang=en-Us? It's ok if translation file will be out of resources.

2 Answers 2

1

I am maybe late but I give you my solution :

Instead of adding each resource in the DOM I used the ajax loading option. To make short DataTables can load a .json into the initializer (containing all your pretty, localized, resources texts).

So I implemented a new action to get the .json :

public JsonResult LocalizedDataTableLanguage()
{
    // Create ressource object.
    var jsonObject = new
    {
        sEmptyTable = Resources.EmptyTable
    };
    // Serialize and send the object resource.
    return Json(jsonObject);
}

Then you just have to give the Url of this method to the language.url option

Hope this helps

Edit

You can check the json structure expected by DataTables here

Sign up to request clarification or add additional context in comments.

Comments

0

I'm using the server side resources files within my ASP.NET application which would help in this situation, I use the code behind to workout which culture and then populate public variables on the javascript side. you can go through all the strings but make sure you remember to include the correct replacement string in the resouce file ie. "sInfo": "RAV Showing START to END of TOTAL entries". Here is an example of the javascript

var _sEmptyTable = "<%=mstrEmptyTable %>";


jQuery('#example').dataTable(
{
    "oLanguage": {"sEmptyTable": _sEmptyTable}
});

the code behind

public string mstrEmptyTable = "No data available";

just substitute the mstrEmptyTable with your session object or resource file.

Hope that helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.