Localization

SpreadJS provides built-in support for English culture (default), Chinese (need corresponding resource file), and Japanese (need corresponding resource file). You can use them to support your localization work.

In order to support localization, you need to add the appropriate js file link into the document's head section below the Spread link. For example: Then you can choose one of the following methods to support localization. Culture meta You can set culture using the meta tag: Change with code You can change culture using the GC.Spread.Common.CultureManager.culture method:
import * as React from 'react'; import { createRoot } from 'react-dom/client'; import './styles.css'; import { AppFunc } from './app-func'; import { App } from './app-class'; // 1. Functional Component sample createRoot(document.getElementById('app')).render(<AppFunc />); // 2. Class Component sample // createRoot(document.getElementById('app')).render(<App />);
import * as React from 'react'; import { createRoot } from 'react-dom/client'; import GC from '@mescius/spread-sheets'; import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; import '@mescius/spread-sheets-resources-ja'; import '@mescius/spread-sheets-resources-ko'; import '@mescius/spread-sheets-resources-zh'; import './styles.css'; export function AppFunc() { let spread = null; let initSpread = function (value) { spread = value; spread.suspendPaint(); let spreadNS = GC.Spread.Sheets; spread.options.showResizeTip = spreadNS.ShowResizeTip.both; spread.options.showScrollTip = spreadNS.ShowScrollTip.both; let sheet = spread.getActiveSheet(); for (let r = 0; r < 10; r++) { for (let c = 0; c < 5; c++) { sheet.setValue(r, c, r + c); } } sheet.rowFilter(new spreadNS.Filter.HideRowFilter(new spreadNS.Range(0, 0, 10, 5))); sheet.setValue(10, 0, "SUM:"); sheet.setFormula(10, 1, "SUM(A1:E10)"); sheet.setValue(11, 0, "PIESPARKLINE:"); sheet.setFormula(11, 1, 'PIESPARKLINE(A1:E10,"yellow", "green")'); sheet.setRowHeight(11, 100); sheet.setColumnWidth(0, 120); sheet.setColumnWidth(1, 100); spread.resumePaint(); GC.Spread.Common.CultureManager.culture("en-us"); } let changeCultureName = function (e) { GC.Spread.Common.CultureManager.culture(e.target.value); } return (<div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => initSpread(spread)}> <Worksheet> </Worksheet> </SpreadSheets> </div> <div className="options-container"> <div className="option-row"> <label>Culture:</label> <select id="cultureName" onChange={e=> changeCultureName(e)}> <option value="en-us" selected>English</option> <option value="zh-cn">Chinese</option> <option value="ja-jp">Japanese</option> <option value="ko-kr">Korean</option> </select> </div> <div className="option-row"> <ul style={{ margin: 0, paddingLeft: '20px' }}> <li>Perform any of the below actions to view the results:</li> <div>- Click a filter dropdown in the column header</div> <div>- Resize a column or row header</div> <div>- Use the scrollbar to scroll the contents</div> <li>To view localized formula descriptions:</li> <div>- Double click cell B11 or B12</div> <div>- Click to edit the formula to view the updated descriptions</div> </ul> </div> </div> </div>); }
import * as React from 'react'; import { createRoot } from 'react-dom/client'; import GC from '@mescius/spread-sheets'; import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; import '@mescius/spread-sheets-resources-ja'; import '@mescius/spread-sheets-resources-ko'; import '@mescius/spread-sheets-resources-zh'; import './styles.css'; const Component = React.Component; function _getElementById(id) { return document.getElementById(id); } export class App extends Component { constructor(props) { super(props); this.spread = null; } render() { return <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}> <Worksheet> </Worksheet> </SpreadSheets> </div> <div className="options-container"> <div className="option-row"> <label>Culture:</label> <select id="cultureName" onChange={e=>this.changeCultureName(e)}> <option value="en-us" selected>English</option> <option value="zh-cn">Chinese</option> <option value="ja-jp">Japanese</option> <option value="ko-kr">Korean</option> </select> </div> <div className="option-row"> <ul style={{ margin: 0, paddingLeft: '20px' }}> <li>Perform any of the below actions to view the results:</li> <div>- Click a filter dropdown in the column header</div> <div>- Resize a column or row header</div> <div>- Use the scrollbar to scroll the contents</div> <li>To view localized formula descriptions:</li> <div>- Double click cell B11 or B12</div> <div>- Click to edit the formula to view the updated descriptions</div> </ul> </div> </div> </div>; } initSpread(spread) { this.spread = spread; spread.suspendPaint(); let spreadNS = GC.Spread.Sheets; spread.options.showResizeTip = spreadNS.ShowResizeTip.both; spread.options.showScrollTip = spreadNS.ShowScrollTip.both; let sheet = spread.getActiveSheet(); for (let r = 0; r < 10; r++) { for (let c = 0; c < 5; c++) { sheet.setValue(r, c, r + c); } } sheet.rowFilter(new spreadNS.Filter.HideRowFilter(new spreadNS.Range(0, 0, 10, 5))); sheet.setValue(10, 0, "SUM:"); sheet.setFormula(10, 1, "SUM(A1:E10)"); sheet.setValue(11, 0, "PIESPARKLINE:"); sheet.setFormula(11, 1, 'PIESPARKLINE(A1:E10,"yellow", "green")'); sheet.setRowHeight(11, 100); sheet.setColumnWidth(0, 120); sheet.setColumnWidth(1, 100); spread.resumePaint(); GC.Spread.Common.CultureManager.culture("en-us"); } changeCultureName (e) { GC.Spread.Common.CultureManager.culture(e.target.value); } }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/en/lib/react/license.js').then(function () { System.import('./src/app'); }); </script> </head> <body> <div id="app"></div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; margin-top: 10px; } label { display: block; margin-bottom: 6px; } input { padding: 4px 6px; } input[type=button] { margin-top: 6px; display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #app { height: 100%; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true, react: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js', '@mescius/spread-sheets-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js', '@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js', '@mescius/spread-sheets-resources-zh': 'npm:@mescius/spread-sheets-resources-zh/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'react': 'npm:react/cjs/react.production.js', 'react-dom': 'npm:react-dom/cjs/react-dom.production.js', 'react-dom/client': 'npm:react-dom/cjs/react-dom-client.production.js', 'scheduler': 'npm:scheduler/cjs/scheduler.production.js', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'jsx' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);