Skip to content

Commit a874eca

Browse files
committed
Merge branch 'main' into docs
2 parents cf7ae50 + 7b278ed commit a874eca

File tree

17 files changed

+355
-28
lines changed

17 files changed

+355
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ app.mount('#app')
5656

5757
### License & Copyright
5858

59-
Copyright (c) 2014-2024 飞致云 FIT2CLOUD, All rights reserved.
59+
Copyright (c) 2014-2025 FIT2CLOUD 飞致云, All rights reserved.
6060

6161
Licensed under The GNU General Public License version 3 (GPLv3) (the "License"); you may not use this file except in
6262
compliance with the License. You may obtain a copy of the License at

examples/locale/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {createI18n} from 'vue-i18n';
2+
import zh from '@/locale/lang/zh-cn';
3+
import tw from '@/locale/lang/zh-tw';
4+
import en from '@/locale/lang/en';
5+
import ru from '@/locale/lang/ru';
6+
import ja from '@/locale/lang/ja';
7+
import ms from '@/locale/lang/ms';
8+
import pt from '@/locale/lang/pt-br';
9+
10+
const i18n = createI18n({
11+
legacy: false,
12+
locale: localStorage.getItem('lang') || 'zh',
13+
fallbackLocale: 'zh',
14+
globalInjection: true,
15+
messages: {
16+
zh,
17+
tw,
18+
ru,
19+
en,
20+
ja,
21+
ms,
22+
pt,
23+
},
24+
warnHtmlMessage: false,
25+
});
26+
27+
export default i18n;

examples/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {createApp} from 'vue'
22
import App from './App.vue'
3+
import i18n from './locale'
34
// 整体引入
45
import Fit2CloudPlus from '@/index'
56
import ElementPlus from 'element-plus'
@@ -14,9 +15,10 @@ import './index.scss';
1415

1516
const app = createApp(App);
1617
app.use(router)
17-
const options = {size: 'default', zIndex: 3000}
18+
const options = {size: 'default', zIndex: 3000, i18n: i18n.global.t}
1819
app.use(Fit2CloudPlus, options);
1920
app.use(ElementPlus, options)
21+
app.use(i18n);
2022
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
2123
app.component(key, component)
2224
}

