@abtnode/util 1.16.14-beta-c308dc3b → 1.16.14-beta-963cb583

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.
Files changed (2) hide show
  1. package/lib/translate.js +19 -0
  2. package/package.json +9 -9
@@ -0,0 +1,19 @@
1
+ /* eslint-disable no-prototype-builtins */
2
+ const replace = (template, data) =>
3
+ template.replace(/{(\w*)}/g, (m, key) => (data.hasOwnProperty(key) ? data[key] : ''));
4
+
5
+ const createTranslator = ({ translations, fallbackLocale = 'en' }) => {
6
+ return (key, locale = fallbackLocale, data = {}) => {
7
+ if (!translations[locale] || !translations[locale][key]) {
8
+ if (fallbackLocale && translations[fallbackLocale]?.[key]) {
9
+ return replace(translations[fallbackLocale]?.[key], data);
10
+ }
11
+
12
+ return key;
13
+ }
14
+
15
+ return replace(translations[locale][key], data);
16
+ };
17
+ };
18
+
19
+ module.exports = createTranslator;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.14-beta-c308dc3b",
6
+ "version": "1.16.14-beta-963cb583",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,13 +18,13 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "Apache-2.0",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.16.14-beta-c308dc3b",
22
- "@abtnode/logger": "1.16.14-beta-c308dc3b",
23
- "@blocklet/constant": "1.16.14-beta-c308dc3b",
24
- "@ocap/client": "1.18.88",
25
- "@ocap/mcrypto": "1.18.88",
26
- "@ocap/util": "1.18.88",
27
- "@ocap/wallet": "1.18.88",
21
+ "@abtnode/constant": "1.16.14-beta-963cb583",
22
+ "@abtnode/logger": "1.16.14-beta-963cb583",
23
+ "@blocklet/constant": "1.16.14-beta-963cb583",
24
+ "@ocap/client": "1.18.89",
25
+ "@ocap/mcrypto": "1.18.89",
26
+ "@ocap/util": "1.18.89",
27
+ "@ocap/wallet": "1.18.89",
28
28
  "archiver": "^5.3.1",
29
29
  "axios": "^0.27.2",
30
30
  "axios-mock-adapter": "^1.21.2",
@@ -71,5 +71,5 @@
71
71
  "fs-extra": "^10.1.0",
72
72
  "jest": "^27.5.1"
73
73
  },
74
- "gitHead": "c08aaac7fb25d0f1c81c8866baf5579714416485"
74
+ "gitHead": "82bae80cd584a096719d6985740e13f15b4f46bf"
75
75
  }