-
Notifications
You must be signed in to change notification settings - Fork 425
多语言
sunsonliu edited this page Aug 22, 2024
·
3 revisions
注:只在v0.8.47及以上版本中支持
new Cherry({
locale: 'zh_CN',
});
new Cherry({
locale: 'ja_JP',
locales: {
'ja_JP': {
bold: '加粗',
italic: '代码',
...
...
},
},
});
具体有哪些词条,可以参考这里
方案一:通过工具栏
new Cherry({
locale: 'zh_CN',
toolbars: {
toolbarRight: ['fullscreen', '|', 'changeLocale'], // 把changeLocale放到右侧工具栏中
}
});
效果如下:
没有自己扩展的语言怎么办?如下操作:
new Cherry({
locale: 'zh_CN',
toolbars: {
toolbarRight: ['fullscreen', '|', 'changeLocale'], // 把changeLocale放到右侧工具栏中
config: {
changeLocale: [
{
locale: 'ja_JP',
name: 'xxxxx',
},
{
locale: 'zh_CN',
name: '中文',
},
{
locale: 'en_US',
name: 'English',
},
{
locale: 'ru_RU',
name: 'Русский',
},
],
},
}
});
方案二:通过api
const cherryObj = new Cherry();
cherryObj.setLocale('en_US');
- 第一步:配置切换语言的事件回调,参考这里
- 第二步:把切换语言的工具栏配置出来
- 第三步:当用户切换语言时,把目标语言持久化到本地或服务端
- 第四步:新页面重新实例化cherry时,从持久化里拿到目标语言放进配置项里