Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@m6web/react-i18n

Package Overview
Dependencies
Maintainers
8
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@m6web/react-i18n - npm Package Compare versions

Comparing version 2.0.0-alpha.1 to 2.0.0

LICENCE.md

21

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [2.0.0](https://github.com/BedrockStreaming/i18n-tools/compare/@m6web/react-i18n@2.0.0-alpha.0...@m6web/react-i18n@2.0.0) (2022-01-07)
### Features
* **react-i18n:** add dutch plural ([#89](https://github.com/BedrockStreaming/i18n-tools/issues/89)) ([714620a](https://github.com/BedrockStreaming/i18n-tools/commit/714620a338548222a6d191931d65653b1ccbd696))
## [1.9.2](https://github.com/M6Web/i18n-tools/compare/@m6web/react-i18n@1.9.1...@m6web/react-i18n@1.9.2) (2021-03-17)

@@ -11,2 +22,6 @@

## [1.9.1](https://github.com/M6Web/i18n-tools/compare/@m6web/react-i18n@1.9.0...@m6web/react-i18n@1.9.1) (2021-03-09)

@@ -16,4 +31,9 @@

# [1.9.0](https://github.com/M6Web/i18n-tools/compare/@m6web/react-i18n@1.9.0...@m6web/react-i18n@1.9.0) (2021-03-08)
### Bug Fixes

@@ -27,2 +47,3 @@

### Features

@@ -29,0 +50,0 @@

9

es/components/i18n.provider.js

@@ -1,2 +0,2 @@

import React, { useMemo } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

@@ -12,10 +12,5 @@ import { translate } from '../utils/i18n.utils';

parseHTML = _ref.parseHTML;
var t = useMemo(function () {
return translate(lang, { i18nNames: i18nNames, errorCallback: errorCallback, parseHTML: parseHTML });
}, [lang, i18nNames, errorCallback, parseHTML]);
return React.createElement(
Context.Provider,
{ value: t },
{ value: translate(lang, i18nNames, errorCallback, parseHTML) },
children

@@ -22,0 +17,0 @@ );

@@ -22,3 +22,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function (t) {
return React.createElement(Element, _extends({}, props, { dangerouslySetInnerHTML: { __html: t(i18nKey, { data: data, number: number, general: general, renderers: renderers }) } }));
return React.createElement(Element, _extends({}, props, { dangerouslySetInnerHTML: { __html: t(i18nKey, data, number, general, renderers) } }));
}

@@ -25,0 +25,0 @@ );

@@ -15,3 +15,3 @@ import React from 'react';

function (t) {
return t(i18nKey, { data: data, number: number, general: general, renderers: renderers });
return t(i18nKey, data, number, general, renderers);
}

@@ -18,0 +18,0 @@ );

import { useContext } from 'react';
import { Context } from '../context/i18n.context';
var emptyObject = {};
export var useTranslate = function useTranslate() {

@@ -9,5 +8,10 @@ var t = useContext(Context);

return function (key) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : emptyObject;
return t(key, data);
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
data = _ref.data,
number = _ref.number,
general = _ref.general,
renderers = _ref.renderers;
return t(key, data, number, general, renderers);
};
};

@@ -12,3 +12,3 @@ import _has from 'lodash-es/has';

en: function en(number) {
return number === 0 || number > 1 ? 'other' : 'one';
return number === 1 ? 'one' : 'other';
},

@@ -18,9 +18,2 @@ fr: function fr(number) {

},
hu: function hu(number, general) {
if (!general) {
return 'one';
}
return number > 1 ? 'other' : 'one';
},
hr: function hr(number, general) {

@@ -47,23 +40,27 @@ // General plural

return '';
},
hu: function hu(number, general) {
if (!general) {
return 'one';
}
return number > 1 ? 'other' : 'one';
},
nl: function nl(number) {
return number === 1 ? 'one' : 'other';
}
};
var defaultConfig = { i18nNames: {}, errorCallback: _noop, parseHTML: false };
export var translate = function translate(lang) {
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var i18nNames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var errorCallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _noop;
var parseHTML = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var _defaultConfig$config = _extends({}, defaultConfig, config),
i18nNames = _defaultConfig$config.i18nNames,
errorCallback = _defaultConfig$config.errorCallback,
parseHTML = _defaultConfig$config.parseHTML;
var pluralize = pluralizeFunctions[_get(lang, '_i18n.lang')] || pluralizeFunctions.fr;
return function (key) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$data = _ref.data,
data = _ref$data === undefined ? {} : _ref$data,
number = _ref.number,
general = _ref.general,
renderers = _ref.renderers;
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var number = arguments[2];
var general = arguments[3];
var renderers = arguments[4];

@@ -70,0 +67,0 @@ var combineKey = key;

@@ -28,10 +28,5 @@ 'use strict';

parseHTML = _ref.parseHTML;
var t = (0, _react.useMemo)(function () {
return (0, _i18n.translate)(lang, { i18nNames: i18nNames, errorCallback: errorCallback, parseHTML: parseHTML });
}, [lang, i18nNames, errorCallback, parseHTML]);
return _react2.default.createElement(
_i18n2.Context.Provider,
{ value: t },
{ value: (0, _i18n.translate)(lang, i18nNames, errorCallback, parseHTML) },
children

@@ -38,0 +33,0 @@ );

@@ -37,3 +37,3 @@ 'use strict';

function (t) {
return _react2.default.createElement(Element, _extends({}, props, { dangerouslySetInnerHTML: { __html: t(i18nKey, { data: data, number: number, general: general, renderers: renderers }) } }));
return _react2.default.createElement(Element, _extends({}, props, { dangerouslySetInnerHTML: { __html: t(i18nKey, data, number, general, renderers) } }));
}

@@ -40,0 +40,0 @@ );

