@lingui/react
Advanced tools
Comparing version 3.0.3 to 3.1.0
@@ -70,6 +70,14 @@ 'use strict'; | ||
var getRenderKey = function getRenderKey() { | ||
return forceRenderOnLocaleChange ? i18n.locale || 'default' : 'default'; | ||
}; | ||
var _React$useState = React__default['default'].useState(makeContext()), | ||
_React$useState2 = _slicedToArray__default['default'](_React$useState, 2), | ||
context = _React$useState2[0], | ||
setContext = _React$useState2[1]; | ||
setContext = _React$useState2[1], | ||
_React$useState3 = React__default['default'].useState(getRenderKey()), | ||
_React$useState4 = _slicedToArray__default['default'](_React$useState3, 2), | ||
renderKey = _React$useState4[0], | ||
setRenderKey = _React$useState4[1]; | ||
/** | ||
@@ -81,2 +89,7 @@ * Subscribe for locale/message changes | ||
* we need to trigger re-rendering of LinguiContext.Consumers. | ||
* | ||
* We call `setContext(makeContext())` after adding the observer in case the `change` | ||
* event would already have fired between the inital renderKey calculation and the | ||
* `useEffect` hook being called. This can happen if locales are loaded/activated | ||
* async. | ||
*/ | ||
@@ -87,4 +100,14 @@ | ||
var unsubscribe = i18n.on("change", function () { | ||
return setContext(makeContext()); | ||
setContext(makeContext()); | ||
setRenderKey(getRenderKey()); | ||
}); | ||
if (renderKey === 'default') { | ||
setRenderKey(getRenderKey()); | ||
} | ||
if (forceRenderOnLocaleChange && renderKey === 'default') { | ||
console.log("I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false."); | ||
} | ||
return function () { | ||
@@ -94,4 +117,3 @@ return unsubscribe(); | ||
}, []); | ||
var renderKey = forceRenderOnLocaleChange && i18n.locale; | ||
if (forceRenderOnLocaleChange && !renderKey) return null; | ||
if (forceRenderOnLocaleChange && renderKey === 'default') return null; | ||
return /*#__PURE__*/React__default['default'].createElement(LinguiContext.Provider, { | ||
@@ -98,0 +120,0 @@ value: context, |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),n=require("@babel/runtime/helpers/defineProperty");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(e),a=r(t),u=r(n),i=a.default.createContext(null);function l(){var e=a.default.useContext(i);return e}function c(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,i=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return u=e.done,e},e:function(e){i=!0,a=e},f:function(){try{u||null==n.return||n.return()}finally{if(i)throw a}}}}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var s=/<(\d+)>(.*?)<\/\1>|<(\d+)\/>/,p=/(?:\r\n|\r|\n)/g,d={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,menuitem:!0};function m(e){if(!e.length)return[];var t=e.slice(0,4),n=o.default(t,4),r=n[0],a=n[1],u=n[2],i=n[3];return[[parseInt(r||u),a||"",i]].concat(m(e.slice(4,e.length)))}var v=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return function(){return"".concat(t,"_").concat(e++)}};function y(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?y(Object(n),!0).forEach((function(t){u.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function h(e){var t=l(),n=t.i18n,r=t.defaultComponent,u=e.render,i=e.component,f=e.id,y=e.message,h=e.formats,g=b({},e.values),O=b({},e.components);g&&Object.keys(g).forEach((function(e){var t=g[e];if(a.default.isValidElement(t)){var n=Object.keys(O).length;O[n]=t,g[e]="<".concat(n,"/>")}}));var j=n&&"function"==typeof n._?n._(f,g,{message:y,formats:h}):f,w=j?function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=v(0,"$lingui$"),u=t.replace(p,"").split(s);if(1===u.length)return t;var i=[],l=u.shift();l&&i.push(l);var f,y=c(m(u));try{for(y.s();!(f=y.n()).done;){var b=o.default(f.value,3),h=b[0],g=b[1],O=b[2],j=n[h];(!j||d[j.type]&&g)&&(j?console.error("".concat(j.type," is a void element tag therefore it must have no children")):console.error("Can use element at index '".concat(h,"' as it is not declared in the original translation")),j=a.default.createElement(a.default.Fragment)),i.push(a.default.cloneElement(j,{key:r()},g?e(g,n):j.props.children)),O&&i.push(O)}}catch(e){y.e(e)}finally{y.f()}return i}(j,O):null;if(null===u||null===i)return w;var P=r||a.default.Fragment;if(u&&i)console.error("You can't use both `component` and `render` prop at the same time. `component` is ignored.");else if(u&&"function"!=typeof u)console.error("Invalid value supplied to prop `render`. It must be a function, provided ".concat(u));else if(i&&"function"!=typeof i)return console.error("Invalid value supplied to prop `component`. It must be a React component, provided ".concat(i)),a.default.createElement(P,null,w);if("function"==typeof u)return u({id:f,translation:w,message:y});var E=i||P;return a.default.createElement(E,null,w)}h.defaultProps={values:{},components:{}},exports.I18nProvider=function(e){var t=e.i18n,n=e.defaultComponent,r=e.forceRenderOnLocaleChange,u=void 0===r||r,l=e.children,c=function(){return{i18n:t,defaultComponent:n}},f=a.default.useState(c()),s=o.default(f,2),p=s[0],d=s[1];a.default.useEffect((function(){var e=t.on("change",(function(){return d(c())}));return function(){return e()}}),[]);var m=u&&t.locale;return u&&!m?null:a.default.createElement(i.Provider,{value:p,key:m},l)},exports.Trans=h,exports.useLingui=l,exports.withI18n=function(e){return function(e){return function(t){var n=l(),r=n.i18n;return a.default.createElement(e,Object.assign({},t,{i18n:r}))}}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),n=require("@babel/runtime/helpers/defineProperty");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(e),a=r(t),u=r(n),i=a.default.createContext(null);function l(){var e=a.default.useContext(i);return e}function c(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,i=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return u=e.done,e},e:function(e){i=!0,a=e},f:function(){try{u||null==n.return||n.return()}finally{if(i)throw a}}}}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var s=/<(\d+)>(.*?)<\/\1>|<(\d+)\/>/,d=/(?:\r\n|\r|\n)/g,p={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,menuitem:!0};function m(e){if(!e.length)return[];var t=e.slice(0,4),n=o.default(t,4),r=n[0],a=n[1],u=n[2],i=n[3];return[[parseInt(r||u),a||"",i]].concat(m(e.slice(4,e.length)))}var v=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return function(){return"".concat(t,"_").concat(e++)}};function y(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?y(Object(n),!0).forEach((function(t){u.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function h(e){var t=l(),n=t.i18n,r=t.defaultComponent,u=e.render,i=e.component,f=e.id,y=e.message,h=e.formats,g=b({},e.values),O=b({},e.components);g&&Object.keys(g).forEach((function(e){var t=g[e];if(a.default.isValidElement(t)){var n=Object.keys(O).length;O[n]=t,g[e]="<".concat(n,"/>")}}));var j=n&&"function"==typeof n._?n._(f,g,{message:y,formats:h}):f,P=j?function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=v(0,"$lingui$"),u=t.replace(d,"").split(s);if(1===u.length)return t;var i=[],l=u.shift();l&&i.push(l);var f,y=c(m(u));try{for(y.s();!(f=y.n()).done;){var b=o.default(f.value,3),h=b[0],g=b[1],O=b[2],j=n[h];(!j||p[j.type]&&g)&&(j?console.error("".concat(j.type," is a void element tag therefore it must have no children")):console.error("Can use element at index '".concat(h,"' as it is not declared in the original translation")),j=a.default.createElement(a.default.Fragment)),i.push(a.default.cloneElement(j,{key:r()},g?e(g,n):j.props.children)),O&&i.push(O)}}catch(e){y.e(e)}finally{y.f()}return i}(j,O):null;if(null===u||null===i)return P;var w=r||a.default.Fragment;if(u&&i)console.error("You can't use both `component` and `render` prop at the same time. `component` is ignored.");else if(u&&"function"!=typeof u)console.error("Invalid value supplied to prop `render`. It must be a function, provided ".concat(u));else if(i&&"function"!=typeof i)return console.error("Invalid value supplied to prop `component`. It must be a React component, provided ".concat(i)),a.default.createElement(w,null,P);if("function"==typeof u)return u({id:f,translation:P,message:y});var E=i||w;return a.default.createElement(E,null,P)}h.defaultProps={values:{},components:{}},exports.I18nProvider=function(e){var t=e.i18n,n=e.defaultComponent,r=e.forceRenderOnLocaleChange,u=void 0===r||r,l=e.children,c=function(){return{i18n:t,defaultComponent:n}},f=function(){return u&&t.locale||"default"},s=a.default.useState(c()),d=o.default(s,2),p=d[0],m=d[1],v=a.default.useState(f()),y=o.default(v,2),b=y[0],h=y[1];return a.default.useEffect((function(){var e=t.on("change",(function(){m(c()),h(f())}));return"default"===b&&h(f()),u&&"default"===b&&console.log("I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false."),function(){return e()}}),[]),u&&"default"===b?null:a.default.createElement(i.Provider,{value:p,key:b},l)},exports.Trans=h,exports.useLingui=l,exports.withI18n=function(e){return function(e){return function(t){var n=l(),r=n.i18n;return a.default.createElement(e,Object.assign({},t,{i18n:r}))}}}; | ||
//# sourceMappingURL=react.production.min.js.map |
{ | ||
"name": "@lingui/react", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "React components for translations", | ||
@@ -43,3 +43,3 @@ "main": "index.js", | ||
"@babel/runtime": "^7.11.2", | ||
"@lingui/core": "3.0.3" | ||
"@lingui/core": "3.1.0" | ||
}, | ||
@@ -46,0 +46,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27341
361
+ Added@lingui/core@3.1.0(transitive)
- Removed@lingui/core@3.0.3(transitive)
Updated@lingui/core@3.1.0