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

react-localize-redux

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-localize-redux - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

14

dist/ReactLocalizeRedux.js

@@ -224,4 +224,14 @@ (function webpackUniversalModuleDefinition(root, factory) {

var translations = getTranslationsForActiveLanguage(state);
return function (key, data) {
return (0, _utils.getLocalizedElement)(key, translations, data);
return function (value, data) {
if (typeof value === 'string') {
return (0, _utils.getLocalizedElement)(value, translations, data);
} else if (Array.isArray(value)) {
return value.reduce(function (prev, cur) {
var _extends3;
return _extends({}, prev, (_extends3 = {}, _extends3[cur] = (0, _utils.getLocalizedElement)(cur, translations, data), _extends3));
}, {});
} else {
throw new Error('react-localize-redux: invalid key passed to translate.');
}
};

@@ -228,0 +238,0 @@ };

2

dist/ReactLocalizeRedux.min.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-redux"),require("redux"),require("reselect")):"function"==typeof define&&define.amd?define(["react","react-redux","redux","reselect"],t):"object"==typeof exports?exports.ReactLocalizeRedux=t(require("react"),require("react-redux"),require("redux"),require("reselect")):e.ReactLocalizeRedux=t(e.React,e.ReactRedux,e.Redux,e.Reselect)}(this,function(e,t,n,r){return function(e){function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=9)}([function(e,t,n){"use strict";function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1],n=function(){switch(t.type){case g:var n=t.payload.languageCodes,r=t.payload.activeLanguage||n[0],a=n.indexOf(r);return{v:n.map(function(e,t){var n=t===a;return{code:e,active:n}})};case d:return{v:e.map(function(e){return e.code===t.payload.languageCode?u({},e,{active:!0}):u({},e,{active:!1})})};default:return{v:e}}}();if("object"===("undefined"==typeof n?"undefined":o(n)))return n.v}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1];switch(t.type){case f:return u({},e,(0,i.flatten)(t.payload.translation,{safe:!0}));default:return e}}t.__esModule=!0,t.getTranslate=t.getTranslationsForActiveLanguage=t.customeEqualSelector=t.getActiveLanguage=t.getLanguages=t.getTranslations=t.setActiveLanguage=t.setLanguages=t.addTranslation=t.localeReducer=t.TRANSLATE=t.SET_ACTIVE_LANGUAGE=t.SET_LANGUAGES=t.ADD_TRANSLATION=void 0;var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e};t.languages=r,t.translations=a;var c=n(7),i=n(4),l=n(8),s=n(3),f=t.ADD_TRANSLATION="@@localize/ADD_TRANSLATION",g=t.SET_LANGUAGES="@@localize/SET_LANGUAGES",d=t.SET_ACTIVE_LANGUAGE="@@localize/SET_ACTIVE_LANGUAGE",p=(t.TRANSLATE="@@localize/TRANSLATE",t.localeReducer=(0,c.combineReducers)({languages:r,translations:a}),t.addTranslation=function(e){return{type:f,payload:{translation:e}}},t.setLanguages=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return{type:g,payload:{languageCodes:e,activeLanguage:t}}},t.setActiveLanguage=function(e){return{type:d,payload:{languageCode:e}}},t.getTranslations=function(e){return e.translations}),v=t.getLanguages=function(e){return e.languages},y=t.getActiveLanguage=function(e){return v(e).find(function(e){return e.active===!0})},b=t.customeEqualSelector=(0,l.createSelectorCreator)(l.defaultMemoize,function(e,t){var n=!(Array.isArray(e)||"code,active"===Object.keys(e).toString());return n&&(t=Object.keys(t).toString(),e=Object.keys(e).toString()),t===e}),A=t.getTranslationsForActiveLanguage=b(y,v,p,function(e,t,n){var r=e.code,a=(0,s.getIndexForLanguageCode)(r,t);return Object.keys(n).reduce(function(e,t){var r;return u({},e,(r={},r[t]=n[t][a],r))},{})});t.getTranslate=function(e){var t=A(e);return function(e,n){return(0,s.getLocalizedElement)(e,t,n)}}},function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.localize=void 0;var a=n(1),o=(r(a),n(6)),u=n(0),c=function(e){return function(t){var n=e?t[e]:t;return{currentLanguage:(0,u.getActiveLanguage)(n).code,translate:(0,u.getTranslate)(n)}}};t.localize=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return(0,o.connect)(c(t),null)(e)}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.getIndexForLanguageCode=t.templater=t.hasHtmlTags=t.getLocalizedElement=void 0;var a=n(1),o=r(a),u=(t.getLocalizedElement=function(e,t,n){var r=t[e]||"Missing locaized: "+e,a=c(r,n);return u(a)?o.default.createElement("span",{dangerouslySetInnerHTML:{__html:a}}):o.default.createElement("span",null,a)},t.hasHtmlTags=function(e){var t=/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[\^'">\s]+))?)+\s*|\s*)\/?>/;return e.search(t)>=0}),c=t.templater=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(var n in t){var r="\\${\\s*"+n+"\\s*}",a=new RegExp(r,"gmi");e=e.replace(a,t[n])}return e};t.getIndexForLanguageCode=function(e,t){return t.map(function(e){return e.code}).indexOf(e)}},function(e,t,n){function r(e,t){function n(e,c,i){i=i?i:1,Object.keys(e).forEach(function(l){var s=e[l],f=t.safe&&Array.isArray(s),g=Object.prototype.toString.call(s),d=o(s),p="[object Object]"===g||"[object Array]"===g,v=c?c+r+l:l;return!f&&!d&&p&&Object.keys(s).length&&(!t.maxDepth||i<a)?n(s,v,i+1):void(u[v]=s)})}t=t||{};var r=t.delimiter||".",a=t.maxDepth,u={};return n(e),u}function a(e,t){function n(e){var t=Number(e);return isNaN(t)||e.indexOf(".")!==-1?e:t}t=t||{};var r=t.delimiter||".",u=t.overwrite||!1,c={},i=o(e);return i||"[object Object]"!==Object.prototype.toString.call(e)?e:(Object.keys(e).forEach(function(o){for(var i=o.split(r),l=n(i.shift()),s=n(i[0]),f=c;void 0!==s;){var g=Object.prototype.toString.call(f[l]),d="[object Object]"===g||"[object Array]"===g;if(!u&&!d&&"undefined"!=typeof f[l])return;(u&&!d||!u&&null==f[l])&&(f[l]="number"!=typeof s||t.object?{}:[]),f=f[l],i.length>0&&(l=n(i.shift()),s=n(i[0]))}f[l]=a(e[o],t)}),c)}var o=n(5);e.exports=r;r.flatten=r,r.unflatten=a},function(e,t){function n(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function r(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&n(e.slice(0,0))}/*!
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-redux"),require("redux"),require("reselect")):"function"==typeof define&&define.amd?define(["react","react-redux","redux","reselect"],t):"object"==typeof exports?exports.ReactLocalizeRedux=t(require("react"),require("react-redux"),require("redux"),require("reselect")):e.ReactLocalizeRedux=t(e.React,e.ReactRedux,e.Redux,e.Reselect)}(this,function(e,t,n,r){return function(e){function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=9)}([function(e,t,n){"use strict";function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1],n=function(){switch(t.type){case g:var n=t.payload.languageCodes,r=t.payload.activeLanguage||n[0],a=n.indexOf(r);return{v:n.map(function(e,t){var n=t===a;return{code:e,active:n}})};case d:return{v:e.map(function(e){return e.code===t.payload.languageCode?u({},e,{active:!0}):u({},e,{active:!1})})};default:return{v:e}}}();if("object"===("undefined"==typeof n?"undefined":o(n)))return n.v}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1];switch(t.type){case f:return u({},e,(0,i.flatten)(t.payload.translation,{safe:!0}));default:return e}}t.__esModule=!0,t.getTranslate=t.getTranslationsForActiveLanguage=t.customeEqualSelector=t.getActiveLanguage=t.getLanguages=t.getTranslations=t.setActiveLanguage=t.setLanguages=t.addTranslation=t.localeReducer=t.TRANSLATE=t.SET_ACTIVE_LANGUAGE=t.SET_LANGUAGES=t.ADD_TRANSLATION=void 0;var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e};t.languages=r,t.translations=a;var c=n(7),i=n(4),l=n(8),s=n(3),f=t.ADD_TRANSLATION="@@localize/ADD_TRANSLATION",g=t.SET_LANGUAGES="@@localize/SET_LANGUAGES",d=t.SET_ACTIVE_LANGUAGE="@@localize/SET_ACTIVE_LANGUAGE",p=(t.TRANSLATE="@@localize/TRANSLATE",t.localeReducer=(0,c.combineReducers)({languages:r,translations:a}),t.addTranslation=function(e){return{type:f,payload:{translation:e}}},t.setLanguages=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return{type:g,payload:{languageCodes:e,activeLanguage:t}}},t.setActiveLanguage=function(e){return{type:d,payload:{languageCode:e}}},t.getTranslations=function(e){return e.translations}),v=t.getLanguages=function(e){return e.languages},y=t.getActiveLanguage=function(e){return v(e).find(function(e){return e.active===!0})},b=t.customeEqualSelector=(0,l.createSelectorCreator)(l.defaultMemoize,function(e,t){var n=!(Array.isArray(e)||"code,active"===Object.keys(e).toString());return n&&(t=Object.keys(t).toString(),e=Object.keys(e).toString()),t===e}),A=t.getTranslationsForActiveLanguage=b(y,v,p,function(e,t,n){var r=e.code,a=(0,s.getIndexForLanguageCode)(r,t);return Object.keys(n).reduce(function(e,t){var r;return u({},e,(r={},r[t]=n[t][a],r))},{})});t.getTranslate=function(e){var t=A(e);return function(e,n){if("string"==typeof e)return(0,s.getLocalizedElement)(e,t,n);if(Array.isArray(e))return e.reduce(function(e,r){var a;return u({},e,(a={},a[r]=(0,s.getLocalizedElement)(r,t,n),a))},{});throw new Error("react-localize-redux: invalid key passed to translate.")}}},function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.localize=void 0;var a=n(1),o=(r(a),n(6)),u=n(0),c=function(e){return function(t){var n=e?t[e]:t;return{currentLanguage:(0,u.getActiveLanguage)(n).code,translate:(0,u.getTranslate)(n)}}};t.localize=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return(0,o.connect)(c(t),null)(e)}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.getIndexForLanguageCode=t.templater=t.hasHtmlTags=t.getLocalizedElement=void 0;var a=n(1),o=r(a),u=(t.getLocalizedElement=function(e,t,n){var r=t[e]||"Missing locaized: "+e,a=c(r,n);return u(a)?o.default.createElement("span",{dangerouslySetInnerHTML:{__html:a}}):o.default.createElement("span",null,a)},t.hasHtmlTags=function(e){var t=/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[\^'">\s]+))?)+\s*|\s*)\/?>/;return e.search(t)>=0}),c=t.templater=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(var n in t){var r="\\${\\s*"+n+"\\s*}",a=new RegExp(r,"gmi");e=e.replace(a,t[n])}return e};t.getIndexForLanguageCode=function(e,t){return t.map(function(e){return e.code}).indexOf(e)}},function(e,t,n){function r(e,t){function n(e,c,i){i=i?i:1,Object.keys(e).forEach(function(l){var s=e[l],f=t.safe&&Array.isArray(s),g=Object.prototype.toString.call(s),d=o(s),p="[object Object]"===g||"[object Array]"===g,v=c?c+r+l:l;return!f&&!d&&p&&Object.keys(s).length&&(!t.maxDepth||i<a)?n(s,v,i+1):void(u[v]=s)})}t=t||{};var r=t.delimiter||".",a=t.maxDepth,u={};return n(e),u}function a(e,t){function n(e){var t=Number(e);return isNaN(t)||e.indexOf(".")!==-1?e:t}t=t||{};var r=t.delimiter||".",u=t.overwrite||!1,c={},i=o(e);return i||"[object Object]"!==Object.prototype.toString.call(e)?e:(Object.keys(e).forEach(function(o){for(var i=o.split(r),l=n(i.shift()),s=n(i[0]),f=c;void 0!==s;){var g=Object.prototype.toString.call(f[l]),d="[object Object]"===g||"[object Array]"===g;if(!u&&!d&&"undefined"!=typeof f[l])return;(u&&!d||!u&&null==f[l])&&(f[l]="number"!=typeof s||t.object?{}:[]),f=f[l],i.length>0&&(l=n(i.shift()),s=n(i[0]))}f[l]=a(e[o],t)}),c)}var o=n(5);e.exports=r;r.flatten=r,r.unflatten=a},function(e,t){function n(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function r(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&n(e.slice(0,0))}/*!
* Determine if an object is a Buffer

@@ -3,0 +3,0 @@ *

@@ -141,5 +141,15 @@ 'use strict';

var translations = getTranslationsForActiveLanguage(state);
return function (key, data) {
return (0, _utils.getLocalizedElement)(key, translations, data);
return function (value, data) {
if (typeof value === 'string') {
return (0, _utils.getLocalizedElement)(value, translations, data);
} else if (Array.isArray(value)) {
return value.reduce(function (prev, cur) {
var _extends3;
return _extends({}, prev, (_extends3 = {}, _extends3[cur] = (0, _utils.getLocalizedElement)(cur, translations, data), _extends3));
}, {});
} else {
throw new Error('react-localize-redux: invalid key passed to translate.');
}
};
};

@@ -141,5 +141,15 @@ 'use strict';

var translations = getTranslationsForActiveLanguage(state);
return function (key, data) {
return (0, _utils.getLocalizedElement)(key, translations, data);
return function (value, data) {
if (typeof value === 'string') {
return (0, _utils.getLocalizedElement)(value, translations, data);
} else if (Array.isArray(value)) {
return value.reduce(function (prev, cur) {
var _extends3;
return _extends({}, prev, (_extends3 = {}, _extends3[cur] = (0, _utils.getLocalizedElement)(cur, translations, data), _extends3));
}, {});
} else {
throw new Error('react-localize-redux: invalid key passed to translate.');
}
};
};
{
"name": "react-localize-redux",
"version": "2.1.0",
"version": "2.2.0",
"description": "Dead simple localization for your React/Redux components",

@@ -5,0 +5,0 @@ "main": "lib/index",

@@ -134,3 +134,3 @@ # React Localize Redux

For components not already using `connect` instead use [localize](#localizecomponent). This will automatically connect your component with the `translate` function and `currentLanguage` prop.
For components not already using `connect` instead use [localize](#localizecomponent-slice). This will automatically connect your component with the `translate` function and `currentLanguage` prop.

@@ -208,2 +208,34 @@ ```javascript

### Pass multiple translations to child components
A parent component that has added the `translate` function by using [getTranslate](#gettranslatestate) or [localize](#localizecomponent-slice) can easily pass multiple translations down to it's child components. Just pass the `translate` function an array of translation keys instead of a single key.
```json
{
"heading": ["Heading", "Heading French"],
"article": {
"title": ["Title", "Title French"],
"author": ["By ${ name }", "By French ${ name }"],
"desc": ["Description", "Description French"]
}
}
```
```javascript
const Article = props => (
<div>
<h2>{ props['article.title'] }</h2>
<h3>{ props['article.author'] }</h3>
<p>{ props['article.desc'] }</p>
</div>
);
const Page = ({ translate }) => (
<div>
<h1>{ translate('heading') }</h1>
<Article { ...translate(['article.title', 'article.author', 'article.desc'], { name: 'Ted' }) } />
</div>
);
```
### Load translation data on demand

@@ -221,8 +253,8 @@

returns `(key, data) => LocalizedElement`
returns `(key | key[], data) => LocalizedElement | { [key: string]: LocalizedElement }`
* `key: string` = The key for the transaltion string e.g. 'greeting'
* `key: string|array` = A translation key or an array of translation keys.
* `data: object` = Pass data to your [dynamic translation](#add-dynamic-content-to-translations) string.
#### Usage:
#### Usage (single translation):

@@ -236,2 +268,6 @@ ```javascript

#### Usage (multiple translations):
See [Pass multiple translations to child components](#pass-multiple-translations-to-child-components).
### `getActiveLanguage(state)`

@@ -273,4 +309,29 @@

### `localize(Component, slice)`
### `getLanguages(state)`
A selector that takes your redux `state` and returns the languages you set.
returns `[{ code: 'en', active: true }, { code: 'fr', active: false }]`;
#### Usage:
```javascript
const LanguageSelector = ({ languages }) => (
<ul>
{ languages.map(language =>
<a href={ `/${ language.code }` }>{ language.code }</a>
)}
</ul>
)
const mapStateToProps = state => ({ languages: getLanguages(state) });
export default connect(mapStateToProps)(Greeting);
```
### `getTranslations(state)`
A selector that takes your redux `state` and returns the raw translation data.
### `localize(Component)`
If you have a Component that is not using `connect` you can wrap it with `localize` to automatically add the `translate` function and `currentLanguage` prop. When using `combineReducers` to add `localeReducer` you must pass the `slice` param to `localize`, where `slice` is the name of the prop you used with `combineReducers` (e.g. locale).

@@ -277,0 +338,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