@@ -30,3 +30,3 @@ 'use strict';

function (t) {
return t(i18nKey, { data: data, number: number, general: general, renderers: renderers });
return t(i18nKey, data, number, general, renderers);
}

@@ -33,0 +33,0 @@ );

@@ -12,3 +12,2 @@ 'use strict';

var emptyObject = {};
var useTranslate = exports.useTranslate = function useTranslate() {

@@ -18,5 +17,10 @@ var t = (0, _react.useContext)(_i18n.Context);

return function (key) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : emptyObject;
return t(key, data);
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
data = _ref.data,
number = _ref.number,
general = _ref.general,
renderers = _ref.renderers;
return t(key, data, number, general, renderers);
};
};

@@ -22,3 +22,3 @@ 'use strict';

en: function en(number) {
return number === 0 || number > 1 ? 'other' : 'one';
return number === 1 ? 'one' : 'other';
},

@@ -28,9 +28,2 @@ fr: function fr(number) {

},
hu: function hu(number, general) {
if (!general) {
return 'one';
}
return number > 1 ? 'other' : 'one';
},
hr: function hr(number, general) {

@@ -57,23 +50,27 @@ // General plural

return '';
},
hu: function hu(number, general) {
if (!general) {
return 'one';
}
return number > 1 ? 'other' : 'one';
},
nl: function nl(number) {
return number === 1 ? 'one' : 'other';
}
};
var defaultConfig = { i18nNames: {}, errorCallback: _lodash2.default.noop, parseHTML: false };
var translate = exports.translate = function translate(lang) {
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var i18nNames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var errorCallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _lodash2.default.noop;
var parseHTML = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var _defaultConfig$config = _extends({}, defaultConfig, config),
i18nNames = _defaultConfig$config.i18nNames,
errorCallback = _defaultConfig$config.errorCallback,
parseHTML = _defaultConfig$config.parseHTML;
var pluralize = pluralizeFunctions[_lodash2.default.get(lang, '_i18n.lang')] || pluralizeFunctions.fr;
return function (key) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$data = _ref.data,
data = _ref$data === undefined ? {} : _ref$data,
number = _ref.number,
general = _ref.general,
renderers = _ref.renderers;
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var number = arguments[2];
var general = arguments[3];
var renderers = arguments[4];

@@ -80,0 +77,0 @@ var combineKey = key;

{
"name": "@m6web/react-i18n",
"version": "2.0.0-alpha.1",
"version": "2.0.0",
"description": "Provider and utils for translation in a react app",
"main": "lib/index.js",
"types": "src/index.d.ts",
"module": "es/index.js",

@@ -54,3 +55,4 @@ "author": "m6web",

"release": "yarn lint && yarn test && yarn build && yarn version"
}
},
"gitHead": "485331638c939413428d4bb72cf3798e8ac5fd7d"
}

@@ -10,2 +10,3 @@ # @m6web/react-i18n

This library brings internationalisation through a set of react components.

@@ -60,3 +61,2 @@

### i18n Provider
This component will provide the translation function to following components via the React.Context api.

@@ -221,6 +221,7 @@

| -------- | ------- | -------- | -------------- | ------------ | ------------- | ------------ |
| EN | `other` | `one` | `other` | `other` | - | - |
| FR | `one` | `one` | `other` | `other` | - | - |
| EN | `other` | `one` | `other` | `other` | - | - |
| HR | `many` | `one` | `other` | `one` | `few` | `many` |
| HU | `one` | `one` | `other` | `one` | - | - |
| HR | `many` | `one` | `other` | `one` | `few` | `many` |
| NL | `other` | `one` | `other` | `other` | - | - |

@@ -232,3 +233,2 @@ The variable used in translation template string has to be `%(number)d`, and is automatically provided by the translate function.

### HTML Interpolation
Basic html tags are automatically interpolated in translation if the syntax is correct (opening tag should be close within the translation).

@@ -239,5 +239,3 @@

Basic textual interpolations are proceeded first, and the HTML comes in a second time.
* translation
- translation
```json

@@ -250,5 +248,3 @@ {

```
* code
- code
```jsx

@@ -266,7 +262,5 @@ import React from 'react';

);
};
}
```
* result
- result
```jsx harmony

@@ -281,15 +275,12 @@ <div>

#### excluded elements
For now `script` and `iframe` elements are ignored with all their children in the HTML tree.
For now `script` and `iframe` elements are ignored with all their children in the HTML tree.
#### keys
In case of arrays of component, keys will be automatically generated to please React.
* translation
- translation
```js
{
foo: {
bar: '<h1>Test</h1>' +
bar:
'<h1>Test</h1>' +
'<p>This is not what we wanna do with this lib but we need to ensure it works anyway</p>' +

@@ -300,9 +291,7 @@ '<ul>' +

'<li>and an auto closing br <br /></li>' +
'</ul>';
'</ul>'
}
}
};
```
* result
- result
```jsx harmony

@@ -309,0 +298,0 @@ <div>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc