@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transifex/native",
3
- "version": "2.0.0-rc2",
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
- "module": "src/index.js",
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
- 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
+ }
@@ -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
  }
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,