- 点击绿色run按钮
- 编辑 index.ts 并观看实时更新!
您可以在多维表格扩展脚本开发指南中了解更多信息 )。
在 Shell 窗格中安装npm包或在 Packages 窗格中搜索并添加。
本模板使用jquery-i18next进行国际化。
- 在js文件中通过$.t()调用,如中文环境下:
console.log($.t('content', {num:888})) // '这是中文内容888'
console.log($.t('title')) // '这是中文标题'
- 在标签中使用: 通过将属性data-i18n设置为某个语言配置的key,在使用该语言的时候,将使用该key对应的值覆盖标签的内容,从而实现国际化。 data-i18n-options用于插值,同$.t函数的第二个参数,将替换语言配置中被{{}}包裹的变量。
<h1 data-i18n="title">默认标题</h1>
<h2 data-i18n="content" data-i18n-options='{"num":888}'> </h2>
如果要在input等不含子元素的元素中使用,则需要给data-i18n属性值加上 [希望赋值的标签属性] 前缀, 比如,给input的placeholder属性进行国际化配置:
<input data-i18n="[placeholder]title"/>
- Hit run
- Edit index.ts and watch it live update!
You can learn more in the Base Extension Development Guide
Install packages in Shell pane or search and add in Packages pane.
This template uses jquery-i18next for internationalization.
- Called through $.t() in the js file, such as in Chinese environment:
console.log($.t('content', {num:888})) // '这是中文内容888'
console.log($.t('title')) // '这是中文标题'
- Use in tags: By setting the attribute data-i18n to the key configured in a certain language, when using that language, the value corresponding to the key will be used to overwrite the content of the tag, thereby achieving internationalization. data-i18n-options are used for interpolation. They are the same as the second parameter of the $.t function and will replace the variables wrapped in {{}} in the language configuration.
<h1 data-i18n="title">默认标题</h1>
<h2 data-i18n="content" data-i18n-options='{"num":888}'> </h2>
If you want to use it in an element without child elements such as input, you need to prefix the data-i18n attribute value with [the label attribute you want to assign]. For example, configure internationalization for the placeholder attribute of input:
<input data-i18n="[placeholder]title"/>