Custom Localization

Custom localization provides the ability to customize SpreadJS with a specific language. Users can also get the current or specified culture language resources and translate to their custom resources.

Users need to define the localization object with the schema, or get the current working or specified culture resources with GC.Spread.Common.CultureManager.getResources(cultureName?: string). Then add to the CultureManager and switch to the defined culture. The worksheet displays different properties with the defined words. For example: Or modify resources based on specified culture resources. Hint: If some of the statements are not set, Spread will display English (if set to an empty string “”, it will not display anything).. The arguments is use {0}, {1}, … for display (e.g.: "Invalid {0}: {1} (must be between {2} and {3}).", "Height: {0} pixels"). Custom localization does not support fromJSON/toJSON, so a user will need to add it every time it is needed. The namespace ("common", "Sheets", "Filter") in the sample is optional, but "Functions" and "TableFunctions" are required. The following is also a valid format:
import { Component, NgModule, enableProdMode } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { SpreadSheetsModule } from '@mescius/spread-sheets-angular'; import '@mescius/spread-sheets-resources-zh'; import GC from '@mescius/spread-sheets'; import './styles.css'; declare let source: any; declare let de: any; declare let zh_tw: any; declare let fr: any; declare let ha_ha: any; declare let langDescription: any; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { spread: GC.Spread.Sheets.Workbook; hostStyle = { width: '100%', height: 'calc(100% - 25px)', overflow: 'hidden', float: 'left' }; language = ""; l_description = "Define English for all worksheet properties as the base and default culture."; constructor() { } initSpread($event: any) { this.spread = $event.spread; let spread = this.spread; let sheet = spread.getActiveSheet(); spread.suspendPaint(); spread.options.showScrollTip = 3; spread.options.showResizeTip = 3; let table = sheet.tables.addFromDataSource("table1", 0, 0, source, GC.Spread.Sheets.Tables.TableThemes.medium9) table.showFooter(true); table.showHeader(true); table.highlightFirstColumn(true); table.setColumnFormula(2, "=SUM(C2:C10)"); table.setColumnFormula(3, "=SUM(D2:D10)"); table.setColumnValue(0, "Total"); sheet.setColumnWidth(0, 130); sheet.setColumnWidth(4, 100); GC.Spread.Common.CultureManager.addCultureInfo("de", null, de); var zhResources = GC.Spread.Common.CultureManager.getResources("zh-cn"); zhResources.Sheets.Tip_Column = zh_tw.Sheet.Tip_Column; zhResources.Sheets.Tip_Height = zh_tw.Sheet.Tip_Height; zhResources.Sheets.Tip_Row = zh_tw.Sheet.Tip_Row; zhResources.Sheets.Tip_Width = zh_tw.Sheet.Tip_Width; zhResources.Sheets.NewTab = zh_tw.Sheet.NewTab; zhResources.StatusBar = zh_tw.StatusBar; zhResources.CalcEngine.Fbx_Summary = zh_tw.CalcEngine.Fbx_Summary; zhResources.Functions.SUM = zh_tw.Functions.SUM; zhResources.Functions.NOW = zh_tw.Functions.NOW; zhResources.Functions.IF = zh_tw.Functions.IF; GC.Spread.Common.CultureManager.addCultureInfo("zh_tw", null, zhResources); GC.Spread.Common.CultureManager.addCultureInfo("fr", null, fr); GC.Spread.Common.CultureManager.addCultureInfo("ha_ha", null, ha_ha); let statusBar = new GC.Spread.Sheets.StatusBar.StatusBar(document.getElementById('statusBar')); statusBar.bind(spread); spread.resumePaint(); } changeCultureName(e: any) { let culture = e.target.value; GC.Spread.Common.CultureManager.culture(culture); this.l_description = langDescription[culture]; if (culture === "en") { this.language = ""; } else if (culture === "zh_tw") { this.language = JSON.stringify(GC.Spread.Common.CultureManager.getResources("zh_tw"), null, 2); } else { this.language = JSON.stringify(window[culture], null, 2); } } } @NgModule({ imports: [BrowserModule, SpreadSheetsModule], declarations: [AppComponent], exports: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule);
<!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/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/spread/source/data/customLocalization.js" type="text/javascript"></script> <!-- Polyfills --> <script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script> <script src="$DEMOROOT$/en/angular/node_modules/zone.js/fesm2015/zone.min.js"></script> <!-- SystemJS --> <script src="$DEMOROOT$/en/angular/node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.import('@angular/compiler'); System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('$DEMOROOT$/en/lib/angular/license.ts'); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html>
<div class="sample-tutorial"> <div class="sample-container"> <gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)"> <gc-worksheet> </gc-worksheet> </gc-spread-sheets> <div id="statusBar"></div> </div> <div class="sample-options"> <div class="options-container"> Switch Culture: <select id="CultureSelect" (change)="changeCultureName($event)"> <option value="en">en</option> <option value="zh_tw">zh-tw</option> <option value="fr">fr</option> <option value="de">de</option> <option value="ha_ha">Ha-Ha</option> </select> <p>{{l_description}}</p> <textarea id="language" cols="85" rows="40" style="max-width: 98%; height: 500px" readonly="readonly" [value]="language"></textarea> <div class="sample-options"> <div class="options-container"> </div> </div> </div> </div> </div>
* { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } .sample-options { float: right; height: 100%; } .options-toggle { display: none; } .sample-tutorial { height: 100%; overflow: hidden; position: relative; } .sample-container { width: calc(100% - 280px); height: 100%; float: left; position: relative; } .sample-spreadsheets { width: 100%; height: calc(100% - 25px); overflow: hidden; } #statusBar { bottom: 0; height: 25px; width: 100%; position: absolute; } .options-container { float: right; width: 280px; padding: 12px; 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; box-sizing: border-box; width: 100%; } input[type=button] { margin-top: 6px; display: block; } .summary { background-color: #e6e6fa; padding: 3px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
(function (global) { System.config({ transpiler: 'ts', typescriptOptions: { tsconfig: true }, meta: { 'typescript': { "exports": "ts" }, '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { 'core-js': 'npm:core-js/client/shim.min.js', 'zone': 'npm:zone.js/fesm2015/zone.min.js', 'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js', '@angular/core': 'npm:@angular/core/fesm2022', '@angular/common': 'npm:@angular/common/fesm2022/common.mjs', '@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs', '@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs', '@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs', '@angular/router': 'npm:@angular/router/fesm2022/router.mjs', '@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs', 'jszip': 'npm:jszip/dist/jszip.min.js', 'typescript': 'npm:typescript/lib/typescript.js', 'ts': './plugin.js', 'tslib':'npm:tslib/tslib.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', '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-zh': 'npm:@mescius/spread-sheets-resources-zh/index.js', '@mescius/spread-sheets-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'ts' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, "node_modules/@angular": { defaultExtension: 'mjs' }, "@mescius/spread-sheets-angular": { defaultExtension: 'mjs' }, '@angular/core': { defaultExtension: 'mjs', main: 'core.mjs' } } }); })(this);