examples/markdown/getting-started.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,53 @@ app.mount('#app')
132132
133133
```
134134

135+
## 国际化
136+
137+
创建国际化文件,例如:
138+
139+
```typescript
140+
// locale/lang/zh.ts
141+
import fit2cloudLocale from 'fit2cloud-ui-plus/src/locale/lang/ru'
142+
143+
const message = {
144+
home: "首页",
145+
...
146+
}
147+
148+
export default {
149+
...fit2cloudLocale,
150+
...message
151+
};
152+
```
153+
154+
初始化 i18n ,例如:创建 locale/index.ts 文件:
155+
156+
```typescript
157+
import {createI18n} from 'vue-i18n';
158+
import zh from './locale/lang/zh';
159+
import en from './locale/lang/en';
160+
161+
const i18n = createI18n({
162+
legacy: false,
163+
locale: localStorage.getItem('lang') || 'zh',
164+
fallbackLocale: 'zh',
165+
globalInjection: true,
166+
messages: {
167+
zh,
168+
en
169+
},
170+
warnHtmlMessage: false,
171+
});
172+
173+
export default i18n;
174+
175+
```
176+
177+
在 main.ts 中引入翻译的方法, 例如:
178+
179+
```typescript
180+
import i18n from './locale'
181+
182+
const options = {size: 'default', zIndex: 3000, i18n: i18n.global.t}
183+
app.use(Fit2CloudPlus, options);
184+
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fit2cloud-ui-plus",
3-
"version": "1.1.18",
3+
"version": "1.2.0",
44
"private": false,
55
"main": "./lib/fit2cloud-ui-plus.es.js",
66
"files": [
@@ -32,6 +32,7 @@
3232
"vite-plugin-markdown": "^2.0.2",
3333
"vue": "^3.2.37",
3434
"vue-clipboard3": "^2.0.0",
35+
"vue-i18n": "^10.0.5",
3536
"vue-router": "^4.0.14"
3637
},
3738
"devDependencies": {

src/components/table/table-column-select/FuTableColumnSelectPopover.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<template>
22
<el-popover class="fu-table-column-select" :popper-class="popperClass" :trigger="trigger"
33
:show-arrow="false" :style="{'visibility': hasSelect ? 'visible': 'hidden'}">
4-
<h3>
5-
{{ header }}
6-
</h3>
74
<div class="fu-table-column-select-popper__body">
85
<div v-for="(c, i) in columns" :key="i" class="fu-table-column-select-popper__item">
96
<el-checkbox v-model="c.show" :checked="c.show !== false" draggable="true" @dragstart="dragstart($event, i)"
@@ -79,8 +76,4 @@ const hasSelect = computed(() => {
7976
return props.columns?.length > 0 && !isFixAll.value
8077
});
8178
82-
const header = computed(() => {
83-
return props.title || t('fu.table.custom_table_fields')
84-
});
85-
8679
</script>

src/hooks/use-global-config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const globalConfigKey: InjectionKey<Ref<GlobalConfig>> = Symbol('GlobalCo
88
export interface GlobalConfig {
99
size?: string,
1010
locale?: any
11+
i18n?: Function
1112
}
1213

1314
export function useGlobalConfig(key?: keyof any, defaultValue = undefined) {

src/hooks/use-locale/index.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { computed, isRef, ref, unref } from 'vue'
2-
import { get } from 'lodash-unified'
1+
import {computed, isRef, ref, unref} from 'vue'
2+
import {get} from 'lodash-unified'
33
import Chinese from '@/locale/lang/zh-cn'
4-
import { useGlobalConfig } from '@/hooks'
5-
import type { MaybeRef } from '@vueuse/core'
6-
import type { Ref } from 'vue'
7-
import type { Language } from '@/locale'
4+
import {useGlobalConfig} from '@/hooks'
5+
import type {MaybeRef} from '@vueuse/core'
6+
import type {Ref} from 'vue'
7+
import type {Language} from '@/locale'
88

99
export type TranslatorOption = Record<string, string | number>
1010
export type Translator = (path: string, option?: TranslatorOption) => string
@@ -16,18 +16,22 @@ export type LocaleContext = {
1616

1717
export const buildTranslator =
1818
(locale: MaybeRef<Language>): Translator =>
19-
(path, option) =>
20-
translate(path, option, unref(locale))
19+
(path, option) =>
20+
translate(path, option, unref(locale))
2121

2222
export const translate = (
2323
path: string,
2424
option: undefined | TranslatorOption,
2525
locale: Language
26-
): string =>
27-
(get(locale, path, path) as string).replace(
28-
/\{(\w+)\}/g,
29-
(_, key) => `${option?.[key] ?? `{${key}}`}`
30-
)
26+
): string => {
27+
if (!i18nHandler) {
28+
return (get(locale, path, path) as string).replace(
29+
/\{(\w+)\}/g,
30+
(_, key) => `${option?.[key] ?? `{${key}}`}`
31+
)
32+
}
33+
return i18nHandler(path);
34+
}
3135

3236
export const buildLocaleContext = (
3337
locale: MaybeRef<Language>
@@ -45,3 +49,9 @@ export const useLocale = () => {
4549
const locale = useGlobalConfig('locale')
4650
return buildLocaleContext(computed(() => locale.value || Chinese))
4751
}
52+
53+
let i18nHandler: Function;
54+
55+
export const i18n = (fn: Function | undefined) => {
56+
i18nHandler = fn || i18nHandler;
57+
};

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PackageJSON from "../package.json"
22

33
import type {App} from 'vue'
4-
import {GlobalConfig, provideGlobalConfig} from "@/hooks";
4+
import {GlobalConfig, i18n, provideGlobalConfig} from "@/hooks";
55

66
const components = import.meta.globEager('@/components/*/index.ts');
77

@@ -10,6 +10,7 @@ const install = (app: App, config: GlobalConfig): void => {
1010
let component = components[key].default;
1111
app.use(component)
1212
})
13+
i18n(config.i18n)
1314
provideGlobalConfig(config)
1415
}
1516

src/locale/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
export { default as en } from './lang/en'
22
export { default as zhCn } from './lang/zh-cn'
33
export { default as zhTw } from './lang/zh-tw'
4+
export { default as ja } from './lang/ja'
5+
export { default as ms } from './lang/ms'
6+
export { default as ru } from './lang/ru'
7+
export { default as ptBr } from './lang/pt-br'
48

59
export type TranslatePair = {
610
[key: string]: string | string[] | TranslatePair

0 commit comments

Comments
 (0)