1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| import { getI18n } from '/@/setup/i18n';
| import projectSetting from '/@/settings/projectSetting';
|
| export function useI18n(namespace?: string) {
| function getKey(key: string) {
| if (!namespace) {
| return key;
| }
| if (key.startsWith(namespace)) {
| return key;
| }
| return `${namespace}.${key}`;
| }
| const normalFn = {
| t: (key: string) => {
| return getKey(key);
| },
| };
|
| if (!projectSetting.locale.show || !getI18n()) {
| return normalFn;
| }
|
| const { t, ...methods } = getI18n().global;
|
| return {
| ...methods,
| t: (key: string, ...arg: Parameters<typeof t>) => {
| return t(getKey(key), ...arg);
| },
| };
| }
|
|