Language files
Language files
Hello!
I've recently begun using datatables.net for a large corporate project.
The website is based on asp.net 4.0 with C#
The problem we/I am facing is the language part of datatables.
as its a global project we would very much like to utilize our extensive library of translations,
by using our custom made translation tool.
The problem is that, when i try to change the language used by datatables.net by a file,
It wont render.
below is code for both initializing the table,
aswell as the code we are trying to use for the language file.
[code]
jQuery('#tblTournaments').dataTable({
"oLanguage": {
"sUrl": "/Scripts/DataTablesLanguageFile.aspx"
}
});
[/code]
Quite simple!
[code]
{
'sProcessing': '<%=Framework.Core.Language.Translate("Please_wait", "Please wait..", "t2_", "")%>',
'sLengthMenu': '<%=Framework.Core.Language.Translate("Items_per_page", "Items per page", "t2_", "")%> _MENU_',
'sZeroRecords': '<%=Framework.Core.Language.Translate("No_data_was_found", "No data was found", "t2_", "")%>',
'sInfo': '_START_ <%=Framework.Core.Language.Translate("to", "to", "t2_", "")%> _END_ <%=Framework.Core.Language.Translate("of", "of", "t2_", "")%> _TOTAL_',
'sInfoEmpty': '0 <%=Framework.Core.Language.Translate("to", "to", "t2_", "")%> 0 <%=Framework.Core.Language.Translate("of", "of", "t2_", "")%> 0',
'sInfoFiltered': '(<%=Framework.Core.Language.Translate("filtered", "filtered", "t2_", "")%> <%=Framework.Core.Language.Translate("of", "of", "t2_", "")%> _MAX_)',
'sInfoPostFix': '',
'sSearch': '<%=Framework.Core.Language.Translate("Search", "Search", "t2_", "")%>',
'sUrl': '',
'oPaginate': {
'sFirst': '<%=Framework.Core.Language.Translate("First", "First", "t2_", "")%>',
'sPrevious': '<%=Framework.Core.Language.Translate("Previous", "Previous", "t2_", "")%>',
'sNext': '<%=Framework.Core.Language.Translate("Next", "Next", "t2_", "")%>',
'sLast': '<%=Framework.Core.Language.Translate("Last", "Last", "t2_", "")%>'
}
}
[/code]
The problem would seem to be datatables.net not being much for using anything beside "" to enclose the parameters and their value.
thus, using '' does not work
( Tested this by downloading the de_DE.txt from the live demo:
http://www.datatables.net/release-datatables/examples/examples_support/de_DE.txt )
Is there anyway around this?
A possible fix could be to do it like this:
[code]
"oLanguage": {
"sLengthMenu": "Display _MENU_ records per page",
"sZeroRecords": "Nothing found - sorry",
"sInfo": "Showing _START_ to _END_ of _TOTAL_ records",
"sInfoEmpty": "Showing 0 to 0 of 0 records",
"sInfoFiltered": "(filtered from _MAX_ total records)"
}
[/code]
however, we would very much like not to, if at all possible!
Regards
A fellow developer in need! :)
I've recently begun using datatables.net for a large corporate project.
The website is based on asp.net 4.0 with C#
The problem we/I am facing is the language part of datatables.
as its a global project we would very much like to utilize our extensive library of translations,
by using our custom made translation tool.
The problem is that, when i try to change the language used by datatables.net by a file,
It wont render.
below is code for both initializing the table,
aswell as the code we are trying to use for the language file.
[code]
jQuery('#tblTournaments').dataTable({
"oLanguage": {
"sUrl": "/Scripts/DataTablesLanguageFile.aspx"
}
});
[/code]
Quite simple!
[code]
{
'sProcessing': '<%=Framework.Core.Language.Translate("Please_wait", "Please wait..", "t2_", "")%>',
'sLengthMenu': '<%=Framework.Core.Language.Translate("Items_per_page", "Items per page", "t2_", "")%> _MENU_',
'sZeroRecords': '<%=Framework.Core.Language.Translate("No_data_was_found", "No data was found", "t2_", "")%>',
'sInfo': '_START_ <%=Framework.Core.Language.Translate("to", "to", "t2_", "")%> _END_ <%=Framework.Core.Language.Translate("of", "of", "t2_", "")%> _TOTAL_',
'sInfoEmpty': '0 <%=Framework.Core.Language.Translate("to", "to", "t2_", "")%> 0 <%=Framework.Core.Language.Translate("of", "of", "t2_", "")%> 0',
'sInfoFiltered': '(<%=Framework.Core.Language.Translate("filtered", "filtered", "t2_", "")%> <%=Framework.Core.Language.Translate("of", "of", "t2_", "")%> _MAX_)',
'sInfoPostFix': '',
'sSearch': '<%=Framework.Core.Language.Translate("Search", "Search", "t2_", "")%>',
'sUrl': '',
'oPaginate': {
'sFirst': '<%=Framework.Core.Language.Translate("First", "First", "t2_", "")%>',
'sPrevious': '<%=Framework.Core.Language.Translate("Previous", "Previous", "t2_", "")%>',
'sNext': '<%=Framework.Core.Language.Translate("Next", "Next", "t2_", "")%>',
'sLast': '<%=Framework.Core.Language.Translate("Last", "Last", "t2_", "")%>'
}
}
[/code]
The problem would seem to be datatables.net not being much for using anything beside "" to enclose the parameters and their value.
thus, using '' does not work
( Tested this by downloading the de_DE.txt from the live demo:
http://www.datatables.net/release-datatables/examples/examples_support/de_DE.txt )
Is there anyway around this?
A possible fix could be to do it like this:
[code]
"oLanguage": {
"sLengthMenu": "Display _MENU_ records per page",
"sZeroRecords": "Nothing found - sorry",
"sInfo": "Showing _START_ to _END_ of _TOTAL_ records",
"sInfoEmpty": "Showing 0 to 0 of 0 records",
"sInfoFiltered": "(filtered from _MAX_ total records)"
}
[/code]
however, we would very much like not to, if at all possible!
Regards
A fellow developer in need! :)
This discussion has been closed.
Replies
A work around is to replace the JSON loader DataTables uses to use eval() (since what you have is valid Javascript), but that sounds a bit messy.
Allan
Its pure server calls
(<%= %>) to the code behind.
its rendered as this:
[code]
{ 'sProcessing': 'Please wait..', 'sLengthMenu': 'Items per page _MENU_', 'sZeroRecords': 'No data was found', 'sInfo': '_START_ to _END_ of _TOTAL_', 'sInfoEmpty': '0 to 0 of 0', 'sInfoFiltered': '(filtered of _MAX_)', 'sInfoPostFix': '', 'sSearch': 'Search', 'sUrl': '', 'oPaginate': { 'sFirst': 'First', 'sPrevious': 'Previous', 'sNext': 'Next', 'sLast': 'Last' } }
[/code]
however, i might have figured out a way around it which involves building the structure on the server,
then writing it out.
EDIT:
The idea of building it server side worked.
[code]
<%@ WebHandler Language="C#" Class="DataTableHandler" %>
using System;
using System.Web;
using System.Collections.Generic;
public class DataTableHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
HttpRequest req = context.Request;
HttpResponse res = context.Response;
object output = new object();
switch (req["methodName"])
{
case "LoadLanguage":
Method_LoadLanguage(out output, req, res);
break;
}
res.Write(output);
}
private void Method_LoadLanguage(out object output, HttpRequest req, HttpResponse res)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("{");
sb.Append("\"sProcessing\":\"" + Framework.Core.Language.Translate("Please_wait", "Please wait..", "t2_", "") + "\",");
sb.Append("\"sLengthMenu\":\"_MENU_ " + Framework.Core.Language.Translate("Items_per_page", "Items per page", "t2_", "") + "\",");
sb.Append("\"sZeroRecords\":\"" + Framework.Core.Language.Translate("No_data_was_found", "No data was found", "t2_", "") + "\",");
sb.Append("\"sInfo\":\"_START_ " + Framework.Core.Language.Translate("to", "to", "t2_", "") + "_END_ " + Framework.Core.Language.Translate("of", "of", "t2_", "") + " _TOTAL_\",");
sb.Append("\"sInfoEmpty\":\"0 " + Framework.Core.Language.Translate("to", "to", "t2_", "") + " 0 " + Framework.Core.Language.Translate("of", "of", "t2_", "") + " 0\",");
sb.Append("\"sInfoFiltered\":\"(" + Framework.Core.Language.Translate("filtered", "filtered", "t2_", "") + " " + Framework.Core.Language.Translate("of", "of", "t2_", "") + " _MAX_)\",");
sb.Append("\"sInfoPostFix\":\"\",");
sb.Append("\"sSearch\":\"" + Framework.Core.Language.Translate("Search", "Search", "t2_", "") + "\",");
sb.Append("\"sUrl\":\"\",");
sb.Append("\"oPaginate\":{");
sb.Append("\"sFirst\":\"" + Framework.Core.Language.Translate("First", "First", "t2_", "") + "\",");
sb.Append("\"sPrevious\":\"" + Framework.Core.Language.Translate("Previous", "Previous", "t2_", "") + "\",");
sb.Append("\"sNext\":\"" + Framework.Core.Language.Translate("Next", "Next", "t2_", "") + "\",");
sb.Append("\"sLast\":\"" + Framework.Core.Language.Translate("Last", "Last", "t2_", "") + "\"");
sb.Append("}");
sb.Append("}");
output = sb.ToString();
}
}
[/code]
A simple c# handler.ashx with a function to output the language.
[code]
"oLanguage": {
"sUrl": "/ClientHandlers/DataTableHandler.ashx?methodName=LoadLanguage"
}
[/code]