跳到主要内容

React Spreadsheet 本地化

React Spreadsheet 针对 UI 的不同方面提供了两套独立的本地化机制。

两种本地化机制

机制Prop控制范围
UI 本地化spreadsheetLocale菜单标签、工具栏提示、对话框文字及本地化公式名称
数字/日期格式化localization小数分隔符、货币符号、日期/时间显示格式

这两个 props 相互独立,可单独使用,也可同时使用。

UI 本地化(spreadsheetLocale)

spreadsheetLocale prop 接受一个 SpreadsheetLocale 对象,该对象包含两个属性:

  • locale - Record<string, string> 类型,用于覆盖 UI 字符串
  • formulas - Record<string, [string, string?][]> 类型,按类别分组的本地化公式名称
const locale: SpreadsheetLocale = {
locale: {
"File": "Datei",
"Edit": "Bearbeiten",
"Insert": "Einfügen",
"Undo": "Rückgängig",
"Redo": "Wiederherstellen",
// ... 更多 UI 字符串
},
formulas: {
"MATCH": [
["Suchwert", "Erforderlich. Der Wert, der im Sucharray abgeglichen werden soll."],
["Sucharray", "Erforderlich. Ein Zellbereich oder ein Array-Bezug."],
],
// ... 更多公式类别
},
};

<ReactSpreadsheet sheets={sheets} spreadsheetLocale={locale} />
警告

spreadsheetLocale 是仅初始化 prop。在初次渲染后修改该值会导致 widget 被销毁并重新创建,撤销/重做历史记录及 UI 状态(选区、滚动位置)将被重置。

数字/日期格式化(localization)

localization prop 控制数字和日期的显示方式,包括小数分隔符、货币符号和日期格式。其格式与 DHTMLX Spreadsheet 的 localization 配置属性相同。

<ReactSpreadsheet
sheets={sheets}
localization={{
decimal: ",",
thousands: " ",
currency: "€",
}}
/>
警告

localization 同样是仅初始化 prop。修改该值会触发完整的销毁/重建周期。