@transifex/native 1.0.5 → 2.0.0
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.d.ts +9 -8
- package/dist/node.native.js +2 -2
- package/dist/node.native.js.map +1 -1
- package/package.json +5 -4
- package/src/TxNative.js +18 -5
- package/src/index.d.ts +9 -8
- package/src/utils.js +19 -0
- package/webpack.config.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transifex/native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Transifex Native for Javascript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transifex",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"main": "dist/node.native.js",
|
|
15
15
|
"browser": "dist/browser.native.js",
|
|
16
16
|
"module": "src/index.js",
|
|
17
|
+
"types": "dist/node.native.d.ts",
|
|
17
18
|
"publishConfig": {
|
|
18
19
|
"access": "public"
|
|
19
20
|
},
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
"url": "https://github.com/transifex/transifex-javascript/issues"
|
|
29
30
|
},
|
|
30
31
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
32
|
+
"node": ">=12.0.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@babel/core": "^7.14.5",
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"eslint-loader": "^4.0.2",
|
|
44
45
|
"eslint-plugin-import": "^2.23.4",
|
|
45
46
|
"glob": "^7.1.7",
|
|
46
|
-
"mocha": "^
|
|
47
|
+
"mocha": "^9.1.3",
|
|
47
48
|
"nock": "^13.1.0",
|
|
48
49
|
"nyc": "^15.1.0",
|
|
49
50
|
"source-map-support": "^0.5.19",
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"@messageformat/core": "^3.0.0",
|
|
55
|
-
"axios": "^0.
|
|
56
|
+
"axios": "^0.24.0",
|
|
56
57
|
"md5": "^2.3.0"
|
|
57
58
|
}
|
|
58
59
|
}
|
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/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export const tx
|
|
3
|
-
export const t
|
|
4
|
-
export const PseudoTranslationPolicy:
|
|
5
|
-
export const SourceStringPolicy:
|
|
6
|
-
export const SourceErrorPolicy:
|
|
7
|
-
export const ThrowErrorPolicy:
|
|
8
|
-
export const MessageFormatRenderer:
|
|
1
|
+
declare module '@transifex/native' {
|
|
2
|
+
export const tx: any;
|
|
3
|
+
export const t: any;
|
|
4
|
+
export const PseudoTranslationPolicy: any;
|
|
5
|
+
export const SourceStringPolicy: any;
|
|
6
|
+
export const SourceErrorPolicy: any;
|
|
7
|
+
export const ThrowErrorPolicy: any;
|
|
8
|
+
export const MessageFormatRenderer: any;
|
|
9
|
+
}
|
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;
|
package/webpack.config.js
CHANGED