@axewo/fin-locale 3.0.2 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/context.cjs +1 -0
- package/dist/context.mjs +30 -0
- package/dist/create-i18n.cjs +1 -1
- package/dist/create-i18n.mjs +48 -45
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +24 -16
- package/dist/locale-string.cjs +1 -0
- package/dist/locale-string.mjs +45 -0
- package/dist/locales/en/platform.cjs +1 -1
- package/dist/locales/en/platform.mjs +4 -0
- package/dist/locales/zh-CN/platform.cjs +1 -1
- package/dist/locales/zh-CN/platform.mjs +4 -0
- package/dist/types/context.d.ts +16 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/locale-string.d.ts +23 -0
- package/dist/types/locales/en/platform.d.ts +4 -0
- package/dist/types/locales/zh-CN/platform.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,3 +41,48 @@ const stopLocaleStorage = connectFinLocaleStorage(
|
|
|
41
41
|
包根导出 `zhCN`、`en`、`createFinI18n`、`installFinI18n`、`useFinLocale`、`normalizeAppLocale`、`normalizeFinLocale`、`translateFinBuiltin`、`useFinText`、`connectFinLocaleStorage`。规范子路径为 `/locales/zh-CN` 和 `/locales/en`,旧 `/lang/zh-CN`、`/lang/en` 保留兼容;源码只维护 `src/locales`。
|
|
42
42
|
|
|
43
43
|
`useFinText` 供可独立使用的公共展示组件读取当前 App 的翻译,未注入时回退中文;业务页面应使用 `useFinLocale`。非 Vue 启动边界使用 `translateFinBuiltin(key, locale)`,不创建共享全局实例。
|
|
44
|
+
|
|
45
|
+
## 在 setup 外读取当前应用的语言
|
|
46
|
+
|
|
47
|
+
组件内继续使用 `useFinLocale()`。请求层、字典工具或旧代码需要在 `setup` 外访问语言时,每个项目创建一个 `createFinLocaleContext()`,并绑定该 App 安装的真实 i18n 实例:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// 项目 src/locales/context.ts:导出本项目自己的访问器。
|
|
51
|
+
import { createFinLocaleContext } from '@axewo/fin-locale'
|
|
52
|
+
export const appLocale = createFinLocaleContext()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
// 启动入口。
|
|
57
|
+
import { installFinI18n } from '@axewo/fin-locale'
|
|
58
|
+
import { appLocale } from './locales/context'
|
|
59
|
+
|
|
60
|
+
const i18n = installFinI18n(app, { messages })!
|
|
61
|
+
const stopLocaleContext = appLocale.bind(i18n)
|
|
62
|
+
// 后续请求按调用时读取:appLocale.locale.value。
|
|
63
|
+
// 挂载失败或卸载时:stopLocaleContext()。
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
访问器提供只读 `locale`、保留 vue-i18n 插值和复数参数的 `t`、词条检查 `te`。绑定前及释放后使用 `zh-CN`,`t` 返回原键,`te` 返回 `false`。重新绑定会复用访问器上的稳定响应式引用;上一轮的释放函数不能清除新绑定,即使两轮使用同一 i18n 实例。访问器只连接 composition 模式实例,不创建词条、另一份语言状态或持久化监听。
|
|
67
|
+
|
|
68
|
+
基座和每个子应用各自创建访问器,服务端渲染则每个请求各自创建。库不导出全局默认 `i18n`。后台 `Content-Language` 要求下划线等协议转换由项目请求层完成,公共访问器保留 UI 的语言标识。已有 `src/lang/index.ts` 可以暂作重导出兼容入口;调用方迁移后删除,不应再维护第二套实现。
|
|
69
|
+
|
|
70
|
+
## 后台多语言字段
|
|
71
|
+
|
|
72
|
+
菜单名称、字典标签等 `{ 'zh-CN': '名称', 'en-US': 'Name' }` 字段使用以下工具,不交给 UI 消息树处理:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import {
|
|
76
|
+
toLocaleKey, normalizeLocaleString, buildLocaleString,
|
|
77
|
+
getExactLocaleText, getLocaleText, useFinLocale,
|
|
78
|
+
} from '@axewo/fin-locale'
|
|
79
|
+
|
|
80
|
+
const { locale } = useFinLocale()
|
|
81
|
+
toLocaleKey('en') // 'en-US',保留后台字段地区键
|
|
82
|
+
const names = normalizeLocaleString({ en_US: 'Name', ja_JP: '名前' }, '名称')
|
|
83
|
+
getLocaleText(names, locale.value) // 展示:精确语言 → 同语言族 → 中文 → 首个翻译
|
|
84
|
+
getExactLocaleText(names, 'zh-CN') // 编辑:只读中文或 zh,不借用其他语言
|
|
85
|
+
buildLocaleString({ ...names, 'ja-JP': '' }) // 提交时去掉清空的翻译
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`LocaleString` 为 `Record<string, string>`。上述函数不创建 i18n 实例、不读取全局语言或存储、不修改传入对象。`getLocaleText` 的第二个参数省略时为中文;需要随语言切换更新时,在 `computed` 或渲染函数中传入当前 `locale.value`。旧单语字符串在 `normalizeLocaleString` 中写入中文;无效非字符串翻译会被忽略。后台语言字典的接口、权限与加载状态仍由项目维护。
|
package/dist/context.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");function l(){const t=n.shallowRef();return{locale:n.computed(()=>{var e;return((e=t.value)==null?void 0:e.composer.locale.value)??"zh-CN"}),t:(...e)=>{var c;const o=(c=t.value)==null?void 0:c.composer;return o?Reflect.apply(o.t,o,e):String(e[0])},te:(e,o)=>{var c;return((c=t.value)==null?void 0:c.composer.te(e,o))??!1},bind(e){if(e.mode!=="composition")throw new TypeError("createFinLocaleContext requires a composition-mode i18n instance");const o={composer:e.global};return t.value=o,()=>{t.value===o&&(t.value=void 0)}}}}exports.createFinLocaleContext=l;
|
package/dist/context.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { shallowRef as n, computed as l } from "vue";
|
|
2
|
+
function p() {
|
|
3
|
+
const t = n();
|
|
4
|
+
return {
|
|
5
|
+
locale: l(() => {
|
|
6
|
+
var e;
|
|
7
|
+
return ((e = t.value) == null ? void 0 : e.composer.locale.value) ?? "zh-CN";
|
|
8
|
+
}),
|
|
9
|
+
t: (...e) => {
|
|
10
|
+
var c;
|
|
11
|
+
const o = (c = t.value) == null ? void 0 : c.composer;
|
|
12
|
+
return o ? Reflect.apply(o.t, o, e) : String(e[0]);
|
|
13
|
+
},
|
|
14
|
+
te: (e, o) => {
|
|
15
|
+
var c;
|
|
16
|
+
return ((c = t.value) == null ? void 0 : c.composer.te(e, o)) ?? !1;
|
|
17
|
+
},
|
|
18
|
+
bind(e) {
|
|
19
|
+
if (e.mode !== "composition")
|
|
20
|
+
throw new TypeError("createFinLocaleContext requires a composition-mode i18n instance");
|
|
21
|
+
const o = { composer: e.global };
|
|
22
|
+
return t.value = o, () => {
|
|
23
|
+
t.value === o && (t.value = void 0);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
p as createFinLocaleContext
|
|
30
|
+
};
|
package/dist/create-i18n.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("vue-i18n"),p=require("vue"),o=require("@axewo/fin-core/locale"),L=require("./locales/zh-CN/index.cjs"),d=require("./locales/zh-CN/formula-additions.cjs"),z=require("./locales/en/index.cjs"),F=require("./locales/en/formula-additions.cjs"),M=require("./locales/zh-CN/platform.cjs"),_=require("./locales/en/platform.cjs");function l(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const i=o.mergeLocaleMessages(o.mergeLocaleMessages(L,d),M),u=o.mergeLocaleMessages(o.mergeLocaleMessages(z,F),_);function c(e,t="zh-CN"){let n=o.normalizeFinLocale(t)==="en"?u:i;for(const r of e.split("."))n=l(n)?n[r]:void 0;return typeof n=="string"?n:e}function b(e){const t={"zh-CN":o.mergeLocaleMessages({},i),en:o.mergeLocaleMessages({},u)};if(!l(e))return t;for(const[n,r]of Object.entries(e)){const s=o.normalizeAppLocale(n,"");!s||!l(r)||(t[s]=t[s]?o.mergeLocaleMessages(t[s],r):o.mergeLocaleMessages({},r))}return t}function f(e){const{messages:t,...n}=e||{};return g.createI18n({fallbackLocale:"zh-CN",legacy:!1,missingWarn:!1,fallbackWarn:!1,...n,locale:o.normalizeAppLocale(n.locale),messages:b(t)})}function m(){const{t:e,locale:t}=g.useI18n({useScope:"global"});return{t:e,locale:t,setLocale:n=>{t.value=o.normalizeAppLocale(n)}}}function I(){var r;const e=(r=p.getCurrentInstance())==null?void 0:r.appContext.app;if(!(e!=null&&e.__VUE_I18N_SYMBOL__))return s=>c(s);const{t,locale:n}=m();return s=>{const a=t(s);return a===s?c(s,n.value):a}}function q(e,t){const n=e,r=n.__VUE_I18N_SYMBOL__;if(r){const a=n._context.provides[r];if(a)return a}const s=f(t);return e.use(s),s}Object.defineProperty(exports,"normalizeAppLocale",{enumerable:!0,get:()=>o.normalizeAppLocale});Object.defineProperty(exports,"normalizeFinLocale",{enumerable:!0,get:()=>o.normalizeFinLocale});exports.createFinI18n=f;exports.en=u;exports.installFinI18n=q;exports.translateFinBuiltin=c;exports.useFinLocale=m;exports.useFinText=I;exports.zhCN=i;
|
package/dist/create-i18n.mjs
CHANGED
|
@@ -1,82 +1,85 @@
|
|
|
1
|
-
import { createI18n as
|
|
2
|
-
import { getCurrentInstance as
|
|
3
|
-
import { mergeLocaleMessages as
|
|
1
|
+
import { createI18n as u, useI18n as p } from "vue-i18n";
|
|
2
|
+
import { getCurrentInstance as g } from "vue";
|
|
3
|
+
import { mergeLocaleMessages as s, normalizeAppLocale as l, normalizeFinLocale as _ } from "@axewo/fin-core/locale";
|
|
4
4
|
import { normalizeAppLocale as U, normalizeFinLocale as V } from "@axewo/fin-core/locale";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
function
|
|
5
|
+
import z from "./locales/zh-CN/index.mjs";
|
|
6
|
+
import L from "./locales/zh-CN/formula-additions.mjs";
|
|
7
|
+
import F from "./locales/en/index.mjs";
|
|
8
|
+
import h from "./locales/en/formula-additions.mjs";
|
|
9
|
+
import C from "./locales/zh-CN/platform.mjs";
|
|
10
|
+
import I from "./locales/en/platform.mjs";
|
|
11
|
+
function a(e) {
|
|
12
12
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
function
|
|
16
|
-
let n =
|
|
17
|
-
for (const
|
|
14
|
+
const f = s(s(z, L), C), m = s(s(F, h), I);
|
|
15
|
+
function c(e, o = "zh-CN") {
|
|
16
|
+
let n = _(o) === "en" ? m : f;
|
|
17
|
+
for (const r of e.split(".")) n = a(n) ? n[r] : void 0;
|
|
18
18
|
return typeof n == "string" ? n : e;
|
|
19
19
|
}
|
|
20
20
|
function N(e) {
|
|
21
21
|
const o = {
|
|
22
|
-
"zh-CN":
|
|
23
|
-
en:
|
|
22
|
+
"zh-CN": s({}, f),
|
|
23
|
+
en: s({}, m)
|
|
24
24
|
};
|
|
25
|
-
if (!
|
|
25
|
+
if (!a(e))
|
|
26
26
|
return o;
|
|
27
|
-
for (const [n,
|
|
28
|
-
const
|
|
29
|
-
!
|
|
27
|
+
for (const [n, r] of Object.entries(e)) {
|
|
28
|
+
const t = l(n, "");
|
|
29
|
+
!t || !a(r) || (o[t] = o[t] ? s(o[t], r) : s({}, r));
|
|
30
30
|
}
|
|
31
31
|
return o;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function d(e) {
|
|
34
34
|
const { messages: o, ...n } = e || {};
|
|
35
|
-
return
|
|
35
|
+
return u({
|
|
36
36
|
fallbackLocale: "zh-CN",
|
|
37
37
|
legacy: !1,
|
|
38
38
|
missingWarn: !1,
|
|
39
39
|
fallbackWarn: !1,
|
|
40
40
|
...n,
|
|
41
|
-
locale:
|
|
41
|
+
locale: l(n.locale),
|
|
42
42
|
messages: N(o)
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
const { t: e, locale: o } =
|
|
45
|
+
function b() {
|
|
46
|
+
const { t: e, locale: o } = p({ useScope: "global" });
|
|
47
47
|
return {
|
|
48
48
|
t: e,
|
|
49
49
|
locale: o,
|
|
50
50
|
setLocale: (n) => {
|
|
51
|
-
o.value =
|
|
51
|
+
o.value = l(n);
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
var
|
|
57
|
-
const e = (
|
|
58
|
-
if (!(e != null && e.__VUE_I18N_SYMBOL__)) return (t) =>
|
|
59
|
-
const { t: o } =
|
|
60
|
-
return (t) =>
|
|
55
|
+
function j() {
|
|
56
|
+
var r;
|
|
57
|
+
const e = (r = g()) == null ? void 0 : r.appContext.app;
|
|
58
|
+
if (!(e != null && e.__VUE_I18N_SYMBOL__)) return (t) => c(t);
|
|
59
|
+
const { t: o, locale: n } = b();
|
|
60
|
+
return (t) => {
|
|
61
|
+
const i = o(t);
|
|
62
|
+
return i === t ? c(t, n.value) : i;
|
|
63
|
+
};
|
|
61
64
|
}
|
|
62
65
|
function E(e, o) {
|
|
63
|
-
const n = e,
|
|
64
|
-
if (
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
return
|
|
66
|
+
const n = e, r = n.__VUE_I18N_SYMBOL__;
|
|
67
|
+
if (r) {
|
|
68
|
+
const i = n._context.provides[r];
|
|
69
|
+
if (i)
|
|
70
|
+
return i;
|
|
68
71
|
}
|
|
69
|
-
const
|
|
70
|
-
return e.use(
|
|
72
|
+
const t = d(o);
|
|
73
|
+
return e.use(t), t;
|
|
71
74
|
}
|
|
72
75
|
export {
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
d as createFinI18n,
|
|
77
|
+
m as en,
|
|
75
78
|
E as installFinI18n,
|
|
76
79
|
U as normalizeAppLocale,
|
|
77
80
|
V as normalizeFinLocale,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
c as translateFinBuiltin,
|
|
82
|
+
b as useFinLocale,
|
|
83
|
+
j as useFinText,
|
|
84
|
+
f as zhCN
|
|
82
85
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./create-i18n.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./create-i18n.cjs"),o=require("./storage.cjs"),i=require("./context.cjs"),t=require("./locale-string.cjs"),a=require("./locales/zh-CN/formula-additions.cjs"),r=require("./locales/en/formula-additions.cjs"),n=require("@axewo/fin-core/locale");exports.createFinI18n=e.createFinI18n;exports.en=e.en;exports.installFinI18n=e.installFinI18n;exports.translateFinBuiltin=e.translateFinBuiltin;exports.useFinLocale=e.useFinLocale;exports.useFinText=e.useFinText;exports.zhCN=e.zhCN;exports.connectFinLocaleStorage=o.connectFinLocaleStorage;exports.createFinLocaleContext=i.createFinLocaleContext;exports.buildLocaleString=t.buildLocaleString;exports.getExactLocaleText=t.getExactLocaleText;exports.getLocaleText=t.getLocaleText;exports.normalizeLocaleString=t.normalizeLocaleString;exports.toLocaleKey=t.toLocaleKey;exports.zhCNFormulaAdditions=a;exports.enFormulaAdditions=r;Object.defineProperty(exports,"normalizeAppLocale",{enumerable:!0,get:()=>n.normalizeAppLocale});Object.defineProperty(exports,"normalizeFinLocale",{enumerable:!0,get:()=>n.normalizeFinLocale});
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
import { createFinI18n as
|
|
2
|
-
import { connectFinLocaleStorage as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { createFinI18n as t, en as a, installFinI18n as n, translateFinBuiltin as r, useFinLocale as l, useFinText as i, zhCN as c } from "./create-i18n.mjs";
|
|
2
|
+
import { connectFinLocaleStorage as x } from "./storage.mjs";
|
|
3
|
+
import { createFinLocaleContext as L } from "./context.mjs";
|
|
4
|
+
import { buildLocaleString as p, getExactLocaleText as s, getLocaleText as u, normalizeLocaleString as d, toLocaleKey as g } from "./locale-string.mjs";
|
|
5
|
+
import { default as A } from "./locales/zh-CN/formula-additions.mjs";
|
|
6
|
+
import { default as S } from "./locales/en/formula-additions.mjs";
|
|
7
|
+
import { normalizeAppLocale as h, normalizeFinLocale as I } from "@axewo/fin-core/locale";
|
|
6
8
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
p as buildLocaleString,
|
|
10
|
+
x as connectFinLocaleStorage,
|
|
11
|
+
t as createFinI18n,
|
|
12
|
+
L as createFinLocaleContext,
|
|
9
13
|
a as en,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
S as enFormulaAdditions,
|
|
15
|
+
s as getExactLocaleText,
|
|
16
|
+
u as getLocaleText,
|
|
17
|
+
n as installFinI18n,
|
|
18
|
+
h as normalizeAppLocale,
|
|
19
|
+
I as normalizeFinLocale,
|
|
20
|
+
d as normalizeLocaleString,
|
|
21
|
+
g as toLocaleKey,
|
|
22
|
+
r as translateFinBuiltin,
|
|
23
|
+
l as useFinLocale,
|
|
24
|
+
i as useFinText,
|
|
25
|
+
c as zhCN,
|
|
26
|
+
A as zhCNFormulaAdditions
|
|
19
27
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function L(t){const e=t.trim().replaceAll("_","-");if(e.toLowerCase()==="zh")return"zh-CN";if(e.toLowerCase()==="en")return"en-US";try{return Intl.getCanonicalLocales(e)[0]||e}catch{return e}}function f(t){return!t||typeof t!="object"||Array.isArray(t)?[]:Object.entries(t).filter(e=>typeof e[1]=="string")}function c(t){return t.trim().replaceAll("_","-").toLowerCase()}function y(t,e){var a,l;const r=c(e),n=r.split("-")[0],o=f(t);return((a=o.find(([s])=>c(s)===r))==null?void 0:a[1])||((l=o.find(([s])=>c(s)===n))==null?void 0:l[1])||""}function p(t,e=""){const r=new Map(f(t).map(([o,a])=>[L(o),a])),n=typeof t=="string"?t:e;return!r.get("zh-CN")&&n&&r.set("zh-CN",n),Object.fromEntries(r)}function m(t){return Object.fromEntries(Object.entries(p(t)).filter(([,e])=>e.trim()))}function b(t,e="zh-CN",r=""){var l,s,g,u;if(typeof t=="string")return t;const n=f(t).filter(([,i])=>i),o=c(e||"zh-CN"),a=o.split("-")[0];return((l=n.find(([i])=>c(i)===o))==null?void 0:l[1])||((s=n.find(([i])=>c(i).split("-")[0]===a))==null?void 0:s[1])||((g=n.find(([i])=>c(i)==="zh-cn"))==null?void 0:g[1])||((u=n[0])==null?void 0:u[1])||r}exports.buildLocaleString=m;exports.getExactLocaleText=y;exports.getLocaleText=b;exports.normalizeLocaleString=p;exports.toLocaleKey=L;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function p(t) {
|
|
2
|
+
const n = t.trim().replaceAll("_", "-");
|
|
3
|
+
if (n.toLowerCase() === "zh") return "zh-CN";
|
|
4
|
+
if (n.toLowerCase() === "en") return "en-US";
|
|
5
|
+
try {
|
|
6
|
+
return Intl.getCanonicalLocales(n)[0] || n;
|
|
7
|
+
} catch {
|
|
8
|
+
return n;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function l(t) {
|
|
12
|
+
return !t || typeof t != "object" || Array.isArray(t) ? [] : Object.entries(t).filter(
|
|
13
|
+
(n) => typeof n[1] == "string"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function c(t) {
|
|
17
|
+
return t.trim().replaceAll("_", "-").toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
function m(t, n) {
|
|
20
|
+
var s, f;
|
|
21
|
+
const r = c(n), e = r.split("-")[0], i = l(t);
|
|
22
|
+
return ((s = i.find(([a]) => c(a) === r)) == null ? void 0 : s[1]) || ((f = i.find(([a]) => c(a) === e)) == null ? void 0 : f[1]) || "";
|
|
23
|
+
}
|
|
24
|
+
function h(t, n = "") {
|
|
25
|
+
const r = new Map(l(t).map(([i, s]) => [p(i), s])), e = typeof t == "string" ? t : n;
|
|
26
|
+
return !r.get("zh-CN") && e && r.set("zh-CN", e), Object.fromEntries(r);
|
|
27
|
+
}
|
|
28
|
+
function y(t) {
|
|
29
|
+
return Object.fromEntries(
|
|
30
|
+
Object.entries(h(t)).filter(([, n]) => n.trim())
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function z(t, n = "zh-CN", r = "") {
|
|
34
|
+
var f, a, u, g;
|
|
35
|
+
if (typeof t == "string") return t;
|
|
36
|
+
const e = l(t).filter(([, o]) => o), i = c(n || "zh-CN"), s = i.split("-")[0];
|
|
37
|
+
return ((f = e.find(([o]) => c(o) === i)) == null ? void 0 : f[1]) || ((a = e.find(([o]) => c(o).split("-")[0] === s)) == null ? void 0 : a[1]) || ((u = e.find(([o]) => c(o) === "zh-cn")) == null ? void 0 : u[1]) || ((g = e[0]) == null ? void 0 : g[1]) || r;
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
y as buildLocaleString,
|
|
41
|
+
m as getExactLocaleText,
|
|
42
|
+
z as getLocaleText,
|
|
43
|
+
h as normalizeLocaleString,
|
|
44
|
+
p as toLocaleKey
|
|
45
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e={fin:{confirmation:{logoutTitle:"Sign out of the system?",logoutContent:"Unsaved changes will be lost after signing out.",logoutConfirm:"Sign out",unsavedTitle:"Discard changes?",unsavedContent:"The following changes have not been saved and will be lost when you leave.",continueEditing:"Continue editing",discardConfirm:"Discard and leave",currentPage:"Current page",unsavedForms:"Pages and forms with unsaved changes"},shell:{closePopover:"Close popover",expand:"Expand sidebar",collapse:"Collapse sidebar",search:"Search menus",searchPlaceholder:"Search menus and apps…",searchTitle:"Menu search",noResults:"No matching menus",notifications:"Notifications",noMessages:"Message service is not connected",messageHint:"Notifications will appear here after the service is connected.",profile:"My profile",exiting:"Confirming sign out…",closeTabMenu:"Close tab menu",leftTabs:"Scroll tabs left",rightTabs:"Scroll tabs right",openedPages:"Open pages",moreTabs:"More tab actions",tabMenu:"Tab actions",refresh:"Refresh page",close:"Close current",closeOthers:"Close others",closeLeft:"Close left",closeRight:"Close right",closeAll:"Close all business pages",mainNav:"Main navigation",ready:"Workspace is ready",closeTab:"Close",pageLoading:"Loading page…",pageFailed:"Page failed to load",reload:"Reload"},errors:{unauthenticated:"Your session has expired. Please sign in again.",forbidden:"403: You do not have permission for this action.",timeout:"The operation timed out. Please try again.",network:"Connection failed. Please check your network.",unknown:"The operation failed. Please try again or contact support.",cancelled:"Operation cancelled"},auth:{independent:"Standalone mode",login:"Sign in",logout:"Sign out",username:"Username",password:"Password",required:"Sign in to access business features.",devSettings:"Development settings",token:"Test token",verify:"Verify and apply",clear:"Clear credentials",close:"Close",configured:"Credentials configured",unconfigured:"No credentials configured",memoryHint:"Credentials are stored in memory and cleared when the page reloads.",developmentStorageHint:"Development credentials are stored locally and validated on reload. Clear credentials or sign out to remove them.",verifyHint:"User and permissions are updated only after the session endpoint validates the token.",saved:"Credentials verified",cleared:"Credentials cleared"},micro:{connected:"Connected to host",disconnected:"Host unavailable",workspace:"Workspace",language:"Language",standalone:"Standalone mode",loading:"Starting application, please wait…",retry:"Retry startup",startupFailed:"Application failed to start",startupCancelled:"Startup was cancelled. You can retry."}}};module.exports=e;
|
|
1
|
+
"use strict";const e={fin:{confirmation:{logoutTitle:"Sign out of the system?",logoutContent:"Unsaved changes will be lost after signing out.",logoutConfirm:"Sign out",unsavedTitle:"Discard changes?",unsavedContent:"The following changes have not been saved and will be lost when you leave.",continueEditing:"Continue editing",discardConfirm:"Discard and leave",currentPage:"Current page",unsavedForms:"Pages and forms with unsaved changes"},shell:{closePopover:"Close popover",expand:"Expand sidebar",collapse:"Collapse sidebar",search:"Search menus",searchPlaceholder:"Search menus and apps…",searchTitle:"Menu search",noResults:"No matching menus",notifications:"Notifications",noMessages:"Message service is not connected",messageHint:"Notifications will appear here after the service is connected.",profile:"My profile",exiting:"Confirming sign out…",closeTabMenu:"Close tab menu",leftTabs:"Scroll tabs left",rightTabs:"Scroll tabs right",openedPages:"Open pages",moreTabs:"More tab actions",tabMenu:"Tab actions",refresh:"Refresh page",close:"Close current",closeOthers:"Close others",closeLeft:"Close left",closeRight:"Close right",closeAll:"Close all business pages",mainNav:"Main navigation",ready:"Workspace is ready",closeTab:"Close",pageLoading:"Loading page…",pageFailed:"Page failed to load",reload:"Reload"},errors:{unauthenticated:"Your session has expired. Please sign in again.",forbidden:"403: You do not have permission for this action.",timeout:"The operation timed out. Please try again.",network:"Connection failed. Please check your network.",unknown:"The operation failed. Please try again or contact support.",cancelled:"Operation cancelled"},auth:{independent:"Standalone mode",login:"Sign in",logout:"Sign out",username:"Username",password:"Password",required:"Sign in to access business features.",devSettings:"Development settings",token:"Test token",verify:"Verify and apply",clear:"Clear credentials",close:"Close",configured:"Credentials configured",unconfigured:"No credentials configured",memoryHint:"Credentials are stored in memory and cleared when the page reloads.",developmentStorageHint:"Development credentials are stored locally and validated on reload. Clear credentials or sign out to remove them.",verifyHint:"User and permissions are updated only after the session endpoint validates the token.",saved:"Credentials verified",cleared:"Credentials cleared"},micro:{connected:"Connected to host",disconnected:"Host unavailable",workspace:"Workspace",language:"Language",standalone:"Standalone mode",loading:"Starting application, please wait…",retry:"Retry startup",appLoading:"Loading application…",loadFailed:"Application failed to load",loadFailedDescription:"Please reload or contact your administrator",reload:"Reload",startupFailed:"Application failed to start",startupCancelled:"Startup was cancelled. You can retry."}}};module.exports=e;
|
|
@@ -79,6 +79,10 @@ const e = {
|
|
|
79
79
|
standalone: "Standalone mode",
|
|
80
80
|
loading: "Starting application, please wait…",
|
|
81
81
|
retry: "Retry startup",
|
|
82
|
+
appLoading: "Loading application…",
|
|
83
|
+
loadFailed: "Application failed to load",
|
|
84
|
+
loadFailedDescription: "Please reload or contact your administrator",
|
|
85
|
+
reload: "Reload",
|
|
82
86
|
startupFailed: "Application failed to start",
|
|
83
87
|
startupCancelled: "Startup was cancelled. You can retry."
|
|
84
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e={fin:{confirmation:{logoutTitle:"是否退出管理系统?",logoutContent:"退出后,未保存的内容将丢失。",logoutConfirm:"确认退出",unsavedTitle:"是否放弃修改?",unsavedContent:"以下内容尚未保存,离开后本次修改将丢失。",continueEditing:"继续编辑",discardConfirm:"放弃修改并离开",currentPage:"当前页面",unsavedForms:"未保存的页面和表单"},shell:{closePopover:"关闭弹出菜单",expand:"展开侧栏",collapse:"折叠侧栏",search:"搜索菜单",searchPlaceholder:"搜索菜单、应用…",searchTitle:"菜单搜索",noResults:"未找到匹配的菜单",notifications:"消息通知",noMessages:"尚未接入消息服务",messageHint:"接入后将在这里显示真实的通知消息。",profile:"个人中心",exiting:"正在确认退出…",closeTabMenu:"关闭页签菜单",leftTabs:"向左查看页签",rightTabs:"向右查看页签",openedPages:"已打开页面",moreTabs:"更多页签操作",tabMenu:"页签操作菜单",refresh:"刷新页面",close:"关闭当前",closeOthers:"关闭其他",closeLeft:"关闭左侧",closeRight:"关闭右侧",closeAll:"关闭全部业务页",mainNav:"主导航",ready:"工作空间已就绪",closeTab:"关闭",pageLoading:"页面加载中…",pageFailed:"页面加载失败",reload:"重新加载"},errors:{unauthenticated:"登录已失效,请重新登录",forbidden:"403:无权执行此操作,请联系管理员",timeout:"操作超时,请稍后重试",network:"连接失败,请检查网络后重试",unknown:"操作失败,请稍后重试或联系管理员",cancelled:"操作已取消"},auth:{independent:"独立运行",login:"登录",logout:"退出登录",username:"账号",password:"密码",required:"请登录后访问业务功能",devSettings:"开发设置",token:"测试 Token",verify:"验证并应用",clear:"清除凭据",close:"关闭",configured:"已配置凭据",unconfigured:"未配置凭据",memoryHint:"凭据仅保存在内存,刷新页面后需重新设置。",developmentStorageHint:"开发凭据保存在本地,刷新后自动验证恢复;清除凭据或退出登录时删除。",verifyHint:"验证会话接口成功后才会更新用户与权限。",saved:"凭据已验证",cleared:"凭据已清除"},micro:{connected:"宿主已连接",disconnected:"未连接宿主",workspace:"工作空间",language:"语言",standalone:"独立运行",loading:"正在启动应用,请稍候…",retry:"重试启动",startupFailed:"应用启动失败",startupCancelled:"应用启动已取消,可重试启动"}}};module.exports=e;
|
|
1
|
+
"use strict";const e={fin:{confirmation:{logoutTitle:"是否退出管理系统?",logoutContent:"退出后,未保存的内容将丢失。",logoutConfirm:"确认退出",unsavedTitle:"是否放弃修改?",unsavedContent:"以下内容尚未保存,离开后本次修改将丢失。",continueEditing:"继续编辑",discardConfirm:"放弃修改并离开",currentPage:"当前页面",unsavedForms:"未保存的页面和表单"},shell:{closePopover:"关闭弹出菜单",expand:"展开侧栏",collapse:"折叠侧栏",search:"搜索菜单",searchPlaceholder:"搜索菜单、应用…",searchTitle:"菜单搜索",noResults:"未找到匹配的菜单",notifications:"消息通知",noMessages:"尚未接入消息服务",messageHint:"接入后将在这里显示真实的通知消息。",profile:"个人中心",exiting:"正在确认退出…",closeTabMenu:"关闭页签菜单",leftTabs:"向左查看页签",rightTabs:"向右查看页签",openedPages:"已打开页面",moreTabs:"更多页签操作",tabMenu:"页签操作菜单",refresh:"刷新页面",close:"关闭当前",closeOthers:"关闭其他",closeLeft:"关闭左侧",closeRight:"关闭右侧",closeAll:"关闭全部业务页",mainNav:"主导航",ready:"工作空间已就绪",closeTab:"关闭",pageLoading:"页面加载中…",pageFailed:"页面加载失败",reload:"重新加载"},errors:{unauthenticated:"登录已失效,请重新登录",forbidden:"403:无权执行此操作,请联系管理员",timeout:"操作超时,请稍后重试",network:"连接失败,请检查网络后重试",unknown:"操作失败,请稍后重试或联系管理员",cancelled:"操作已取消"},auth:{independent:"独立运行",login:"登录",logout:"退出登录",username:"账号",password:"密码",required:"请登录后访问业务功能",devSettings:"开发设置",token:"测试 Token",verify:"验证并应用",clear:"清除凭据",close:"关闭",configured:"已配置凭据",unconfigured:"未配置凭据",memoryHint:"凭据仅保存在内存,刷新页面后需重新设置。",developmentStorageHint:"开发凭据保存在本地,刷新后自动验证恢复;清除凭据或退出登录时删除。",verifyHint:"验证会话接口成功后才会更新用户与权限。",saved:"凭据已验证",cleared:"凭据已清除"},micro:{connected:"宿主已连接",disconnected:"未连接宿主",workspace:"工作空间",language:"语言",standalone:"独立运行",loading:"正在启动应用,请稍候…",retry:"重试启动",appLoading:"子应用加载中…",loadFailed:"子应用加载失败",loadFailedDescription:"请重新加载或联系管理员",reload:"重新加载",startupFailed:"应用启动失败",startupCancelled:"应用启动已取消,可重试启动"}}};module.exports=e;
|
|
@@ -79,6 +79,10 @@ const e = {
|
|
|
79
79
|
standalone: "独立运行",
|
|
80
80
|
loading: "正在启动应用,请稍候…",
|
|
81
81
|
retry: "重试启动",
|
|
82
|
+
appLoading: "子应用加载中…",
|
|
83
|
+
loadFailed: "子应用加载失败",
|
|
84
|
+
loadFailedDescription: "请重新加载或联系管理员",
|
|
85
|
+
reload: "重新加载",
|
|
82
86
|
startupFailed: "应用启动失败",
|
|
83
87
|
startupCancelled: "应用启动已取消,可重试启动"
|
|
84
88
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { Composer, I18n } from 'vue-i18n';
|
|
3
|
+
/** 供请求层等 setup 外代码访问当前应用的语言实例,不创建第二份 i18n。 */
|
|
4
|
+
export interface FinLocaleContext {
|
|
5
|
+
readonly locale: ComputedRef<string>;
|
|
6
|
+
readonly t: Composer['t'];
|
|
7
|
+
readonly te: Composer['te'];
|
|
8
|
+
/** 挂载后绑定;返回本次绑定的幂等释放函数,旧释放不会清除后续绑定。 */
|
|
9
|
+
bind(i18n: I18n): () => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 每个应用独立创建,再在启动时绑定 installFinI18n 返回的实例。
|
|
13
|
+
* 不使用包级全局实例,不读写存储,不负责后台语言键格式转换。
|
|
14
|
+
* 未绑定或释放后 locale 为 zh-CN,t 返回原键,te 返回 false。
|
|
15
|
+
*/
|
|
16
|
+
export declare function createFinLocaleContext(): FinLocaleContext;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { createFinI18n, en, installFinI18n, useFinLocale, useFinText, zhCN, normalizeAppLocale, normalizeFinLocale, translateFinBuiltin, type FinLocale } from './create-i18n';
|
|
5
5
|
export { connectFinLocaleStorage } from './storage';
|
|
6
|
+
export { createFinLocaleContext, type FinLocaleContext } from './context';
|
|
7
|
+
export { toLocaleKey, getExactLocaleText, normalizeLocaleString, buildLocaleString, getLocaleText, type LocaleString } from './locale-string';
|
|
6
8
|
export { default as zhCNFormulaAdditions } from './locales/zh-CN/formula-additions';
|
|
7
9
|
export { default as enFormulaAdditions } from './locales/en/formula-additions';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** 后台业务字段的多语言映射,与 UI 消息树分开处理。 */
|
|
2
|
+
export type LocaleString = Record<string, string>;
|
|
3
|
+
/**
|
|
4
|
+
* 规范后台字段语言键,保留地区和扩展语种;en/zh 使用后台默认键。
|
|
5
|
+
* 与 normalizeAppLocale 不同,en-US 不会折叠成 UI 内置标识 en。
|
|
6
|
+
* 无法识别的历史键保留原值,由业务校验是否允许提交。
|
|
7
|
+
*/
|
|
8
|
+
export declare function toLocaleKey(locale: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* 编辑时读取指定语言,仅兼容连接符、大小写和无地区语言键。
|
|
11
|
+
* 不回退到其他地区或其他语言,避免将显示用回退文案写入表单。
|
|
12
|
+
*/
|
|
13
|
+
export declare function getExactLocaleText(value: unknown, locale: string): string;
|
|
14
|
+
/** 保留所有字符串翻译,规范历史键;旧单语字段补入中文,不修改原对象。 */
|
|
15
|
+
export declare function normalizeLocaleString(value: unknown, legacyChinese?: string): LocaleString;
|
|
16
|
+
/** 提交时去掉空翻译;保留其余文本原值,不自动改写输入内容。 */
|
|
17
|
+
export declare function buildLocaleString(value: unknown): LocaleString;
|
|
18
|
+
/**
|
|
19
|
+
* 展示业务字段:精确语言 → 同语言族 → 中文 → 首个非空翻译 → fallback。
|
|
20
|
+
* 字符串原样返回;不读取全局 i18n、浏览器或持久化状态。
|
|
21
|
+
* 当前 UI 语言由调用方显式传入,省略时使用中文。
|
|
22
|
+
*/
|
|
23
|
+
export declare function getLocaleText(value: unknown, locale?: string, fallback?: string): string;
|