refactor(admin): using i18next

This commit is contained in:
dntzhang 2021-08-31 10:54:16 +08:00
parent 7df3fd4346
commit 02095dba93
18 changed files with 279 additions and 475 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@omiu/select",
"version": "0.0.14",
"version": "0.0.15",
"description": "Mobile pop-up options list",
"docsExtend": {
"cnName": "下拉菜单",

View File

@ -109,7 +109,7 @@ export default class Select extends WeElement<Props> {
Number(
this.tags
? this.tags.clientHeight +
(this.tags.clientHeight > heightMap[this.props.size] ? 6 : 0)
(this.tags.clientHeight > heightMap[this.props.size] ? 6 : 0)
: 0
)
)
@ -138,7 +138,7 @@ export default class Select extends WeElement<Props> {
label: string
install() {
beforeRender() {
if (this.props.multiple) {
for (let i = 0, len = this.props.items.length; i < len; i++) {
if (this.props.value.indexOf(this.props.items[i].value) !== -1) {

View File

@ -7,7 +7,6 @@
"serve": "vite preview"
},
"devDependencies": {
"@rollup/plugin-yaml": "^3.1.0",
"cross-env": "^7.0.3",
"less": "^4.1.1",
"sass": "^1.35.1",
@ -47,7 +46,7 @@
"@omiu/progress": "^0.0.3",
"@omiu/radio": "^0.0.6",
"@omiu/rate": "^0.0.9",
"@omiu/select": "^0.0.13",
"@omiu/select": "^0.0.15",
"@omiu/slider": "0.0.15",
"@omiu/steps": "^0.0.5",
"@omiu/switch": "^0.0.2",
@ -63,6 +62,8 @@
"axios": "^0.21.1",
"bytemd": "^1.10.13",
"file-saver": "^2.0.5",
"i18next": "^20.4.0",
"i18next-resources-to-backend": "^1.0.0",
"imagesloaded": "^4.1.4",
"markdown-it": "^12.1.0",
"markdown-it-anchor": "^8.1.0",

View File

@ -1,13 +1,13 @@
import { i18n } from '~/modules/i18n'
import i18next from 'i18next'
import { genId } from '../../../util/id'
export const getIntroductionNode = () => {
return {
label: i18n.t('Introduction'),
label: i18next.t('Introduction'),
//icon: 'description',
href: '#/docs/introduction',
md:
i18n.locale === 'zh'
i18next.language === 'zh'
? import(`./zh/introduction.md?raw`)
: import(`./en/introduction.md?raw`),
// vite 目前不支持
@ -18,11 +18,11 @@ export const getIntroductionNode = () => {
export const getThemeNode = () => {
return {
label: i18n.t('CustomTheme'),
label: i18next.t('CustomTheme'),
//icon: 'description',
href: '#/docs/theme',
md:
i18n.locale === 'zh'
i18next.language === 'zh'
? import(`./zh/theme.md?raw`)
: import(`./en/theme.md?raw`),
// vite 目前不支持
@ -33,11 +33,11 @@ export const getThemeNode = () => {
export const getContribution = () => {
return {
label: i18n.t('Contribution'),
label: i18next.t('Contribution'),
//icon: 'description',
href: '#/docs/contribution',
md:
i18n.locale === 'zh'
i18next.language === 'zh'
? import(`./zh/Contribution.md?raw`)
: import(`./en/Contribution.md?raw`),
// vite 目前不支持

View File

@ -1,17 +1,17 @@
import { i18n } from '~/modules/i18n'
import i18next from 'i18next'
import { genId } from '../../util/id'
export const getDocsList = () => {
return [
{
label: i18n.t('Demo1'),
label: i18next.t('Demo1'),
icon: 'description',
href: '#/docs/demo1',
md: import('./demo.md?raw'),
id: genId()
},
{
label: i18n.t('Demo2'),
label: i18next.t('Demo2'),
icon: 'description',
href: '#/docs/demo2',
md: import('./demo2.md?raw'),

View File

@ -0,0 +1,88 @@
export const base = {
translation: {
ManagerWorkbench: 'Manager Workbench',
Welcome: 'Welcome',
ColorPicker: 'ColorPicker',
Theme: 'Theme',
WelcomePage: 'Welcome age',
BasicTable: 'Basic Table',
TableDeleteAnimation: 'Table Delete Animation',
Form: 'Form',
MaterialIcons: 'Material Icons',
Others: 'Others',
Error: 'Error',
Warning: 'Warning',
Comment: 'Comment',
ExternalLink: 'External Link',
MarkdownDocs: 'Markdown Docs',
Demo1: 'Demo1',
Demo2: 'Demo2',
Components: 'OMIU Components',
Input: 'Input',
Loading: 'Loading',
Toast: 'Toast',
Tree: 'Tree',
ToggleIcon: 'ToggleIcon',
Card: 'Card',
Checkbox: 'Checkbox',
Radio: 'Radio',
Slider: 'Slider',
Switch: 'Switch',
Progress: 'Progress',
Pagination: 'Pagination',
InlineEditing: 'Inline Editing Table',
MarkdownEditor: 'Markdown Editor',
Dashboard: 'Dashboard',
TimePicker: 'Time Picker',
MindMap: 'Mind Map',
ManyThanksTo: 'Many Thanks To',
Results: 'Results Pages',
BrowserIncompatible: 'Browser Incompatible',
NetworkError: 'Network Error',
NotFound: 'Not Found',
PermissionDenied: 'Permission Denied',
ServerError: 'Server Error',
MasonryList: 'Masonry List',
NotificationList: 'NotificationList',
PersonalCenter: 'PersonalCenter',
Introduction: 'Introduction',
CustomTheme: 'Custom Theme',
Contribution: 'Add new component',
StepsForm: 'Steps Form',
Button: 'Button',
HamburgerMenu: 'HamburgerMenu',
Link: 'Link',
Tabs: 'Tabs',
Breadcrumb: 'Breadcrumb',
BottomNav: 'BottomNav',
Tag: 'Tag',
Rate: 'Rate',
BasicList: 'Basic List',
Cascader: 'Cascader',
Chart: 'OMIU Charts',
Bar: 'Bar',
Line: 'Line',
Scatter: 'Scatter',
Pie: 'Pie',
Doughnut: 'Doughnut',
Radar: 'radar',
PolarArea: 'polarArea',
Bubble: 'Bubble',
Barline: 'Barline',
Success: 'Success',
Failure: 'Failure',
Dialog: 'Dialog',
Avatar: 'Avatar',
Badge: 'Badge',
ActionSheet: 'ActionSheet',
Collapse: 'Collapse'
}
}

View File

@ -0,0 +1,90 @@
export const base = {
translation: {
ManagerWorkbench: '管理者工作台',
Welcome: '欢迎',
Theme: '主题',
ColorPicker: 'ColorPicker 颜色选择器',
WelcomePage: '欢迎界面',
BasicTable: '基础表格',
TableDeleteAnimation: '表格删除动画',
Form: '表单',
MaterialIcons: 'Material 图标',
Others: '其他',
Error: '错误告警',
Warning: '异常告警',
Comment: '评论模块',
ExternalLink: '外部链接',
MarkdownDocs: 'Markdown 文档',
Demo1: '文档例子1',
Demo2: '文档例子2',
Components: 'OMIU 组件',
Input: 'Input 输入框',
Loading: 'Loading 加载中',
Toast: 'Toast 弹出式提示',
Tree: 'Tree 树形控件',
ToggleIcon: 'ToggleIcon 可切换图标',
Card: 'Card 卡片',
Checkbox: 'Checkbox 复选框',
Radio: 'Radio 单选框',
Slider: 'Slider 滑块',
Switch: 'Switch 开关按钮',
Progress: 'Progress 进度条',
Pagination: 'Pagination 分页',
InlineEditing: '表格行内编辑',
MarkdownEditor: 'Markdown 编辑器',
Dashboard: '仪表盘',
TimePicker: 'Time Picker 时间选择器',
MindMap: '思维导图',
ManyThanksTo: '感谢有你',
Results: '结果页',
BrowserIncompatible: '浏览器不兼容',
NetworkError: '网络异常',
NotFound: '访问页面不存在',
PermissionDenied: '无权限',
ServerError: '服务端错误',
MasonryList: '瀑布流列表',
NotificationList: '通知中心',
PersonalCenter: '个人中心',
Introduction: '简介',
CustomTheme: '自定义主题',
Contribution: '加入新组件',
StepsForm: '分步表单',
Button: 'Button 按钮',
HamburgerMenu: 'HamburgerMenu 汉堡包菜单',
Link: 'Link 文字链接',
Tabs: 'Tabs 选项卡',
Breadcrumb: 'Breadcrumb 面包屑',
BottomNav: 'BottomNav 底部导航',
Rate: 'Rate 评分',
Tag: 'Tag 标签',
BasicList: '基础列表',
Cascader: 'Cascader 级联选择器',
Chart: 'OMIU 图表',
Bar: '柱状图',
Line: '线状图',
Scatter: '散点图',
Pie: '饼图',
Doughnut: '环状图',
Radar: '雷达图',
PolarArea: '极区图',
Bubble: '气泡图',
Barline: '合成图',
Success: '成功页',
Failure: '失败页',
Dialog: 'Dialog 弹窗层',
Avatar: 'Avatar 头像',
Badge: 'Badge 徽章',
ActionSheet: 'ActionSheet 弹出式菜单',
Collapse: 'Collapse 折叠'
}
}

View File

@ -33,7 +33,6 @@ import './components/admin-main-welcome'
import { tw, sheet } from 'omi-twind'
import Store from './store'
import { i18n } from './modules/i18n'
const fadeCSS = `.fade-leave-to,
.fade-enter {
@ -55,7 +54,6 @@ export default class extends WeElement {
tagName: 'admin-main-welcome'
}
i18n = i18n
transition
@ -96,6 +94,8 @@ export default class extends WeElement {
// hashChange()
this.routeTo(location.hash)
}
this.store.routeTo = this.routeTo.bind(this)
}
store
@ -121,30 +121,32 @@ export default class extends WeElement {
md: any
} = this.findNodeByHash(hash, this.store.treeData)
this.store.selectTreeNodeById(node.id)
if (node) {
this.store.selectTreeNodeById(node.id)
if (!node.children) {
const tab = this.store.tabs.find((tab) => tab.id === node.id)
if (tab) {
this.store.tabsActiveIndex = this.store.tabs.indexOf(tab)
} else {
this.store.tabs.push({
label: node.label,
closeable: false,
id: node.id,
href: node.href
})
this.store.tabsActiveIndex = this.store.tabs.length - 1
if (!node.children) {
const tab = this.store.tabs.find((tab) => tab.id === node.id)
if (tab) {
this.store.tabsActiveIndex = this.store.tabs.indexOf(tab)
} else {
this.store.tabs.push({
label: node.label,
closeable: false,
id: node.id,
href: node.href
})
this.store.tabsActiveIndex = this.store.tabs.length - 1
}
}
}
// @ts-ignore
node.md &&
node.md.then((e) => {
this.store.markdown = e.default
})
// @ts-ignore
node.md &&
node.md.then((e) => {
this.store.markdown = e.default
})
// 重新读取 hash 值
hashChange()
// 重新读取 hash 值
hashChange()
}
}
render() {
@ -163,11 +165,8 @@ export default class extends WeElement {
}
}
// config i18n default language in ~/modules/i18n
render(
<my-app name="Omi"></my-app>,
'#root',
new Store({
i18n
})
new Store({})
)

View File

@ -1,86 +0,0 @@
export const base = {
ManagerWorkbench: 'Manager Workbench',
Welcome: 'Welcome',
ColorPicker: 'ColorPicker',
Theme: 'Theme',
WelcomePage: 'Welcome age',
BasicTable: 'Basic Table',
TableDeleteAnimation: 'Table Delete Animation',
Form: 'Form',
MaterialIcons: 'Material Icons',
Others: 'Others',
Error: 'Error',
Warning: 'Warning',
Comment: 'Comment',
ExternalLink: 'External Link',
MarkdownDocs: 'Markdown Docs',
Demo1: 'Demo1',
Demo2: 'Demo2',
Components: 'OMIU Components',
Input: 'Input',
Loading: 'Loading',
Toast: 'Toast',
Tree: 'Tree',
ToggleIcon: 'ToggleIcon',
Card: 'Card',
Checkbox: 'Checkbox',
Radio: 'Radio',
Slider: 'Slider',
Switch: 'Switch',
Progress: 'Progress',
Pagination: 'Pagination',
InlineEditing: 'Inline Editing Table',
MarkdownEditor: 'Markdown Editor',
Dashboard: 'Dashboard',
TimePicker: 'Time Picker',
MindMap: 'Mind Map',
ManyThanksTo: 'Many Thanks To',
Results: 'Results Pages',
BrowserIncompatible: 'Browser Incompatible',
NetworkError: 'Network Error',
NotFound: 'Not Found',
PermissionDenied: 'Permission Denied',
ServerError: 'Server Error',
MasonryList: 'Masonry List',
NotificationList: 'NotificationList',
PersonalCenter: 'PersonalCenter',
Introduction: 'Introduction',
CustomTheme: 'Custom Theme',
Contribution: 'Add new component',
StepsForm: 'Steps Form',
Button: 'Button',
HamburgerMenu: 'HamburgerMenu',
Link: 'Link',
Tabs: 'Tabs',
Breadcrumb: 'Breadcrumb',
BottomNav: 'BottomNav',
Tag: 'Tag',
Rate: 'Rate',
BasicList: 'Basic List',
Cascader: 'Cascader',
Chart: 'OMIU Charts',
Bar: 'Bar',
Line: 'Line',
Scatter: 'Scatter',
Pie: 'Pie',
Doughnut: 'Doughnut',
Radar: 'radar',
PolarArea: 'polarArea',
Bubble: 'Bubble',
Barline: 'Barline',
Success: 'Success',
Failure: 'Failure',
Dialog: 'Dialog',
Avatar: 'Avatar',
Badge: 'Badge',
ActionSheet: 'ActionSheet',
Collapse: 'Collapse'
}

View File

@ -1,87 +0,0 @@
export const base = {
ManagerWorkbench: '管理者工作台',
Welcome: '欢迎',
Theme: '主题',
ColorPicker: 'ColorPicker 颜色选择器',
WelcomePage: '欢迎界面',
BasicTable: '基础表格',
TableDeleteAnimation: '表格删除动画',
Form: '表单',
MaterialIcons: 'Material 图标',
Others: '其他',
Error: '错误告警',
Warning: '异常告警',
Comment: '评论模块',
ExternalLink: '外部链接',
MarkdownDocs: 'Markdown 文档',
Demo1: '文档例子1',
Demo2: '文档例子2',
Components: 'OMIU 组件',
Input: 'Input 输入框',
Loading: 'Loading 加载中',
Toast: 'Toast 弹出式提示',
Tree: 'Tree 树形控件',
ToggleIcon: 'ToggleIcon 可切换图标',
Card: 'Card 卡片',
Checkbox: 'Checkbox 复选框',
Radio: 'Radio 单选框',
Slider: 'Slider 滑块',
Switch: 'Switch 开关按钮',
Progress: 'Progress 进度条',
Pagination: 'Pagination 分页',
InlineEditing: '表格行内编辑',
MarkdownEditor: 'Markdown 编辑器',
Dashboard: '仪表盘',
TimePicker: 'Time Picker 时间选择器',
MindMap: '思维导图',
ManyThanksTo: '感谢有你',
Results: '结果页',
BrowserIncompatible: '浏览器不兼容',
NetworkError: '网络异常',
NotFound: '访问页面不存在',
PermissionDenied: '无权限',
ServerError: '服务端错误',
MasonryList: '瀑布流列表',
NotificationList: '通知中心',
PersonalCenter: '个人中心',
Introduction: '简介',
CustomTheme: '自定义主题',
Contribution: '加入新组件',
StepsForm: '分步表单',
Button: 'Button 按钮',
HamburgerMenu: 'HamburgerMenu 汉堡包菜单',
Link: 'Link 文字链接',
Tabs: 'Tabs 选项卡',
Breadcrumb: 'Breadcrumb 面包屑',
BottomNav: 'BottomNav 底部导航',
Rate: 'Rate 评分',
Tag: 'Tag 标签',
BasicList: '基础列表',
Cascader: 'Cascader 级联选择器',
Chart: 'OMIU 图表',
Bar: '柱状图',
Line: '线状图',
Scatter: '散点图',
Pie: '饼图',
Doughnut: '环状图',
Radar: '雷达图',
PolarArea: '极区图',
Bubble: '气泡图',
Barline: '合成图',
Success: '成功页',
Failure: '失败页',
Dialog: 'Dialog 弹窗层',
Avatar: 'Avatar 头像',
Badge: 'Badge 徽章',
ActionSheet: 'ActionSheet 弹出式菜单',
Collapse: 'Collapse 折叠'
}

View File

@ -9,9 +9,9 @@ import '@omiu/icon/notifications'
import '@omiu/icon/settings'
import '@omiu/icon/git-hub'
import '@omiu/badge'
import { i18n } from '~/modules/i18n'
import i18next from 'i18next'
interface Props {}
interface Props { }
const tagName = 'layout-header'
declare global {
@ -67,7 +67,7 @@ export default class extends WeElement<Props> {
goNotification = () => {
// header-tabs是否存在通知中心存在则tab为Object
const tab = this.store.tabs.find(
(tab) => tab.label === i18n.t('NotificationList')
(tab) => tab.label === i18next.t('NotificationList')
)
// 如果tab栏无通知中心则store push
@ -77,8 +77,8 @@ export default class extends WeElement<Props> {
location.hash = tab.href
} else {
const notificationTab = this.store.treeData
.find((item) => item.label === i18n.t('ManagerWorkbench'))
.children.find((item) => item.label === i18n.t('NotificationList'))
.find((item) => item.label === i18next.t('ManagerWorkbench'))
.children.find((item) => item.label === i18next.t('NotificationList'))
this.store.tabs.push(notificationTab)
this.store.tabsActiveIndex = this.store.tabs.length - 1
this.store.selectTreeNodeById(notificationTab.id)
@ -89,7 +89,7 @@ export default class extends WeElement<Props> {
goPersonalCenter = () => {
// 待页面搭建完成后开放
const tab = this.store.tabs.find(
(tab) => tab.label === i18n.t('PersonalCenter')
(tab) => tab.label === i18next.t('PersonalCenter')
)
if (tab) {
@ -98,8 +98,8 @@ export default class extends WeElement<Props> {
location.hash = tab.href
} else {
const PersonalCenterTab = this.store.treeData
.find((item) => item.label === i18n.t('ManagerWorkbench'))
.children.find((item) => item.label === i18n.t('PersonalCenter'))
.find((item) => item.label === i18next.t('ManagerWorkbench'))
.children.find((item) => item.label === i18next.t('PersonalCenter'))
this.store.tabs.push(PersonalCenterTab)
this.store.tabsActiveIndex = this.store.tabs.length - 1
this.store.selectTreeNodeById(PersonalCenterTab.id)
@ -126,7 +126,7 @@ export default class extends WeElement<Props> {
`}
size="mini"
onItemSelect={this.onItemSelect}
value={this.store.i18n.locale}
value={i18next.language}
items={this.items}
></o-select>
</div>
@ -142,7 +142,7 @@ export default class extends WeElement<Props> {
style={{ color: this.store.themeColor }}
>
<o-icon-palette></o-icon-palette>
{i18n.t('Theme')}
{i18next.t('Theme')}
</div>
{this.isShowColorPicker && (
<o-color-picker

View File

@ -1,84 +0,0 @@
ManagerWorkbench: "Manager Workbench"
Welcome: "Welcome"
ColorPicker: "ColorPicker"
Theme: "Theme"
WelcomePage: "Welcome age"
BasicTable: "Basic Table"
TableDeleteAnimation: "Table Delete Animation"
Form: "Form"
MaterialIcons: "Material Icons"
Others: "Others"
Error: "Error"
Warning: "Warning"
Comment: "Comment"
ExternalLink: "External Link"
MarkdownDocs: "Markdown Docs"
Demo1: "Demo1"
Demo2: "Demo2"
Components: "OMIU Components"
Input: "Input"
Loading: "Loading"
Toast: "Toast"
Tree: "Tree"
ToggleIcon: "ToggleIcon"
Card: "Card"
Checkbox: "Checkbox"
Radio: "Radio"
Slider: "Slider"
Switch: "Switch"
Progress: "Progress"
Pagination: "Pagination"
InlineEditing: "Inline Editing Table"
MarkdownEditor: "Markdown Editor"
Dashboard: "Dashboard"
TimePicker: "Time Picker"
MindMap: "Mind Map"
ManyThanksTo: "Many Thanks To"
Results: "Results Pages"
BrowserIncompatible: "Browser Incompatible"
NetworkError: "Network Error"
NotFound: "Not Found"
PermissionDenied: "Permission Denied"
ServerError: "Server Error"
MasonryList: "Masonry List"
NotificationList: "NotificationList"
PersonalCenter: "PersonalCenter"
Introduction: "Introduction"
CustomTheme: "Custom Theme"
Contribution: "Add new component"
StepsForm: "Steps Form"
Button: "Button"
HamburgerMenu: "HamburgerMenu"
Link: "Link"
Tabs: "Tabs"
Breadcrumb: "Breadcrumb"
BottomNav: "BottomNav"
Tag: "Tag"
Rate: "Rate"
BasicList: "Basic List"
Cascader: "Cascader"
Chart: "OMIU Charts"
Bar: "Bar"
Line: "Line"
Scatter: "Scatter"
Pie: "Pie"
Doughnut: "Doughnut"
Radar: "radar"
PolarArea: "polarArea"
Bubble: "Bubble"
Barline: "Barline"
Success: "Success"
Failure: "Failure"
Dialog: "Dialog"
Avatar: "Avatar"
Badge: "Badge"
ActionSheet: "ActionSheet"
Collapse: "Collapse"

View File

@ -1,85 +0,0 @@
ManagerWorkbench: "管理者工作台"
Welcome: "欢迎"
Theme: "主题"
ColorPicker: "ColorPicker 颜色选择器"
WelcomePage: "欢迎界面"
BasicTable: "基础表格"
TableDeleteAnimation: "表格删除动画"
Form: "表单"
MaterialIcons: "Material 图标"
Others: "其他"
Error: "错误告警"
Warning: "异常告警"
Comment: "评论模块"
ExternalLink: "外部链接"
MarkdownDocs: "Markdown 文档"
Demo1: "文档例子1"
Demo2: "文档例子2"
Components: "OMIU 组件"
Input: "Input 输入框"
Loading: "Loading 加载中"
Toast: "Toast 弹出式提示"
Tree: "Tree 树形控件"
ToggleIcon: "ToggleIcon 可切换图标"
Card: "Card 卡片"
Checkbox: "Checkbox 复选框"
Radio: "Radio 单选框"
Slider: "Slider 滑块"
Switch: "Switch 开关按钮"
Progress: "Progress 进度条"
Pagination: "Pagination 分页"
InlineEditing: "表格行内编辑"
MarkdownEditor: "Markdown 编辑器"
Dashboard: "仪表盘"
TimePicker: "Time Picker 时间选择器"
MindMap: "思维导图"
ManyThanksTo: "感谢有你"
Results: "结果页"
BrowserIncompatible: "浏览器不兼容"
NetworkError: "网络异常"
NotFound: "访问页面不存在"
PermissionDenied: "无权限"
ServerError: "服务端错误"
MasonryList: "瀑布流列表"
NotificationList: "通知中心"
PersonalCenter: "个人中心"
Introduction: "简介"
CustomTheme: "自定义主题"
Contribution: "加入新组件"
StepsForm: "分步表单"
Button: "Button 按钮"
HamburgerMenu: "HamburgerMenu 汉堡包菜单"
Link: "Link 文字链接"
Tabs: "Tabs 选项卡"
Breadcrumb: "Breadcrumb 面包屑"
BottomNav: "BottomNav 底部导航"
Rate: "Rate 评分"
Tag: "Tag 标签"
BasicList: "基础列表"
Cascader: "Cascader 级联选择器"
Chart: "OMIU 图表"
Bar: "柱状图"
Line: "线状图"
Scatter: "散点图"
Pie: "饼图"
Doughnut: "环状图"
Radar: "雷达图"
PolarArea: "极区图"
Bubble: "气泡图"
Barline: "合成图"
Success: "成功页"
Failure: "失败页"
Dialog: "Dialog 弹窗层"
Avatar: "Avatar 头像"
Badge: "Badge 徽章"
ActionSheet: "ActionSheet 弹出式菜单"
Collapse: "Collapse 折叠"

View File

@ -1,59 +0,0 @@
export type Language = 'zh' | 'en'
export const languages: Language[] = ['en', 'zh']
export const t = (key: string, messages: Object) => {
if (!key) return ''
const keyArr = key.split('.')
const name = keyArr.shift()
if (!keyArr.length) {
return messages[name] || name
} else {
return t(keyArr.join('.'), messages[name])
}
}
export const createI18n = (options: { locale: Language; messages: Object }) => {
let locale = options.locale || 'zh'
const i18n = {
locale,
setLocale: (locale: Language) => {
i18n.locale = locale
i18n.t = (key: string) => t(key, messages[locale])
},
t: (key: string) => t(key, messages[locale]),
messages
}
return i18n
}
// import i18n resources
// https://vitejs.dev/guide/features.html#glob-import
const relativePath = '../locales/'
export const messages = Object.fromEntries(
// globEager can not use variable
Object.entries(import.meta.globEager('../locales/*.y(a)?ml')).map(
([key, value]) => {
const yaml = key.endsWith('.yaml')
return [key.slice(relativePath.length, yaml ? -5 : -4), value.default]
}
)
)
export const install = () => {
const i18n = createI18n({
locale: 'zh',
messages
})
return i18n
}
export const i18n = createI18n({
locale: 'zh',
messages
})
export type I18nType = ReturnType<typeof createI18n>
export default i18n

View File

@ -5,7 +5,6 @@ import {
getContribution
} from './components/components/docs/config'
import { genId } from './util/id'
import type { I18nType } from '~/modules/i18n'
export interface NavTree {
id?: number
@ -28,7 +27,7 @@ interface ComponentChild {
href: string
}
export function genNavTree(i18n: I18nType) {
export function genNavTree(i18n) {
const navTree: NavTree[] = [
{
label: i18n.t('ManagerWorkbench'),

View File

@ -87,12 +87,14 @@ export function registerRouting(rootEl) {
route('/docs/:name', (evt) => {
//lazy load
const md = rootEl.getMdByName(evt.params.name, rootEl.store.treeData)
md.then((e) => {
rootEl.payload = { mdContent: e.default, padding: 20 }
import('./components/docs/admin-docs').then(() =>
rootEl.transitionTo('admin-docs')
)
})
if (md) {
md.then((e) => {
rootEl.payload = { mdContent: e.default, padding: 20 }
import('./components/docs/admin-docs').then(() =>
rootEl.transitionTo('admin-docs')
)
})
}
})

View File

@ -3,13 +3,15 @@ import { genNavTree, NavTree } from './nav-tree'
import { getNotifications } from './service/notifications'
import { resetId } from './util/id'
import { route } from 'omi-router'
import type { I18nType, Language } from './modules/i18n'
import i18next from 'i18next'
import resourcesToBackend from 'i18next-resources-to-backend'
class Store {
i18n: I18nType
themeColor: string
installed: (store: Store) => void
locale: Language
isLeftPanelClosed: boolean
ignoreAttrs: boolean
ui: {
@ -35,7 +37,6 @@ class Store {
}[]
constructor(options) {
this.i18n = options.i18n
this.themeColor = '#07c160'
@ -46,14 +47,15 @@ class Store {
this.ignoreAttrs = true
this.ui = {}
this.treeData = []
this.tabs = []
this.markdown = ''
this.html = ''
this.setLocale(this.i18n.locale, () => {
this.setLocale('zh', () => {
this.tabs = [
{
label: this.i18n.t('Welcome'),
label: i18next.t('Welcome'),
href: '#/welcome',
closable: false,
id: 2
@ -72,16 +74,43 @@ class Store {
}
}
setLocale(locale: Language, callback?: () => void) {
async setLocale(locale, callback?: () => void) {
resetId()
this.i18n.setLocale(locale)
await i18next
.use(resourcesToBackend((language, namespace, callback) => {
import(`./i18n/${locale}/base.ts`)
.then((resources) => {
callback(null, resources.base.translation)
})
.catch((error) => {
callback(error, null)
})
}))
.init({
lng: locale
})
// .then(() => {
// console.log(i18next.t('ManagerWorkbench'))
// })
callback && callback()
this.treeData = genNavTree(this.i18n)
this.treeData = genNavTree(i18next)
this.tabs &&
this.tabs.forEach((tab) => {
tab.label = this.getTabLabelById(tab.id)
})
this.ui.myApp.update()
if (location.hash) {
this.routeTo(location.hash)
}
}
routeTo(hash) {
}
getTabLabelById(id) {

View File

@ -2,8 +2,6 @@ import path from 'path'
import { viteMockServe } from 'vite-plugin-mock'
import { defineConfig } from 'vite'
import yaml from '@rollup/plugin-yaml'
export default defineConfig(({ command }) => {
return {
resolve: {
@ -15,8 +13,7 @@ export default defineConfig(({ command }) => {
viteMockServe({
mockPath: 'mock',
localEnabled: command == 'serve'
}),
yaml()
})
],
esbuild: {
jsxFactory: 'h',