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

@m6web/react-i18n

Package Overview
Dependencies
Maintainers
11
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 1.1.0 to 1.2.0

24

lib/components/i18n.container.js

@@ -18,15 +18,21 @@ 'use strict';

var _i18n = require('./i18n.context');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var translate = exports.translate = function translate(RenderComponent) {
var TranslatedComponent = function TranslatedComponent(props, context) {
var t = context.getTranslateFunction();
var TranslatedComponent = function TranslatedComponent(props) {
return _react2.default.createElement(
_i18n.Consumer,
null,
function (t) {
if (props.componentRef) {
return _react2.default.createElement(RenderComponent, _extends({ t: t }, props, { ref: function ref(element) {
return props.componentRef(element);
} }));
}
if (props.componentRef) {
return _react2.default.createElement(RenderComponent, _extends({ t: t }, props, { ref: function ref(element) {
return props.componentRef(element);
} }));
}
return _react2.default.createElement(RenderComponent, _extends({ t: t }, props));
return _react2.default.createElement(RenderComponent, _extends({ t: t }, props));
}
);
};

@@ -33,0 +39,0 @@

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

});
exports.I18nContext = undefined;
exports.Consumer = exports.Provider = undefined;

@@ -15,2 +15,7 @@ var _react = require('react');

var I18nContext = exports.I18nContext = _react2.default.createContext('translation');
var _React$createContext = _react2.default.createContext('translation'),
Provider = _React$createContext.Provider,
Consumer = _React$createContext.Consumer;
exports.Provider = Provider;
exports.Consumer = Consumer;

@@ -8,4 +8,6 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');

@@ -15,47 +17,19 @@

var _react = require('react');
var _i18n = require('../utils/i18n.utils');
var _i18n2 = require('./i18n.context');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var I18nProvider = exports.I18nProvider = function I18nProvider(_ref) {
var lang = _ref.lang,
i18nNames = _ref.i18nNames,
children = _ref.children;
return _react2.default.createElement(
_i18n2.Provider,
{ value: (0, _i18n.translate)(lang, i18nNames) },
children
);
};
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var I18nProvider = exports.I18nProvider = function (_Component) {
_inherits(I18nProvider, _Component);
function I18nProvider(props, context) {
_classCallCheck(this, I18nProvider);
var _this = _possibleConstructorReturn(this, (I18nProvider.__proto__ || Object.getPrototypeOf(I18nProvider)).call(this, props, context));
_this.translate = (0, _i18n.translate)(_this.props.lang, _this.props.i18nNames);
return _this;
}
_createClass(I18nProvider, [{
key: 'getChildContext',
value: function getChildContext() {
var _this2 = this;
return {
getTranslateFunction: function getTranslateFunction() {
return _this2.translate;
}
};
}
}, {
key: 'render',
value: function render() {
return _react.Children.only(this.props.children);
}
}]);
return I18nProvider;
}(_react.Component);
I18nProvider.propTypes = {

@@ -65,6 +39,2 @@ children: _propTypes2.default.element.isRequired,

i18nNames: _propTypes2.default.object
};
I18nProvider.childContextTypes = {
getTranslateFunction: _propTypes2.default.func
};

@@ -18,2 +18,4 @@ 'use strict';

var _i18n = require('./i18n.context');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -23,3 +25,3 @@

var HtmlTrans = function HtmlTrans(_ref, _ref2) {
var HtmlTrans = function HtmlTrans(_ref) {
var i18nKey = _ref.i18nKey,

@@ -29,11 +31,12 @@ data = _ref.data,

general = _ref.general,
element = _ref.element,
otherProps = _objectWithoutProperties(_ref, ['i18nKey', 'data', 'number', 'general', 'element']);
Element = _ref.element,
props = _objectWithoutProperties(_ref, ['i18nKey', 'data', 'number', 'general', 'element']);
var getTranslateFunction = _ref2.getTranslateFunction;
var t = getTranslateFunction();
var props = _extends({}, otherProps, { dangerouslySetInnerHTML: { __html: t(i18nKey, data, number, general) } });
return _react2.default.createElement(element, props);
return _react2.default.createElement(
_i18n.Consumer,
null,
function (t) {
return _react2.default.createElement(Element, _extends({}, props, { dangerouslySetInnerHTML: { __html: t(i18nKey, data, number, general) } }));
}
);
};

@@ -40,0 +43,0 @@

@@ -8,2 +8,6 @@ 'use strict';

var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');

@@ -13,5 +17,7 @@

var _i18n = require('./i18n.context');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Trans = exports.Trans = function Trans(_ref, _ref2) {
var Trans = exports.Trans = function Trans(_ref) {
var i18nKey = _ref.i18nKey,

@@ -21,7 +27,9 @@ data = _ref.data,

general = _ref.general;
var getTranslateFunction = _ref2.getTranslateFunction;
var t = getTranslateFunction();
return t(i18nKey, data, number, general);
return _react2.default.createElement(
_i18n.Consumer,
null,
function (t) {
return t(i18nKey, data, number, general);
}
);
};

@@ -28,0 +36,0 @@

{
"name": "@m6web/react-i18n",
"version": "1.1.0",
"version": "1.2.0",
"description": "Provider and utils for translation in a react app",

@@ -14,3 +14,3 @@ "main": "lib/index.js",

"prop-types": "^15.6.2",
"react": "^16.0.0"
"react": "^16.4.2"
},

@@ -33,5 +33,5 @@ "jest": {

"prop-types": "15.6.2",
"react": "16.4.1",
"react": "16.4.2",
"react-addons-test-utils": "15.6.2",
"react-dom": "16.4.1"
"react-dom": "16.4.2"
},

@@ -38,0 +38,0 @@ "dependencies": {

@@ -7,4 +7,6 @@ # React i18n for 6play apps

It uses react context to provide translation function to every components.
It uses react context API to provide translation function to every components.
React version: `^16.4.0`
## Setup

@@ -11,0 +13,0 @@

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