@transifex/native 2.0.0-rc3 → 2.1.1
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": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Transifex Native for Javascript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transifex",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"main": "dist/node.native.js",
|
|
15
15
|
"browser": "dist/browser.native.js",
|
|
16
|
-
"module": "src/index.js",
|
|
17
16
|
"types": "dist/node.native.d.ts",
|
|
18
17
|
"publishConfig": {
|
|
19
18
|
"access": "public"
|
|
@@ -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
|
}
|