@rdyl/react-i18n-connect 0.0.2 → 0.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/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 0.0.2 (2025-06-05)
1
+ ## 0.0.4 (2025-06-06)
2
2
 
3
3
 
4
4
 
package/dist/index.js CHANGED
@@ -38,18 +38,26 @@ var react_1 = __importStar(require("react"));
38
38
  var utils_1 = require("./utils");
39
39
  var I18nCtx = (0, react_1.createContext)({});
40
40
  var I18nConnect = function (_a) {
41
- var children = _a.children, _b = _a.initialLang, initialLang = _b === void 0 ? "" : _b, _c = _a.locales, locales = _c === void 0 ? {} : _c, onAfterChange = _a.onAfterChange, onBeforeChange = _a.onBeforeChange, onLoad = _a.onLoad;
42
- var _d = (0, react_1.useState)(initialLang), lang = _d[0], _setLang = _d[1];
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
+ 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 title = (0, react_1.useMemo)(function () { return (locales[lang] ? locales[lang].title : ""); }, [lang]);
45
- var dataSource = (0, react_1.useMemo)(function () {
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
+ var records = (0, react_1.useMemo)(function () {
46
53
  // 异步加载
47
54
  if (onLoad) {
48
55
  return loaded;
49
56
  }
50
- return locales[lang] ? locales[lang].messages || {} : {};
57
+ var current = __locales__[lang] || {};
58
+ return current;
51
59
  }, [lang, loaded, onLoad]);
52
- var t = (0, react_1.useCallback)((0, utils_1.ParserI18nFn)(dataSource), [dataSource]);
60
+ var t = (0, react_1.useCallback)((0, utils_1.ParserI18nFn)(records), [records]);
53
61
  var setLang = (0, react_1.useCallback)(function (e) {
54
62
  var cb = function () {
55
63
  _setLang(e);
@@ -74,9 +82,9 @@ var I18nConnect = function (_a) {
74
82
  window.$t = t;
75
83
  }, [t]);
76
84
  return (react_1.default.createElement(I18nCtx.Provider, { value: {
77
- locales: locales,
78
- dataSource: dataSource,
79
- title: title,
85
+ __locales__: __locales__,
86
+ records: records,
87
+ options: options,
80
88
  lang: lang,
81
89
  t: t,
82
90
  setLang: setLang,
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var fs_1 = __importDefault(require("fs"));
7
+ function loadFiles() {
8
+ console.log(fs_1.default);
9
+ }
10
+ exports.default = loadFiles;
package/package.json CHANGED
@@ -1,9 +1,7 @@
1
1
  {
2
2
  "name": "@rdyl/react-i18n-connect",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
- "main": "dist/index.js",
6
- "types": "types/index.d.ts",
7
5
  "publishConfig": {
8
6
  "access": "public"
9
7
  },
@@ -13,6 +11,16 @@
13
11
  "CHANGELOG.md",
14
12
  "README.md"
15
13
  ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./types/index.d.ts"
18
+ },
19
+ "./resolve": {
20
+ "import": "./dist/resolve.js",
21
+ "types": "./types/resolve.d.ts"
22
+ }
23
+ },
16
24
  "scripts": {
17
25
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
18
26
  "build": "tsc && copyfiles -u 1 src/**/*.d.ts src/*.d.ts types && npm run changelog && git add CHANGELOG.md"
package/types/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { FC, PropsWithChildren } from "react";
2
2
  declare const I18nConnect: FC<PropsWithChildren<I18nConnectProps>>;
3
3
  export interface I18nConnectValue {
4
- title: string;
4
+ __locales__: Record<string, Record<string, TRValue>>;
5
5
  lang: string;
6
- dataSource: Record<string, TRValue>;
7
- locales: Record<string, I18nLangEntry>;
6
+ options: I18nLangOption[];
7
+ records: Record<string, TRValue>;
8
8
  setLang(name: string): void;
9
9
  t: TR;
10
10
  }
@@ -0,0 +1,2 @@
1
+ declare function loadFiles(): void;
2
+ export default loadFiles;
package/types/type.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /** @i18n */
2
2
  interface I18nConfig {
3
- locales: Record<string, I18nLangEntry>;
4
- initialLang: string;
3
+ locales: Record<Record<string, TRValue>>;
4
+ initial: string;
5
5
  }
6
6
 
7
- type TRValue = string | number | boolean;
8
-
9
- interface I18nLangEntry {
10
- title: string;
11
- messages?: Record<string, TRValue>;
7
+ interface I18nLangOption {
8
+ name: string;
9
+ label: string;
12
10
  }
13
11
 
12
+ type TRValue = string | number | boolean;
13
+
14
14
  type TR = (k: string, o?: Record<string, unknown>) => string;
15
15
 
16
16
  declare var $t: TR;