GridJs Multi-Language Configuration Guide
Aspose.Cells GridJs Multi-Language Configuration Guide
Overview
This tutorial will guide you through configuring multi-language support in your Aspose.Cells GridJs project. It covers both frontend and backend configurations.
The tutorial is based on the demo project, please adjust according to the actual situation
Frontend Configuration
In your frontend pages, set the interface language using the local
option.
In the demo project, you need to modify the uidload.html file
Here’s an example:
const loadNormalContext = (sheet) => {
const option = {
updateMode: 'server',
updateUrl: '/GridJs2/UpdateCell',
showToolbar: true,
mode: 'edit',
// Supported languages: en/zh/es/pt/de/ru/nl/pl
local: 'pl', // Set to Polish in this example
};
loadWithOption(jsondata, option);
};
Backend Configuration
In the backend code, you need to set the appropriate CultureInfo before processing Excel data.
In the demo project, you need to modify the Controller file
Controller Configuration Points
The following methods in your Controller need culture configuration:
UpdateCell Method
Set region information when updating cells:
[HttpPost]
public ActionResult UpdateCell()
{
// Set culture info
CultureInfo polishCulture = new CultureInfo("pl-PL");
Thread.CurrentThread.CurrentCulture = polishCulture;
Thread.CurrentThread.CurrentUICulture = polishCulture;
string p = HttpContext.Request.Form["p"];
string uid = HttpContext.Request.Form["uid"];
GridJsWorkbook gwb = new GridJsWorkbook();
String ret = gwb.UpdateCell(p, uid);
return Content(ret, "text/plain", System.Text.Encoding.UTF8);
}
DetailFileJsonWithUid Method
Set region information when retrieving Excel JSON
public ActionResult DetailFileJsonWithUid(string filename, string uid)
{
// Set culture info
CultureInfo polishCulture = new CultureInfo("pl-PL");
Thread.CurrentThread.CurrentCulture = polishCulture;
Thread.CurrentThread.CurrentUICulture = polishCulture;
String file = Path.Combine(TestConfig.ListDir, filename);
GridJsWorkbook wbj = new GridJsWorkbook();
StringBuilder sb = wbj.GetJsonByUid(uid, filename);
if(sb == null)
{
Workbook wb = new Workbook(file);
wbj.ImportExcelFile(uid, wb);
sb = wbj.ExportToJsonStringBuilder(filename);
}
return Content(sb.ToString(), "text/plain", System.Text.Encoding.UTF8);
}
DetailStreamJsonWithUid Method
Set region information when streaming Excel JSON
public ActionResult DetailStreamJsonWithUid(string filename, string uid)
{
// Set culture info
CultureInfo polishCulture = new CultureInfo("pl-PL");
Thread.CurrentThread.CurrentCulture = polishCulture;
Thread.CurrentThread.CurrentUICulture = polishCulture;
String file = Path.Combine(TestConfig.ListDir, filename);
GridJsWorkbook wbj = new GridJsWorkbook();
Response.ContentType = "application/json";
Response.Headers.Add("Content-Encoding", "gzip");
using (GZipStream gzip = new GZipStream(Response.Body, CompressionLevel.Optimal))
{
bool isdone = wbj.JsonToStreamByUid(gzip, uid, filename);
if(!isdone)
{
Workbook wb = new Workbook(file);
wbj.ImportExcelFile(uid, wb);
wbj.JsonToStream(gzip, filename);
}
}
return new EmptyResult();
}
Important Notes
- Frontend and backend language settings must be consistent.
- CultureInfo must be set before processing Excel data.
- Supported languages: en(English), zh(Chinese), es(Spanish), pt(Portuguese), de(German), ru(Russian), nl(Dutch), pl(Polish).
- The example uses Polish (pl-PL), but you can change it to any other supported locale.