@transifex/native 2.0.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transifex/native",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Transifex Native for Javascript",
5
5
  "keywords": [
6
6
  "transifex",
@@ -1,7 +1,9 @@
1
1
  /* eslint-disable class-methods-use-this */
2
2
  import MessageFormat from '@messageformat/core';
3
3
 
4
- const MF = new MessageFormat();
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
- const msg = MF.compile(sourceString);
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
  }