自定义本地化

自定义本地化提供了自定义Spread的能力。带有特定语言的表单。

<p>用户需要使用模式定义本地化对象,添加到CultureManager,然后切换到已定义的区域性。 工作表使用定义的单词显示不同的属性。</p> <p>列如:</p> <pre><code class="hljs js language-js"><span class="hljs-keyword">var</span> lang = { <span class="hljs-comment">// localization config goes here</span> Sheets = { <span class="hljs-attr">Tip_Row</span>: <span class="hljs-string">"行 = "</span>, <span class="hljs-comment">//No parameters, will add the row number</span> <span class="hljs-attr">Tip_Column</span>: <span class="hljs-string">"列 = "</span>, <span class="hljs-attr">Tip_Height</span>: <span class="hljs-string">"高度: {0} 像素"</span>, <span class="hljs-comment">//Use the parameters </span> <span class="hljs-attr">Tip_Width</span>: <span class="hljs-string">"寬度: {0} 像素"</span>, }, <span class="hljs-attr">CalcEngine</span>: { <span class="hljs-attr">Fbx_Summary</span>: <span class="hljs-string">"概要"</span> }, <span class="hljs-attr">Functions</span>: { <span class="hljs-attr">SUM</span>: { <span class="hljs-attr">description</span>: <span class="hljs-string">"此函數返回某一單元格區域中所有數字之和。"</span>, <span class="hljs-attr">parameters</span>: [<span class="hljs-string">"值1"</span>, <span class="hljs-string">"值2"</span>] }, <span class="hljs-attr">NOW</span>: { <span class="hljs-attr">description</span>: <span class="hljs-string">"此函數返回當前的日期和時間。"</span> }, <span class="hljs-attr">IF</span>: { <span class="hljs-attr">description</span>: <span class="hljs-string">"使用邏輯函數 IF 函數時,如果條件為真,該函數將返回一個值;如果條件為假,函數將返回另一個值。"</span>, <span class="hljs-attr">parameters</span>: [<span class="hljs-string">"判断条件"</span>, <span class="hljs-string">"值1"</span>, <span class="hljs-string">"值2"</span>] }, } }; GC.Spread.Common.CultureManager.addCultureInfo(<span class="hljs-string">"zh-tw"</span>, <span class="hljs-literal">null</span>, lang); <span class="hljs-comment">//Add the language</span> GC.Spread.Common.CultureManager.culture(<span class="hljs-string">"zh-tw"</span>) <span class="hljs-comment">//set the culture</span> </code></pre> <p><strong>Hint:</strong></p> <p>如果没有设置某些语句,Spread将显示English(如果设置为空字符串" ",它将不显示任何内容).. 参数是使用{0},{1},…用于显示(例如:“无效{0}:{1}(必须在{2}和{3}之间)。”,“高度:{0}像素”)。 自定义本地化不支持fromJson/toJson,所以用户每次需要时都需要添加它。 示例中的名称空间(“common”、“Sheets”、“Filter”)是可选的。但是“函数”和“表函数”是必需的。下面的格式也是有效的。</p> <pre><code class="hljs js language-js"><span class="hljs-keyword">var</span> lang = { <span class="hljs-attr">Tip_Row</span>: <span class="hljs-string">"行 = "</span>, <span class="hljs-comment">//No parameters, will add the row </span> <span class="hljs-attr">Tip_Column</span>: <span class="hljs-string">"列 = "</span>, <span class="hljs-attr">Tip_Height</span>: <span class="hljs-string">"高度: {0} 像素"</span>, <span class="hljs-comment">//Use the parameters </span> <span class="hljs-attr">Tip_Width</span>: <span class="hljs-string">"寬度: {0} 像素"</span>, <span class="hljs-attr">CalcEngine</span>: { <span class="hljs-comment">//the CalcEngine can be optional, and put Fbx_Summary into the lang object.</span> <span class="hljs-attr">Fbx_Summary</span>: <span class="hljs-string">"概要"</span> }, <span class="hljs-attr">Functions</span>: { <span class="hljs-comment">//The "Functions" is needed to custom the function's description.</span> <span class="hljs-attr">SUM</span>: { <span class="hljs-attr">description</span>: <span class="hljs-string">"此函數返回某一單元格區域中所有數字之和。"</span>, <span class="hljs-attr">parameters</span>: [<span class="hljs-string">"值1"</span>, <span class="hljs-string">"值2"</span>] }, } }; </code></pre>
var spreadNS = GC.Spread.Sheets; window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 1}); initSpread(spread); } function initSpread(spread) { var sheet = spread.getActiveSheet(); spread.suspendPaint(); spread.options.showScrollTip = 3; spread.options.showResizeTip = 3; var table = sheet.tables.addFromDataSource("table1", 0, 0, source, GC.Spread.Sheets.Tables.TableThemes.medium2) 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); GC.Spread.Common.CultureManager.addCultureInfo("zh_tw", null, zh_tw); GC.Spread.Common.CultureManager.addCultureInfo("fr", null, fr); GC.Spread.Common.CultureManager.addCultureInfo("ha_ha", null, ha_ha); var statusBar = new GC.Spread.Sheets.StatusBar.StatusBar(document.getElementById('statusBar')); statusBar.bind(spread); spread.resumePaint(); var select = document.getElementById('CultureSelect'); select.addEventListener('change', function () { var culture = this.value; GC.Spread.Common.CultureManager.culture(culture); document.getElementById('l_description').innerText = langDescription[culture]; if (culture === "en") { document.getElementById('language').value = ""; } else { document.getElementById('language').value = JSON.stringify(window[culture], null, 2); } }); }
<!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="./node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="./node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/customLocalization.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div class="sample-container"> <div id="ss" class="sample-spreadsheets"></div> <div id="statusBar"></div> </div> <div class="sample-options"> <div class="options-container"> Switch Culture: <select id="CultureSelect"> <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 id="l_description">The base and default language.</p> <textarea id="language" cols="85" rows="40" style="max-width: 98%; height: 500px" readonly="readonly"></textarea> <div class="sample-options"> <div class="options-container"> </div> </div> </div> </div> </div> </body> </html>
* { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } .sample-options { float: right; height: 100%; } .options-toggle { display: none; } .sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-container { width: calc(100% - 280px); height: 100%; float: left; } .sample-spreadsheets { width: 100%; height: calc(100% - 25px); overflow: hidden; } #statusBar { bottom: 0; height: 25px; width: 100%; position: relative; } .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; }