@transifex/native 2.0.0-rc2 → 2.1.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/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 +2 -2
- package/src/index.d.ts +9 -8
- package/src/renderers/MessageFormatRenderer.js +14 -2
- package/webpack.config.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transifex/native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Transifex Native for Javascript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transifex",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"main": "dist/node.native.js",
|
|
15
15
|
"browser": "dist/browser.native.js",
|
|
16
|
-
"
|
|
16
|
+
"types": "dist/node.native.d.ts",
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
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
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* eslint-disable class-methods-use-this */
|
|
2
2
|
import MessageFormat from '@messageformat/core';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// object to cache MessageFormat classes related to
|
|
5
|
+
// specific locales
|
|
6
|
+
const MF = {};
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* MessageFormat renderer
|
|
@@ -11,7 +13,17 @@ const MF = new MessageFormat();
|
|
|
11
13
|
*/
|
|
12
14
|
export default class MessageFormatRenderer {
|
|
13
15
|
render(sourceString, localeCode, params) {
|
|
14
|
-
|
|
16
|
+
// construct a MessageFormat class based on locale
|
|
17
|
+
// to make dates and other content localizable
|
|
18
|
+
const locale = ((localeCode || '').split('_'))[0];
|
|
19
|
+
if (!MF[locale]) {
|
|
20
|
+
try {
|
|
21
|
+
MF[locale] = new MessageFormat(locale);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
MF[locale] = new MessageFormat();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const msg = MF[locale].compile(sourceString);
|
|
15
27
|
return msg(params);
|
|
16
28
|
}
|
|
17
29
|
}
|
package/webpack.config.js
CHANGED