@opentiny/vue-search-box 0.1.2 → 0.1.3

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.
@@ -2,27 +2,44 @@ import "./index.vue.es.js";
2
2
  import "./components/first-level-panel.vue.es.js";
3
3
  import "./components/second-level-panel.vue.es.js";
4
4
  import zhCN from "./utils/zh_CN.es.js";
5
- import { default as default2 } from "./utils/en_US.es.js";
5
+ import enUS from "./utils/en_US.es.js";
6
6
  /* empty css */
7
7
  import "./index.type.es.js";
8
8
  import _sfc_main from "./index.vue.es2.js";
9
- import { default as default3 } from "./components/first-level-panel.vue.es2.js";
10
- import { default as default4 } from "./components/second-level-panel.vue.es2.js";
9
+ import { default as default2 } from "./components/first-level-panel.vue.es2.js";
10
+ import { default as default3 } from "./components/second-level-panel.vue.es2.js";
11
11
  let apps;
12
12
  _sfc_main.install = function(app) {
13
13
  apps = app;
14
14
  app.component(_sfc_main.name, _sfc_main);
15
15
  };
16
- const t = (key) => {
17
- var _a, _b, _c, _d, _e, _f, _g;
18
- const array = key.split(".");
19
- return ((_b = (_a = apps == null ? void 0 : apps.config) == null ? void 0 : _a.globalProperties) == null ? void 0 : _b.$t) ? (_d = (_c = apps == null ? void 0 : apps.config) == null ? void 0 : _c.globalProperties) == null ? void 0 : _d.$t(key) : (_g = (_f = (_e = zhCN) == null ? void 0 : _e[array == null ? void 0 : array[0]]) == null ? void 0 : _f[array == null ? void 0 : array[1]]) == null ? void 0 : _g[array == null ? void 0 : array[2]];
16
+ const t = (key, params) => {
17
+ var _a, _b, _c, _d, _e;
18
+ if ((_b = (_a = apps == null ? void 0 : apps.config) == null ? void 0 : _a.globalProperties) == null ? void 0 : _b.$t) {
19
+ return apps.config.globalProperties.$t(key, params);
20
+ }
21
+ const lang = ((_e = (_d = (_c = apps == null ? void 0 : apps.config) == null ? void 0 : _c.globalProperties) == null ? void 0 : _d.$i18n) == null ? void 0 : _e.locale) || "zhCN";
22
+ return customTranslate(key, params, lang);
20
23
  };
24
+ function customTranslate(key, params, lang = "zhCN") {
25
+ const resources = { zhCN, enUS };
26
+ const i18nResources = resources[lang] || resources["zhCN"];
27
+ const value = key.split(".").reduce((obj, k) => obj && obj[k] !== void 0 ? obj[k] : void 0, i18nResources);
28
+ let template = typeof value === "string" ? value : key;
29
+ if (params && typeof params === "object") {
30
+ Object.keys(params).forEach((k) => {
31
+ const value2 = params[k] ?? "";
32
+ template = template.replaceAll(`{${k}}`, String(value2));
33
+ });
34
+ }
35
+ template = template.replace(/{{\s*\w+\s*}}/g, "");
36
+ return template;
37
+ }
21
38
  export {
22
- default3 as TinySearchBoxFirstLevelPanel,
23
- default4 as TinySearchBoxSecondLevelPanel,
39
+ default2 as TinySearchBoxFirstLevelPanel,
40
+ default3 as TinySearchBoxSecondLevelPanel,
24
41
  _sfc_main as default,
25
- default2 as enUS,
42
+ enUS,
26
43
  t,
27
44
  zhCN
28
45
  };
@@ -1,4 +1,4 @@
1
- const en_US = {
1
+ const enUS = {
2
2
  tvp: {
3
3
  tvpSearchbox: {
4
4
  defaultPlaceholder: "Select attribute filtering or enter keywords",
@@ -40,5 +40,5 @@ const en_US = {
40
40
  }
41
41
  };
42
42
  export {
43
- en_US as default
43
+ enUS as default
44
44
  };
@@ -15,11 +15,28 @@ index_vue_vue_type_script_setup_true_lang.default.install = function(app) {
15
15
  apps = app;
16
16
  app.component(index_vue_vue_type_script_setup_true_lang.default.name, index_vue_vue_type_script_setup_true_lang.default);
17
17
  };
18
- const t = (key) => {
19
- var _a, _b, _c, _d, _e, _f, _g;
20
- const array = key.split(".");
21
- return ((_b = (_a = apps == null ? void 0 : apps.config) == null ? void 0 : _a.globalProperties) == null ? void 0 : _b.$t) ? (_d = (_c = apps == null ? void 0 : apps.config) == null ? void 0 : _c.globalProperties) == null ? void 0 : _d.$t(key) : (_g = (_f = (_e = zh_CN.default) == null ? void 0 : _e[array == null ? void 0 : array[0]]) == null ? void 0 : _f[array == null ? void 0 : array[1]]) == null ? void 0 : _g[array == null ? void 0 : array[2]];
18
+ const t = (key, params) => {
19
+ var _a, _b, _c, _d, _e;
20
+ if ((_b = (_a = apps == null ? void 0 : apps.config) == null ? void 0 : _a.globalProperties) == null ? void 0 : _b.$t) {
21
+ return apps.config.globalProperties.$t(key, params);
22
+ }
23
+ const lang = ((_e = (_d = (_c = apps == null ? void 0 : apps.config) == null ? void 0 : _c.globalProperties) == null ? void 0 : _d.$i18n) == null ? void 0 : _e.locale) || "zhCN";
24
+ return customTranslate(key, params, lang);
22
25
  };
26
+ function customTranslate(key, params, lang = "zhCN") {
27
+ const resources = { zhCN: zh_CN.default, enUS: en_US.default };
28
+ const i18nResources = resources[lang] || resources["zhCN"];
29
+ const value = key.split(".").reduce((obj, k) => obj && obj[k] !== void 0 ? obj[k] : void 0, i18nResources);
30
+ let template = typeof value === "string" ? value : key;
31
+ if (params && typeof params === "object") {
32
+ Object.keys(params).forEach((k) => {
33
+ const value2 = params[k] ?? "";
34
+ template = template.replaceAll(`{${k}}`, String(value2));
35
+ });
36
+ }
37
+ template = template.replace(/{{\s*\w+\s*}}/g, "");
38
+ return template;
39
+ }
23
40
  exports.zhCN = zh_CN.default;
24
41
  exports.enUS = en_US.default;
25
42
  exports.default = index_vue_vue_type_script_setup_true_lang.default;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const en_US = {
3
+ const enUS = {
4
4
  tvp: {
5
5
  tvpSearchbox: {
6
6
  defaultPlaceholder: "Select attribute filtering or enter keywords",
@@ -41,4 +41,4 @@ const en_US = {
41
41
  }
42
42
  }
43
43
  };
44
- exports.default = en_US;
44
+ exports.default = enUS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentiny/vue-search-box",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/opentiny/tiny-search-box#readme",
6
6
  "bugs": {