@ray-js/api 1.4.50-beta.1 → 1.4.51

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,2 @@
1
- export default function getCdnUrl(path: string): string;
2
- export declare function getCdnUrlAsync(path: string): Promise<string>;
1
+ export default function getCdnUrl(path: string, cdnMap?: Record<string, string>, region?: string): string;
2
+ export declare function getCdnUrlAsync(path: string, cdnMap?: Record<string, string>, region?: string): Promise<string>;
@@ -1,8 +1,7 @@
1
1
  export default function getCdnUrl(path) {
2
- // 暂未实现获取cdn方法,将直接返回path
3
2
  return path;
4
3
  }
5
- export function getCdnUrlAsync(path) {
4
+ export async function getCdnUrlAsync(path) {
6
5
  // 暂未实现获取cdn方法,将直接返回path
7
6
  return Promise.resolve(path);
8
7
  }
@@ -1,2 +1,2 @@
1
- export default function getCdnUrl(path: string): string;
2
- export declare function getCdnUrlAsync(path: string): Promise<string>;
1
+ export default function getCdnUrl(path: string, cdnMap?: Record<string, string>, region?: string): string;
2
+ export declare function getCdnUrlAsync(path: string, cdnMap?: Record<string, string>, region?: string): Promise<string>;
@@ -1,8 +1,7 @@
1
1
  export default function getCdnUrl(path) {
2
- // 暂未实现获取cdn方法,将直接返回path
3
2
  return path;
4
3
  }
5
- export function getCdnUrlAsync(path) {
4
+ export async function getCdnUrlAsync(path) {
6
5
  // 暂未实现获取cdn方法,将直接返回path
7
6
  return Promise.resolve(path);
8
7
  }
@@ -1,27 +1,28 @@
1
1
  type LanguageMap = {
2
2
  [key: string]: Record<string, string>;
3
3
  };
4
- export default class I18N {
4
+ export declare const updateI18n: (data: LanguageMap) => void;
5
+ export default class I18N<LanMap extends LanguageMap, Lan extends LanMap[keyof LanMap] = LanMap[keyof LanMap]> {
5
6
  [x: string]: any;
6
- strings: LanguageMap;
7
+ strings: LanMap;
7
8
  defaultLang: string;
8
9
  __language: string;
9
- constructor(props: LanguageMap);
10
+ constructor(props: LanMap);
10
11
  forceUpdateNetworkLang(productId: string): void;
11
- mergeLanguage(L1: LanguageMap, L2: LanguageMap): LanguageMap;
12
+ mergeLanguage(L1: LanguageMap, L2: LanguageMap): any;
12
13
  isZh(language: string): boolean;
13
14
  setLanguage(language: string): void;
14
15
  buildLanguage(language: string): void;
15
16
  _getBestMatchingLanguage(language: string, props: LanguageMap): any;
16
17
  formatString(str: string, ...values: any[]): string;
17
- formatValue(key: string, ...values: any[]): any;
18
+ formatValue(key: keyof Lan, ...values: any[]): any;
18
19
  _replaceAll(find: string, replace: string, str: string): string;
19
20
  getDpLang(code: string | number, value?: undefined | boolean | string): any;
20
21
  getDpName(code: string, defaultName: string): any;
21
22
  getDpsLang(key: {
22
23
  [key: string]: string;
23
24
  }): {};
24
- getLang(key: string, defaultString?: string): any;
25
+ getLang(key: keyof Lan, defaultString?: string): any;
25
26
  /**
26
27
  * 获取picker标题
27
28
  * @param {*} dpCode
@@ -1,6 +1,21 @@
1
1
  import "core-js/modules/es.string.replace.js";
2
2
  import { requestCloud, getSystemInfoSync, THING } from '../..';
3
3
  import { getBitValue } from '../utils';
4
+
5
+ /**
6
+ * I18n 智能小程序中用来获取多语言的对象
7
+ * 文档: https://developer.tuya.com/cn/miniapp/framework/app/i18n
8
+ */
9
+
10
+ export const updateI18n = () => {
11
+ // 微信小程序中使用的方法,这里不需要实现
12
+ };
13
+ function hasKey(key) {
14
+ if (typeof I18n.has === 'function') {
15
+ return I18n.has(key);
16
+ }
17
+ return I18n.t(key) !== key;
18
+ }
4
19
  export default class I18N {
5
20
  constructor(props) {
6
21
  this.strings = this.mergeLanguage(props, {});
@@ -107,7 +122,7 @@ export default class I18N {
107
122
  return res;
108
123
  }
109
124
  formatValue(key) {
110
- let res = typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
125
+ let res = this.getLang(key);
111
126
  for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
112
127
  res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
113
128
  }
@@ -129,30 +144,30 @@ export default class I18N {
129
144
  } else {
130
145
  key = "dp_".concat(code, "_").concat(value).toLowerCase();
131
146
  }
132
- return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
147
+ return hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
133
148
  }
134
149
  getDpName(code, defaultName) {
135
150
  const key = "dp_".concat(code).toLowerCase();
136
- return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
151
+ return hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
137
152
  }
138
153
  getDpsLang(key) {
139
154
  let strs = {};
140
155
  if (typeof key === 'object') {
141
156
  if (typeof key.strKey === 'string') {
142
- strs = I18n.t(key.strKey) !== key.strKey ? I18n.t(key.strKey) : typeof this[key.strKey] !== 'undefined' ? this[key.strKey] : I18n.t(key.strKey);
157
+ strs = hasKey(key.strKey) ? I18n.t(key.strKey) : typeof this[key.strKey] !== 'undefined' ? this[key.strKey] : I18n.t(key.strKey);
143
158
  } else {
144
159
  Object.keys(key).map(i => {
145
- strs[key[i]] = I18n.t(key[i]) !== key[i] ? I18n.t(key[i]) : typeof this[key[i]] !== 'undefined' ? this[key[i]] : I18n.t(key[i]);
160
+ strs[key[i]] = hasKey(key[i]) ? I18n.t(key[i]) : typeof this[key[i]] !== 'undefined' ? this[key[i]] : I18n.t(key[i]);
146
161
  return null;
147
162
  });
148
163
  }
149
164
  } else {
150
- strs = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
165
+ strs = hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
151
166
  }
152
167
  return strs;
153
168
  }
154
169
  getLang(key, defaultString) {
155
- return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : typeof defaultString !== 'undefined' ? defaultString : I18n.t(key);
170
+ return hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : typeof defaultString !== 'undefined' ? defaultString : I18n.t(key);
156
171
  }
157
172
 
158
173
  /**
@@ -165,7 +180,7 @@ export default class I18N {
165
180
  const lists = schema.range;
166
181
  lists.map(v => {
167
182
  const key = "dp_".concat(dpCode, "_").concat(v).toLowerCase();
168
- result[v] = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
183
+ result[v] = hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
169
184
  return null;
170
185
  });
171
186
  return result;
@@ -180,11 +195,11 @@ export default class I18N {
180
195
  parseCountdown(t, power) {
181
196
  const h = parseFloat("".concat(t / 3600));
182
197
  const m = parseFloat("".concat(t / 60 - h * 60));
183
- const tHour = I18n.t('t_hour') !== 't_hour' ? I18n.t('t_hour') : typeof this.t_hour !== 'undefined' ? this.t_hour : I18n.t('t_hour');
184
- const tMinute = I18n.t('t_minute') !== 't_minute' ? I18n.t('t_minute') : typeof this.t_minute !== 'undefined' ? this.t_minute : I18n.t('t_minute');
198
+ const tHour = hasKey('t_hour') ? I18n.t('t_hour') : typeof this.t_hour !== 'undefined' ? this.t_hour : I18n.t('t_hour');
199
+ const tMinute = hasKey('t_minute') ? I18n.t('t_minute') : typeof this.t_minute !== 'undefined' ? this.t_minute : I18n.t('t_minute');
185
200
  const time = h >= 1.0 ? "".concat(Math.round(h)).concat(tHour) : "".concat(Math.round(m)).concat(tMinute);
186
201
  const key = "countdown_".concat(power ? 'on' : 'off');
187
- const str = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
202
+ const str = hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
188
203
  return this.formatString(str, time);
189
204
  }
190
205
  getFaultStrings(schema, faultCode, faultValue) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/api",
3
- "version": "1.4.50-beta.1",
3
+ "version": "1.4.51",
4
4
  "description": "Ray universal api",
5
5
  "keywords": [
6
6
  "ray"
@@ -29,14 +29,14 @@
29
29
  "watch": "ray start --type=component"
30
30
  },
31
31
  "dependencies": {
32
- "@ray-js/framework": "^1.4.50-beta.1",
33
- "@ray-js/router": "^1.4.50-beta.1",
32
+ "@ray-js/framework": "1.4.51",
33
+ "@ray-js/router": "1.4.51",
34
34
  "@ray-js/wechat": "^0.2.8",
35
35
  "base64-browser": "^1.0.1",
36
36
  "query-string": "^7.1.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@ray-js/cli": "^1.4.50-beta.1",
39
+ "@ray-js/cli": "1.4.51",
40
40
  "art-template": "^4.13.2",
41
41
  "fs-extra": "^10.1.0",
42
42
  "miniprogram-api-typings": "^3.12.2",
@@ -46,5 +46,5 @@
46
46
  "access": "public",
47
47
  "registry": "https://registry.npmjs.org"
48
48
  },
49
- "gitHead": "7f7dda6601efd676ac4f0cbdf6dc05d5ae2df6af"
49
+ "gitHead": "ef52059911e6d19ffadedbcc1cebb2c1b8e843bc"
50
50
  }