@rdyl/react-i18n-connect 0.0.8 → 0.0.9

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/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 0.0.8 (2025-06-09)
1
+ ## 0.0.9 (2025-08-08)
2
2
 
3
3
 
4
4
 
package/dist/index.js CHANGED
@@ -41,14 +41,6 @@ var I18nConnect = function (_a) {
41
41
  var children = _a.children, _b = _a.initial, initial = _b === void 0 ? "" : _b, _c = _a.locales, __locales__ = _c === void 0 ? {} : _c, onAfterChange = _a.onAfterChange, onBeforeChange = _a.onBeforeChange, onLoad = _a.onLoad;
42
42
  var _d = (0, react_1.useState)(initial), lang = _d[0], _setLang = _d[1];
43
43
  var _e = (0, react_1.useState)({}), loaded = _e[0], setLoaded = _e[1];
44
- var options = (0, react_1.useMemo)(function () {
45
- return Object.keys(__locales__).map(function (name) {
46
- return {
47
- name: name,
48
- label: __locales__[name]["$"] || name,
49
- };
50
- });
51
- }, [__locales__]);
52
44
  var records = (0, react_1.useMemo)(function () {
53
45
  // 异步加载
54
46
  if (onLoad) {
@@ -64,9 +56,11 @@ var I18nConnect = function (_a) {
64
56
  onAfterChange && onAfterChange(e);
65
57
  };
66
58
  if (onBeforeChange) {
67
- if (!!onBeforeChange(e)) {
68
- cb();
69
- }
59
+ Promise.resolve(onBeforeChange(e)).then(function (res) {
60
+ if (res) {
61
+ cb();
62
+ }
63
+ });
70
64
  }
71
65
  else {
72
66
  cb();
@@ -84,7 +78,6 @@ var I18nConnect = function (_a) {
84
78
  return (react_1.default.createElement(I18nCtx.Provider, { value: {
85
79
  __locales__: __locales__,
86
80
  records: records,
87
- options: options,
88
81
  lang: lang,
89
82
  t: t,
90
83
  setLang: setLang,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdyl/react-i18n-connect",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -3,7 +3,6 @@ declare const I18nConnect: FC<PropsWithChildren<I18nConnectProps>>;
3
3
  export interface I18nConnectValue {
4
4
  __locales__: Record<string, Record<string, TRValue>>;
5
5
  lang: string;
6
- options: I18nLangOption[];
7
6
  records: Record<string, TRValue>;
8
7
  setLang(name: string): void;
9
8
  t: TR;
@@ -11,7 +10,7 @@ export interface I18nConnectValue {
11
10
  type I18nConnectProps = Partial<I18nConfig> & {
12
11
  onLoad?(t: string): Promise<Record<string, TRValue>>;
13
12
  onAfterChange?(t: string): void;
14
- onBeforeChange?(t: string): unknown;
13
+ onBeforeChange?(t: string): boolean | Promise<boolean>;
15
14
  };
16
15
  export declare const useI18n: () => I18nConnectValue;
17
16
  export default I18nConnect;
package/types/type.d.ts CHANGED
@@ -4,11 +4,6 @@ interface I18nConfig {
4
4
  initial: string;
5
5
  }
6
6
 
7
- interface I18nLangOption {
8
- name: string;
9
- label: string;
10
- }
11
-
12
7
  type TRValue = string | number | boolean;
13
8
 
14
9
  type TR = (k: string, o?: Record<string, unknown>) => string;