@transifex/native 1.0.4 → 2.0.0-rc3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transifex/native",
3
- "version": "1.0.4",
3
+ "version": "2.0.0-rc3",
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": ">=10.0.0"
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": "^8.4.0",
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.21.1",
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
- const pluralized = isPluralized(sourceString);
101
- const key = generateKey(sourceString, params);
102
- let translation = this.cache.get(key, locale);
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
- if (translation && pluralized && translation.startsWith('{???')) {
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
- import Native = require('@transifex/native');
2
- export const tx : Native.tx;
3
- export const t : Native.t;
4
- export const PseudoTranslationPolicy: Native.PseudoTranslationPolicy;
5
- export const SourceStringPolicy: Native.SourceStringPolicy;
6
- export const SourceErrorPolicy: Native.SourceErrorPolicy;
7
- export const ThrowErrorPolicy: Native.ThrowErrorPolicy;
8
- export const MessageFormatRenderer: Native.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
@@ -1,5 +1,5 @@
1
- const nodeConfig = require('./webpack.node.js');
2
- const browserConfig = require('./webpack.browser.js');
1
+ const nodeConfig = require('./webpack.node');
2
+ const browserConfig = require('./webpack.browser');
3
3
 
4
4
  module.exports = [
5
5
  nodeConfig,