zmdms-utils 0.0.98 → 0.0.99

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.
@@ -1,5 +1,6 @@
1
- import instance from '../../node_modules/i18next/dist/esm/i18next.js';
2
- import { initReactI18next } from '../../node_modules/react-i18next/dist/es/initReactI18next.js';
1
+ import i18n from 'i18next';
2
+ export { default as i18n } from 'i18next';
3
+ import { initReactI18next } from 'react-i18next';
3
4
 
4
5
  /**
5
6
  * 初始化逻辑
@@ -10,7 +11,7 @@ import { initReactI18next } from '../../node_modules/react-i18next/dist/es/initR
10
11
  * @returns
11
12
  */
12
13
  function initLocale(options, callback) {
13
- return instance.use(initReactI18next).init(options, callback);
14
+ return i18n.use(initReactI18next).init(options, callback);
14
15
  }
15
16
 
16
- export { instance as i18n, initLocale };
17
+ export { initLocale };
@@ -1,4 +1,5 @@
1
- import instance from '../../node_modules/i18next/dist/esm/i18next.js';
1
+ import i18n from 'i18next';
2
+ import 'react-i18next';
2
3
  import { getTFuncArgs } from './t-options.js';
3
4
 
4
5
  /**
@@ -14,14 +15,14 @@ var tryT = function (key, defaultValueOrOptions) {
14
15
  console.error("tryT: \u8BF7\u4E0D\u8981\u4F20\u5165\u7A7A key \u503C\u8FDB\u884C i18n.t \u51FD\u6570\u6267\u884C\uFF0C\u8FD9\u5C06\u4F1A\u5BFC\u81F4\u76F4\u63A5\u8FD4\u56DE\u7A7A\u5B57\u7B26\u4E32\uFF01");
15
16
  return defaultValue || key;
16
17
  }
17
- if (!instance.exists(key)) {
18
+ if (!i18n.exists(key)) {
18
19
  // 情况2:键名不存在,返回默认值或键名
19
20
  console.error("tryT: i18n-key '".concat(key, "' \u4E0D\u5B58\u5728\uFF0C\u8BF7\u68C0\u67E5\u5BF9\u5E94\u7684 @/locales/resources/locales/xx.json \u4E2D\u662F\u5426\u5B58\u5728\u5BF9\u5E94\u503C"));
20
21
  return defaultValue || key;
21
22
  }
22
23
  try {
23
24
  // 情况3:尝试执行 i18n.t 函数
24
- return instance.t(key, options);
25
+ return i18n.t(key, options);
25
26
  }
26
27
  catch (err) {
27
28
  // 情况4:执行 i18n.t 函数异常,返回默认值或键名
@@ -42,7 +43,7 @@ var tryT = function (key, defaultValueOrOptions) {
42
43
  * const txt = t('someLocaleKey', '兜底默认值');
43
44
  */
44
45
  function safeT(key, defaultValueOrOptions) {
45
- if (instance.isInitialized) {
46
+ if (i18n.isInitialized) {
46
47
  return tryT(key, defaultValueOrOptions);
47
48
  }
48
49
  // 异常情况:没有初始化完成时,返回默认值
@@ -1,5 +1,6 @@
1
+ import { useTranslation } from 'react-i18next';
2
+ export { Trans } from 'react-i18next';
1
3
  import { getTFuncArgs } from './t-options.js';
2
- import { useTranslation } from '../../node_modules/react-i18next/dist/es/useTranslation.js';
3
4
 
4
5
  /**
5
6
  * 这里只是简单代理一下useTranslation,方便后续扩展或添加其他逻辑
package/dist/index.js CHANGED
@@ -23,5 +23,5 @@ export { initLocale } from './es/src/locales/i18n.js';
23
23
  export { useTranslation } from './es/src/locales/use-translation.js';
24
24
  export { safeT } from './es/src/locales/t-in-non-react.js';
25
25
  export { Base64 } from './es/node_modules/js-base64/base64.js';
26
- export { default as i18n } from './es/node_modules/i18next/dist/esm/i18next.js';
27
- export { Trans } from './es/node_modules/react-i18next/dist/es/Trans.js';
26
+ export { default as i18n } from 'i18next';
27
+ export { Trans } from 'react-i18next';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.98",
3
+ "version": "0.0.99",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -19,6 +19,8 @@
19
19
  "html2canvas": "^1.4.1",
20
20
  "jspdf": "^2.5.1",
21
21
  "print-js": "^1.6.0",
22
+ "i18next": ">=22.4.12",
23
+ "react-i18next": ">=12.2.0",
22
24
  "qiankun": "^2.10.8"
23
25
  },
24
26
  "dependencies": {
@@ -1,5 +0,0 @@
1
- import voidElements from '../../void-elements/index.js';
2
-
3
- var t=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(voidElements[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i=/^\s*$/,s=Object.create(null);function a(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c={parse:function(e,t){t||(t={}),t.components||(t.components=s);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a("",t)},"")}};
4
-
5
- export { c as default };