react-localize-redux
Advanced tools
Comparing version 2.8.0 to 2.9.0
@@ -155,7 +155,12 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
case ADD_TRANSLATION: | ||
return _extends({}, state, (0, _flat.flatten)(action.payload.translation, { safe: true })); | ||
// apply transformation if set in options | ||
var _translations = action.translationTransform !== undefined ? action.translationTransform(action.payload.translation, action.languageCodes) : action.payload.translation; | ||
return _extends({}, state, (0, _flat.flatten)(_translations, { safe: true })); | ||
case ADD_TRANSLATION_FOR_LANGUGE: | ||
var languageIndex = action.languageCodes.indexOf(action.payload.language); | ||
var flattenedTranslations = languageIndex >= 0 ? (0, _flat.flatten)(action.payload.translation) : {}; | ||
// convert single translation data into multiple | ||
var languageTranslations = Object.keys(flattenedTranslations).reduce(function (prev, cur) { | ||
// loop through each language, and for languages that don't match active language | ||
// keep existing translation data, and for active language store new translation data | ||
var translationValues = action.languageCodes.map(function (code, index) { | ||
@@ -180,3 +185,4 @@ var existingValues = state[cur] || []; | ||
case INITIALIZE: | ||
return _extends({}, state, action.payload.options); | ||
var _options2 = action.payload.options || {}; | ||
return _extends({}, state, (0, _utils.validateOptions)(_options2)); | ||
default: | ||
@@ -204,5 +210,6 @@ return state; | ||
}); | ||
var translationTransform = state.options.translationTransform; | ||
return { | ||
languages: languages(state.languages, action), | ||
translations: translations(state.translations, _extends({}, action, { languageCodes: languageCodes })), | ||
translations: translations(state.translations, _extends({}, action, { languageCodes: languageCodes, translationTransform: translationTransform })), | ||
options: options(state.options, action) | ||
@@ -464,3 +471,3 @@ }; | ||
}); | ||
exports.objectValuesToString = exports.getIndexForLanguageCode = exports.templater = exports.hasHtmlTags = exports.getLocalizedElement = undefined; | ||
exports.validateOptions = exports.objectValuesToString = exports.getIndexForLanguageCode = exports.templater = exports.hasHtmlTags = exports.getLocalizedElement = undefined; | ||
@@ -518,2 +525,9 @@ var _react = __webpack_require__(1); | ||
var validateOptions = exports.validateOptions = function validateOptions(options) { | ||
if (options.translationTransform !== undefined && typeof options.translationTransform !== 'function') { | ||
throw new Error('react-localize-redux: Invalid translationTransform function.'); | ||
} | ||
return options; | ||
}; | ||
/***/ }), | ||
@@ -520,0 +534,0 @@ /* 5 */ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-redux"),require("redux")):"function"==typeof define&&define.amd?define(["react","react-redux","redux"],t):"object"==typeof exports?exports.ReactLocalizeRedux=t(require("react"),require("react-redux"),require("redux")):e.ReactLocalizeRedux=t(e.React,e.ReactRedux,e.Redux)}(this,function(e,t,n){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=3)}([function(e,t,n){"use strict";function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1];switch(t.type){case f:case p:var n=t.payload.languageCodes,r=t.payload.options||{},a=t.payload.activeLanguage||r.defaultLanguage||n[0],o=n.indexOf(a);return n.map(function(e,t){return{code:e,active:t===o}});case v:return e.map(function(e){return e.code===t.payload.languageCode?i({},e,{active:!0}):i({},e,{active:!1})});default:return e}}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1];switch(t.type){case g:return i({},e,(0,c.flatten)(t.payload.translation,{safe:!0}));case d:var n=t.languageCodes.indexOf(t.payload.language),a=n>=0?(0,c.flatten)(t.payload.translation):{},o=Object.keys(a).reduce(function(o,u){var c=t.languageCodes.map(function(t,r){var o=e[u]||[];return r===n?a[u]:o[r]});return i({},o,r({},u,c))},{});return i({},e,o);default:return e}}function u(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:y,t=arguments[1];switch(t.type){case f:return i({},e,t.payload.options);default:return e}}Object.defineProperty(t,"__esModule",{value:!0}),t.getTranslate=t.getTranslationsForActiveLanguage=t.translationsEqualSelector=t.getActiveLanguage=t.getOptions=t.getLanguages=t.getTranslations=t.setActiveLanguage=t.setLanguages=t.addTranslationForLanguage=t.addTranslation=t.initialize=t.localeReducer=t.defaultTranslateOptions=t.TRANSLATE=t.SET_ACTIVE_LANGUAGE=t.SET_LANGUAGES=t.ADD_TRANSLATION_FOR_LANGUGE=t.ADD_TRANSLATION=t.INITIALIZE=void 0;var i=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=a,t.translations=o,t.options=u;var c=(n(9),n(5)),l=n(7),s=n(4),f=t.INITIALIZE="@@localize/INITIALIZE",g=t.ADD_TRANSLATION="@@localize/ADD_TRANSLATION",d=t.ADD_TRANSLATION_FOR_LANGUGE="@@localize/ADD_TRANSLATION_FOR_LANGUGE",p=t.SET_LANGUAGES="@@localize/SET_LANGUAGES",v=t.SET_ACTIVE_LANGUAGE="@@localize/SET_ACTIVE_LANGUAGE",y=(t.TRANSLATE="@@localize/TRANSLATE",t.defaultTranslateOptions={renderInnerHtml:!0}),b={languages:[],translations:{},options:y},A=(t.localeReducer=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b,t=arguments[1],n=e.languages.map(function(e){return e.code});return{languages:a(e.languages,t),translations:o(e.translations,i({},t,{languageCodes:n})),options:u(e.options,t)}},t.initialize=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:y;return{type:f,payload:{languageCodes:e,options:t}}},t.addTranslation=function(e){return{type:g,payload:{translation:e}}},t.addTranslationForLanguage=function(e,t){return{type:d,payload:{translation:e,language:t}}},t.setLanguages=function(e,t){return{type:p,payload:{languageCodes:e,activeLanguage:t}}},t.setActiveLanguage=function(e){return{type:v,payload:{languageCode:e}}},t.getTranslations=function(e){return e.translations}),O=t.getLanguages=function(e){return e.languages},T=t.getOptions=function(e){return e.options},L=t.getActiveLanguage=function(e){var t=O(e);return t[t.map(function(e){return e.active}).indexOf(!0)]},j=t.translationsEqualSelector=(0,l.createSelectorCreator)(l.defaultMemoize,function(e,t){if(!(Array.isArray(e)||"code,active"===Object.keys(e).toString())){var n=t,r=e,a=Object.keys(n).toString(),o=Object.keys(r).toString();return a+" - "+(0,s.objectValuesToString)(n)==o+" - "+(0,s.objectValuesToString)(r)}return t===e}),m=t.getTranslationsForActiveLanguage=j(L,O,A,function(e,t,n){var a=e.code,o=(0,s.getIndexForLanguageCode)(a,t);return Object.keys(n).reduce(function(e,t){return i({},e,r({},t,n[t][o]))},{})});t.getTranslate=(0,l.createSelector)(m,T,function(e,t){return function(n,a){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u=i({},t,o);if("string"==typeof n)return(0,s.getLocalizedElement)(n,e,a,u);if(Array.isArray(n))return n.reduce(function(t,n){return i({},t,r({},n,(0,s.getLocalizedElement)(n,e,a,u)))},{});throw new Error("react-localize-redux: Invalid key passed to getTranslate.")}})},function(t,n){t.exports=e},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.localize=void 0;var r=n(1),a=(function(e){e&&e.__esModule}(r),n(8)),o=n(0),u=function(e){return function(t){var n=e?t[e]:t;return{currentLanguage:(0,o.getActiveLanguage)(n).code,translate:(0,o.getTranslate)(n)}}};t.localize=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return(0,a.connect)(u(t))(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);Object.defineProperty(t,"localize",{enumerable:!0,get:function(){return r.localize}});var a=n(0);Object.defineProperty(t,"localeReducer",{enumerable:!0,get:function(){return a.localeReducer}}),Object.defineProperty(t,"initialize",{enumerable:!0,get:function(){return a.initialize}}),Object.defineProperty(t,"addTranslation",{enumerable:!0,get:function(){return a.addTranslation}}),Object.defineProperty(t,"addTranslationForLanguage",{enumerable:!0,get:function(){return a.addTranslationForLanguage}}),Object.defineProperty(t,"setLanguages",{enumerable:!0,get:function(){return a.setLanguages}}),Object.defineProperty(t,"setActiveLanguage",{enumerable:!0,get:function(){return a.setActiveLanguage}}),Object.defineProperty(t,"getTranslate",{enumerable:!0,get:function(){return a.getTranslate}}),Object.defineProperty(t,"getActiveLanguage",{enumerable:!0,get:function(){return a.getActiveLanguage}}),Object.defineProperty(t,"getLanguages",{enumerable:!0,get:function(){return a.getLanguages}}),Object.defineProperty(t,"getTranslations",{enumerable:!0,get:function(){return a.getTranslations}}),Object.defineProperty(t,"getOptions",{enumerable:!0,get:function(){return a.getOptions}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.objectValuesToString=t.getIndexForLanguageCode=t.templater=t.hasHtmlTags=t.getLocalizedElement=void 0;var r=n(1),a=function(e){return e&&e.__esModule?e:{default:e}}(r),o=n(0),u=(t.getLocalizedElement=function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:o.defaultTranslateOptions,c=t[e]||"Missing localized key: "+e,l=i(c,n);return r.renderInnerHtml&&u(l)?a.default.createElement("span",{dangerouslySetInnerHTML:{__html:l}}):l},t.hasHtmlTags=function(e){var t=/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[\^'">\s]+))?)+\s*|\s*)\/?>/;return e.search(t)>=0}),i=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)},t.objectValuesToString=function(e){return Object.values?Object.values(e).toString():Object.keys(e).map(function(t){return e[t].toString()}).toString()}},function(e,t,n){function r(e,t){function n(e,i,c){c=c||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=i?i+r+l:l;if(!f&&!d&&p&&Object.keys(s).length&&(!t.maxDepth||c<a))return n(s,v,c+1);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)||-1!==e.indexOf(".")?e:t}t=t||{};var r=t.delimiter||".",u=t.overwrite||!1,i={};return o(e)||"[object Object]"!==Object.prototype.toString.call(e)?e:(Object.keys(e).forEach(function(o){for(var c=o.split(r),l=n(c.shift()),s=n(c[0]),f=i;void 0!==s;){var g=Object.prototype.toString.call(f[l]),d="[object Object]"===g||"[object Array]"===g;if(!u&&!d&&void 0!==f[l])return;(u&&!d||!u&&null==f[l])&&(f[l]="number"!=typeof s||t.object?{}:[]),f=f[l],c.length>0&&(l=n(c.shift()),s=n(c[0]))}f[l]=a(e[o],t)}),i)}var o=n(6);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")):"function"==typeof define&&define.amd?define(["react","react-redux","redux"],t):"object"==typeof exports?exports.ReactLocalizeRedux=t(require("react"),require("react-redux"),require("redux")):e.ReactLocalizeRedux=t(e.React,e.ReactRedux,e.Redux)}(this,function(e,t,n){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=3)}([function(e,t,n){"use strict";function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments[1];switch(t.type){case f:case p:var n=t.payload.languageCodes,r=t.payload.options||{},a=t.payload.activeLanguage||r.defaultLanguage||n[0],o=n.indexOf(a);return n.map(function(e,t){return{code:e,active:t===o}});case v:return e.map(function(e){return e.code===t.payload.languageCode?i({},e,{active:!0}):i({},e,{active:!1})});default:return e}}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1];switch(t.type){case g:var n=void 0!==t.translationTransform?t.translationTransform(t.payload.translation,t.languageCodes):t.payload.translation;return i({},e,(0,c.flatten)(n,{safe:!0}));case d:var a=t.languageCodes.indexOf(t.payload.language),o=a>=0?(0,c.flatten)(t.payload.translation):{},u=Object.keys(o).reduce(function(n,u){var c=t.languageCodes.map(function(t,n){var r=e[u]||[];return n===a?o[u]:r[n]});return i({},n,r({},u,c))},{});return i({},e,u);default:return e}}function u(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:y,t=arguments[1];switch(t.type){case f:var n=t.payload.options||{};return i({},e,(0,s.validateOptions)(n));default:return e}}Object.defineProperty(t,"__esModule",{value:!0}),t.getTranslate=t.getTranslationsForActiveLanguage=t.translationsEqualSelector=t.getActiveLanguage=t.getOptions=t.getLanguages=t.getTranslations=t.setActiveLanguage=t.setLanguages=t.addTranslationForLanguage=t.addTranslation=t.initialize=t.localeReducer=t.defaultTranslateOptions=t.TRANSLATE=t.SET_ACTIVE_LANGUAGE=t.SET_LANGUAGES=t.ADD_TRANSLATION_FOR_LANGUGE=t.ADD_TRANSLATION=t.INITIALIZE=void 0;var i=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=a,t.translations=o,t.options=u;var c=(n(9),n(5)),l=n(7),s=n(4),f=t.INITIALIZE="@@localize/INITIALIZE",g=t.ADD_TRANSLATION="@@localize/ADD_TRANSLATION",d=t.ADD_TRANSLATION_FOR_LANGUGE="@@localize/ADD_TRANSLATION_FOR_LANGUGE",p=t.SET_LANGUAGES="@@localize/SET_LANGUAGES",v=t.SET_ACTIVE_LANGUAGE="@@localize/SET_ACTIVE_LANGUAGE",y=(t.TRANSLATE="@@localize/TRANSLATE",t.defaultTranslateOptions={renderInnerHtml:!0}),b={languages:[],translations:{},options:y},A=(t.localeReducer=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b,t=arguments[1],n=e.languages.map(function(e){return e.code}),r=e.options.translationTransform;return{languages:a(e.languages,t),translations:o(e.translations,i({},t,{languageCodes:n,translationTransform:r})),options:u(e.options,t)}},t.initialize=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:y;return{type:f,payload:{languageCodes:e,options:t}}},t.addTranslation=function(e){return{type:g,payload:{translation:e}}},t.addTranslationForLanguage=function(e,t){return{type:d,payload:{translation:e,language:t}}},t.setLanguages=function(e,t){return{type:p,payload:{languageCodes:e,activeLanguage:t}}},t.setActiveLanguage=function(e){return{type:v,payload:{languageCode:e}}},t.getTranslations=function(e){return e.translations}),T=t.getLanguages=function(e){return e.languages},O=t.getOptions=function(e){return e.options},L=t.getActiveLanguage=function(e){var t=T(e);return t[t.map(function(e){return e.active}).indexOf(!0)]},m=t.translationsEqualSelector=(0,l.createSelectorCreator)(l.defaultMemoize,function(e,t){if(!(Array.isArray(e)||"code,active"===Object.keys(e).toString())){var n=t,r=e,a=Object.keys(n).toString(),o=Object.keys(r).toString();return a+" - "+(0,s.objectValuesToString)(n)==o+" - "+(0,s.objectValuesToString)(r)}return t===e}),j=t.getTranslationsForActiveLanguage=m(L,T,A,function(e,t,n){var a=e.code,o=(0,s.getIndexForLanguageCode)(a,t);return Object.keys(n).reduce(function(e,t){return i({},e,r({},t,n[t][o]))},{})});t.getTranslate=(0,l.createSelector)(j,O,function(e,t){return function(n,a){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u=i({},t,o);if("string"==typeof n)return(0,s.getLocalizedElement)(n,e,a,u);if(Array.isArray(n))return n.reduce(function(t,n){return i({},t,r({},n,(0,s.getLocalizedElement)(n,e,a,u)))},{});throw new Error("react-localize-redux: Invalid key passed to getTranslate.")}})},function(t,n){t.exports=e},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.localize=void 0;var r=n(1),a=(function(e){e&&e.__esModule}(r),n(8)),o=n(0),u=function(e){return function(t){var n=e?t[e]:t;return{currentLanguage:(0,o.getActiveLanguage)(n).code,translate:(0,o.getTranslate)(n)}}};t.localize=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return(0,a.connect)(u(t))(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2);Object.defineProperty(t,"localize",{enumerable:!0,get:function(){return r.localize}});var a=n(0);Object.defineProperty(t,"localeReducer",{enumerable:!0,get:function(){return a.localeReducer}}),Object.defineProperty(t,"initialize",{enumerable:!0,get:function(){return a.initialize}}),Object.defineProperty(t,"addTranslation",{enumerable:!0,get:function(){return a.addTranslation}}),Object.defineProperty(t,"addTranslationForLanguage",{enumerable:!0,get:function(){return a.addTranslationForLanguage}}),Object.defineProperty(t,"setLanguages",{enumerable:!0,get:function(){return a.setLanguages}}),Object.defineProperty(t,"setActiveLanguage",{enumerable:!0,get:function(){return a.setActiveLanguage}}),Object.defineProperty(t,"getTranslate",{enumerable:!0,get:function(){return a.getTranslate}}),Object.defineProperty(t,"getActiveLanguage",{enumerable:!0,get:function(){return a.getActiveLanguage}}),Object.defineProperty(t,"getLanguages",{enumerable:!0,get:function(){return a.getLanguages}}),Object.defineProperty(t,"getTranslations",{enumerable:!0,get:function(){return a.getTranslations}}),Object.defineProperty(t,"getOptions",{enumerable:!0,get:function(){return a.getOptions}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.validateOptions=t.objectValuesToString=t.getIndexForLanguageCode=t.templater=t.hasHtmlTags=t.getLocalizedElement=void 0;var r=n(1),a=function(e){return e&&e.__esModule?e:{default:e}}(r),o=n(0),u=(t.getLocalizedElement=function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:o.defaultTranslateOptions,c=t[e]||"Missing localized key: "+e,l=i(c,n);return r.renderInnerHtml&&u(l)?a.default.createElement("span",{dangerouslySetInnerHTML:{__html:l}}):l},t.hasHtmlTags=function(e){var t=/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[\^'">\s]+))?)+\s*|\s*)\/?>/;return e.search(t)>=0}),i=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)},t.objectValuesToString=function(e){return Object.values?Object.values(e).toString():Object.keys(e).map(function(t){return e[t].toString()}).toString()},t.validateOptions=function(e){if(void 0!==e.translationTransform&&"function"!=typeof e.translationTransform)throw new Error("react-localize-redux: Invalid translationTransform function.");return e}},function(e,t,n){function r(e,t){function n(e,i,c){c=c||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=i?i+r+l:l;if(!f&&!d&&p&&Object.keys(s).length&&(!t.maxDepth||c<a))return n(s,v,c+1);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)||-1!==e.indexOf(".")?e:t}t=t||{};var r=t.delimiter||".",u=t.overwrite||!1,i={};return o(e)||"[object Object]"!==Object.prototype.toString.call(e)?e:(Object.keys(e).forEach(function(o){for(var c=o.split(r),l=n(c.shift()),s=n(c[0]),f=i;void 0!==s;){var g=Object.prototype.toString.call(f[l]),d="[object Object]"===g||"[object Array]"===g;if(!u&&!d&&void 0!==f[l])return;(u&&!d||!u&&null==f[l])&&(f[l]="number"!=typeof s||t.object?{}:[]),f=f[l],c.length>0&&(l=n(c.shift()),s=n(c[0]))}f[l]=a(e[o],t)}),i)}var o=n(6);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 @@ * |
@@ -8,3 +8,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; }; | ||
import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect'; | ||
import { getLocalizedElement, getIndexForLanguageCode, objectValuesToString } from '../utils'; | ||
import { getLocalizedElement, getIndexForLanguageCode, objectValuesToString, validateOptions } from '../utils'; | ||
@@ -59,7 +59,12 @@ /** | ||
case ADD_TRANSLATION: | ||
return _extends({}, state, flatten(action.payload.translation, { safe: true })); | ||
// apply transformation if set in options | ||
var _translations = action.translationTransform !== undefined ? action.translationTransform(action.payload.translation, action.languageCodes) : action.payload.translation; | ||
return _extends({}, state, flatten(_translations, { safe: true })); | ||
case ADD_TRANSLATION_FOR_LANGUGE: | ||
var languageIndex = action.languageCodes.indexOf(action.payload.language); | ||
var flattenedTranslations = languageIndex >= 0 ? flatten(action.payload.translation) : {}; | ||
// convert single translation data into multiple | ||
var languageTranslations = Object.keys(flattenedTranslations).reduce(function (prev, cur) { | ||
// loop through each language, and for languages that don't match active language | ||
// keep existing translation data, and for active language store new translation data | ||
var translationValues = action.languageCodes.map(function (code, index) { | ||
@@ -84,3 +89,4 @@ var existingValues = state[cur] || []; | ||
case INITIALIZE: | ||
return _extends({}, state, action.payload.options); | ||
var _options2 = action.payload.options || {}; | ||
return _extends({}, state, validateOptions(_options2)); | ||
default: | ||
@@ -108,5 +114,6 @@ return state; | ||
}); | ||
var translationTransform = state.options.translationTransform; | ||
return { | ||
languages: languages(state.languages, action), | ||
translations: translations(state.translations, _extends({}, action, { languageCodes: languageCodes })), | ||
translations: translations(state.translations, _extends({}, action, { languageCodes: languageCodes, translationTransform: translationTransform })), | ||
options: options(state.options, action) | ||
@@ -113,0 +120,0 @@ }; |
@@ -46,2 +46,9 @@ import React from 'react'; | ||
}).toString() : Object.values(data).toString(); | ||
}; | ||
export var validateOptions = function validateOptions(options) { | ||
if (options.translationTransform !== undefined && typeof options.translationTransform !== 'function') { | ||
throw new Error('react-localize-redux: Invalid translationTransform function.'); | ||
} | ||
return options; | ||
}; |
@@ -72,7 +72,12 @@ 'use strict'; | ||
case ADD_TRANSLATION: | ||
return _extends({}, state, (0, _flat.flatten)(action.payload.translation, { safe: true })); | ||
// apply transformation if set in options | ||
var _translations = action.translationTransform !== undefined ? action.translationTransform(action.payload.translation, action.languageCodes) : action.payload.translation; | ||
return _extends({}, state, (0, _flat.flatten)(_translations, { safe: true })); | ||
case ADD_TRANSLATION_FOR_LANGUGE: | ||
var languageIndex = action.languageCodes.indexOf(action.payload.language); | ||
var flattenedTranslations = languageIndex >= 0 ? (0, _flat.flatten)(action.payload.translation) : {}; | ||
// convert single translation data into multiple | ||
var languageTranslations = Object.keys(flattenedTranslations).reduce(function (prev, cur) { | ||
// loop through each language, and for languages that don't match active language | ||
// keep existing translation data, and for active language store new translation data | ||
var translationValues = action.languageCodes.map(function (code, index) { | ||
@@ -97,3 +102,4 @@ var existingValues = state[cur] || []; | ||
case INITIALIZE: | ||
return _extends({}, state, action.payload.options); | ||
var _options2 = action.payload.options || {}; | ||
return _extends({}, state, (0, _utils.validateOptions)(_options2)); | ||
default: | ||
@@ -121,5 +127,6 @@ return state; | ||
}); | ||
var translationTransform = state.options.translationTransform; | ||
return { | ||
languages: languages(state.languages, action), | ||
translations: translations(state.translations, _extends({}, action, { languageCodes: languageCodes })), | ||
translations: translations(state.translations, _extends({}, action, { languageCodes: languageCodes, translationTransform: translationTransform })), | ||
options: options(state.options, action) | ||
@@ -126,0 +133,0 @@ }; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.objectValuesToString = exports.getIndexForLanguageCode = exports.templater = exports.hasHtmlTags = exports.getLocalizedElement = undefined; | ||
exports.validateOptions = exports.objectValuesToString = exports.getIndexForLanguageCode = exports.templater = exports.hasHtmlTags = exports.getLocalizedElement = undefined; | ||
@@ -58,2 +58,9 @@ var _react = require('react'); | ||
}).toString() : Object.values(data).toString(); | ||
}; | ||
var validateOptions = exports.validateOptions = function validateOptions(options) { | ||
if (options.translationTransform !== undefined && typeof options.translationTransform !== 'function') { | ||
throw new Error('react-localize-redux: Invalid translationTransform function.'); | ||
} | ||
return options; | ||
}; |
{ | ||
"name": "react-localize-redux", | ||
"version": "2.8.0", | ||
"version": "2.9.0", | ||
"description": "Localization library for React/Redux", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105546
1488