@transifex/native 1.0.2 → 2.0.0-rc1
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/README.md +19 -15
- package/dist/browser.native.js +2 -2
- package/dist/browser.native.js.map +1 -1
- package/dist/node.native.js +2 -2
- package/dist/node.native.js.map +1 -1
- package/package.json +4 -4
- package/src/TxNative.js +18 -5
- package/src/utils.js +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transifex/native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc1",
|
|
4
4
|
"description": "Transifex Native for Javascript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transifex",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"url": "https://github.com/transifex/transifex-javascript/issues"
|
|
29
29
|
},
|
|
30
30
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
31
|
+
"node": ">=12.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/core": "^7.14.5",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"eslint-loader": "^4.0.2",
|
|
44
44
|
"eslint-plugin-import": "^2.23.4",
|
|
45
45
|
"glob": "^7.1.7",
|
|
46
|
-
"mocha": "^
|
|
46
|
+
"mocha": "^9.1.3",
|
|
47
47
|
"nock": "^13.1.0",
|
|
48
48
|
"nyc": "^15.1.0",
|
|
49
49
|
"source-map-support": "^0.5.19",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@messageformat/core": "^3.0.0",
|
|
55
|
-
"axios": "^0.
|
|
55
|
+
"axios": "^0.24.0",
|
|
56
56
|
"md5": "^2.3.0"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/src/TxNative.js
CHANGED
|
@@ -6,7 +6,7 @@ import SourceErrorPolicy from './policies/SourceErrorPolicy';
|
|
|
6
6
|
import SourceStringPolicy from './policies/SourceStringPolicy';
|
|
7
7
|
import MessageFormatRenderer from './renderers/MessageFormatRenderer';
|
|
8
8
|
import {
|
|
9
|
-
generateKey, isString, isPluralized, escape,
|
|
9
|
+
generateKey, isString, isPluralized, escape, generateHashedKey,
|
|
10
10
|
} from './utils';
|
|
11
11
|
import {
|
|
12
12
|
sendEvent,
|
|
@@ -97,11 +97,24 @@ export default class TxNative {
|
|
|
97
97
|
*/
|
|
98
98
|
translateLocale(locale, sourceString, params) {
|
|
99
99
|
try {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
// get translation from source based key (2.x.x)
|
|
101
|
+
let translation = this.cache.get(
|
|
102
|
+
generateKey(sourceString, params),
|
|
103
|
+
locale,
|
|
104
|
+
);
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
// fall back to hash based key (1.x.x)
|
|
107
|
+
if (!translation) {
|
|
108
|
+
translation = this.cache.get(
|
|
109
|
+
generateHashedKey(sourceString, params),
|
|
110
|
+
locale,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (translation
|
|
115
|
+
&& translation.startsWith('{???')
|
|
116
|
+
&& isPluralized(sourceString)
|
|
117
|
+
) {
|
|
105
118
|
const variableName = sourceString
|
|
106
119
|
.substring(1, sourceString.indexOf(','))
|
|
107
120
|
.trim();
|
package/src/utils.js
CHANGED
|
@@ -11,6 +11,25 @@ import md5 from 'md5';
|
|
|
11
11
|
export function generateKey(string, options = {}) {
|
|
12
12
|
if (options._key) return options._key;
|
|
13
13
|
|
|
14
|
+
if (options._context) {
|
|
15
|
+
return `${string}::${options._context}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ensure string is returned
|
|
19
|
+
return `${string}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Generate a hashed based string key
|
|
24
|
+
*
|
|
25
|
+
* @export
|
|
26
|
+
* @param {String} string
|
|
27
|
+
* @param {Object} options
|
|
28
|
+
* @returns {String} key
|
|
29
|
+
*/
|
|
30
|
+
export function generateHashedKey(string, options = {}) {
|
|
31
|
+
if (options._key) return options._key;
|
|
32
|
+
|
|
14
33
|
let context = '';
|
|
15
34
|
if (options._context) {
|
|
16
35
|
context = options._context;
|