UNPKG

react-gettext

Version:

Gettext implementation for React based project.

1 lines 7.71 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("PropTypes"),require("React"),require("hoistNonReactStatic")):"function"==typeof define&&define.amd?define(["PropTypes","React","hoistNonReactStatic"],e):"object"==typeof exports?exports.ReactGettext=e(require("PropTypes"),require("React"),require("hoistNonReactStatic")):t.ReactGettext=e(t.PropTypes,t.React,t.hoistNonReactStatic)}(window,(function(t,e,n){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(e,n){e.exports=t},function(t,n){t.exports=e},function(t,e){t.exports=n},function(t,e,n){"use strict";n.r(e),n.d(e,"Textdomain",(function(){return w})),n.d(e,"TextdomainContext",(function(){return D})),n.d(e,"buildTextdomain",(function(){return A}));var r=n(1),o=n.n(r),u=n(2),i=n.n(u),c=n(0),a=n.n(c);function f(t){return"function"==typeof t?t():t}function p(t,e){return Number.isNaN(parseInt(e,10))?0:"function"==typeof t?t(e):"string"!=typeof t||t.match(/[^n0-9 !=?:%+-/*><&|()]/i)?0:+Function("n","return ".concat(t))(e)}function l(t,e){var n=f(t);return Object.prototype.hasOwnProperty.call(n,e)?n[e]:e}function s(t,e,n,r,o){var u=f(t),i=p(e,o),c=o>1?r:n;return Object.prototype.hasOwnProperty.call(u,n)&&Array.isArray(u[n])&&u[n].length>i&&i>=0?u[n][i]:c}function y(t,e,n){var r=f(t),o=n+""+e;return Object.prototype.hasOwnProperty.call(r,o)?r[o]:e}function b(t,e,n,r,o,u){var i=f(t),c=p(e,o),a=o>1?r:n,l=u+""+n;return Object.prototype.hasOwnProperty.call(i,l)&&Array.isArray(i[l])&&i[l].length>c&&c>=0?i[l][c]:a}function d(t){return(d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function h(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function x(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function v(t,e){return(v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function g(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=O(t);if(e){var o=O(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return m(this,n)}}function m(t,e){return!e||"object"!==d(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function O(t){return(O=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var j=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&v(t,e)}(u,t);var e,n,r,o=g(u);function u(){return h(this,u),o.apply(this,arguments)}return e=u,(n=[{key:"getChildContext",value:function(){return{gettext:this.gettext.bind(this),xgettext:this.xgettext.bind(this),ngettext:this.ngettext.bind(this),nxgettext:this.nxgettext.bind(this)}}},{key:"gettext",value:function(t){return l(this.props.translations,t)}},{key:"ngettext",value:function(t,e,n){var r=this.props;return s(r.translations,r.plural,t,e,n)}},{key:"xgettext",value:function(t,e){return y(this.props.translations,t,e)}},{key:"nxgettext",value:function(t,e,n,r){var o=this.props;return b(o.translations,o.plural,t,e,n,r)}},{key:"render",value:function(){return this.props.children}}])&&x(e.prototype,n),r&&x(e,r),u}(r.Component);j.propTypes={translations:a.a.oneOfType([a.a.func,a.a.objectOf(a.a.oneOfType([a.a.string,a.a.arrayOf(a.a.string)]))]),plural:a.a.oneOfType([a.a.func,a.a.string]),children:a.a.oneOfType([a.a.node,a.a.arrayOf(a.a.node)])},j.defaultProps={translations:{},plural:"n != 1",children:[]},j.childContextTypes={gettext:a.a.func,ngettext:a.a.func,xgettext:a.a.func,nxgettext:a.a.func};var w=j;function P(t){return(P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function R(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function S(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function _(t,e,n){return e&&S(t.prototype,e),n&&S(t,n),t}function T(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&C(t,e)}function C(t,e){return(C=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function k(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=E(t);if(e){var o=E(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return N(this,n)}}function N(t,e){return!e||"object"!==P(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function E(t){return(E=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var q=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"n != 1",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(r){var u=Object.assign({withRef:!1},n),c=function(t){T(n,t);var e=k(n);function n(){return R(this,n),e.apply(this,arguments)}return _(n,[{key:"getWrappedComponent",value:function(){return this.refs.wrappedComponent}},{key:"render",value:function(){var t=Object.assign({},this.props);return u.withRef&&(t.ref="wrappedComponent"),o.a.createElement(r,t)}}]),n}(w);return c.defaultProps={translations:t,plural:e},c.displayName="withGettext(".concat(r.displayName||r.name||"Component",")"),i()(c,r)}};var A=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"n != 1";return{gettext:l.bind(null,t),ngettext:s.bind(null,t,e),xgettext:y.bind(null,t),nxgettext:b.bind(null,t,e)}},D=o.a.createContext(A({},"n != 1"));e.default=q}])}));