@transifex/native 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.native.js +1 -1
- package/dist/node.native.js +1 -1
- package/package.json +1 -2
package/dist/browser.native.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
|
-
e.exports=function(e){return null!=e&&(r(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&r(e.slice(0,0))}(e)||!!e._isBuffer)}},function(e,t,r){"use strict";r.r(t),r.d(t,"generateKey",(function(){return F})),r.d(t,"generateHashedKey",(function(){return O})),r.d(t,"escape",(function(){return A})),r.d(t,"isString",(function(){return T})),r.d(t,"normalizeLocale",(function(){return N})),r.d(t,"isPluralized",(function(){return B})),r.d(t,"FETCHING_TRANSLATIONS",(function(){return P})),r.d(t,"TRANSLATIONS_FETCHED",(function(){return C})),r.d(t,"TRANSLATIONS_FETCH_FAILED",(function(){return D})),r.d(t,"LOCALE_CHANGED",(function(){return R})),r.d(t,"FETCHING_LOCALES",(function(){return z})),r.d(t,"LOCALES_FETCHED",(function(){return I})),r.d(t,"LOCALES_FETCH_FAILED",(function(){return q})),r.d(t,"onEvent",(function(){return U})),r.d(t,"offEvent",(function(){return H})),r.d(t,"sendEvent",(function(){return J})),r.d(t,"PseudoTranslationPolicy",(function(){return $})),r.d(t,"SourceStringPolicy",(function(){return Z})),r.d(t,"SourceErrorPolicy",(function(){return K})),r.d(t,"ThrowErrorPolicy",(function(){return V})),r.d(t,"MessageFormatRenderer",(function(){return X})),r.d(t,"tx",(function(){return Y})),r.d(t,"t",(function(){return Q}));var n=r(8),i=r.n(n),o=r(5),a=r.n(o),u=r(0),s=r.n(u),c=r(1),l=r.n(c),f=r(3),h=r.n(f),p=r(9),d=r.n(p),m=function(){function e(){s()(this,e),this.translationsByLocale={}}return l()(e,[{key:"update",value:function(e,t){this.translationsByLocale[e]=t}},{key:"getTranslations",value:function(e){return this.translationsByLocale[e]||{}}},{key:"hasTranslations",value:function(e){return!!this.translationsByLocale[e]}},{key:"isStale",value:function(e){return!this.hasTranslations(e)}},{key:"get",value:function(e,t){return this.getTranslations(t)[e]||""}}]),e}(),g=function(){function e(){s()(this,e)}return l()(e,[{key:"handle",value:function(e,t,r,n){return t}}]),e}(),y=function(){function e(){s()(this,e)}return l()(e,[{key:"handle",value:function(e,t){return e}}]),e}(),v=r(21),w=new(r.n(v).a),b=function(){function e(){s()(this,e)}return l()(e,[{key:"render",value:function(e,t,r){return w.compile(e)(r)}}]),e}(),x=r(4),k=r.n(x),S=r(22),E=r.n(S);function F(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t._key?t._key:t._context?"".concat(e,"::").concat(t._context):"".concat(e)}function O(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t._key)return t._key;var r="";return t._context&&(r=(r=t._context).replace(/,/g,":")),E()("5:".concat(e,":").concat(r))}function A(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function T(e){return"[object String]"===Object.prototype.toString.call(e)}function N(e){var t=e.split("-");return 1===t.length?e:[t[0],t[1].toUpperCase()].join("_")}var j=["zero","one","two","few","many","other"];function _(e){var t=e.indexOf("{");if(-1===t)return[null,null];var r=e.substring(0,t).trim();if("="===r[0]){if(r=r.substring(1),Number.isNaN(parseInt(r,10))||parseInt(r,10)!==parseFloat(r))return[null,null];if(r=parseInt(r,10),void 0===(r=j[r]))return[null,null]}else if(-1===j.indexOf(r))return[null,null];return[r,e.substring(t)]}function L(e){for(var t=0,r=!1,n=0;n<e.length;){var i=e[n];if("'"===i){var o=e[n+1];"'"===o?n+=1:r?r=!1:"{"!==o&&"}"!==o||(r=!0)}else if("{"===i)r||(t+=1);else if("}"===i&&(r||(t-=1),0===t))return[e.substring(1,n),e.substring(n+1).trim()];n+=1}return[null,null]}function B(e){var t=function(e){if(!(e.length>1&&"{"===e[0]&&"}"===e[e.length-1]))return[null,null];var t=e.indexOf(",");if(-1===t)return[null,null];var r=e.indexOf(",",t+1);if(-1===r)return[null,null];var n=e.substring(1,t).trim();return"plural"!==e.substring(t+1,r).trim()?[null,null]:[n,e.substring(r+1,e.length-1).trim()]}(e),r=k()(t,2),n=r[0],i=r[1];if(null==n)return!1;var o,a,u={},s=_(i),c=k()(s,2);if(o=c[0],i=c[1],null==o)return!1;var l=L(i.trim()),f=k()(l,2);if(a=f[0],i=f[1],null==a)return!1;for(u[o]=a;i.trim();){var h=_(i.trim()),p=k()(h,2);if(o=p[0],i=p[1],null==o)return!1;var d=L(i.trim()),m=k()(d,2);if(a=m[0],i=m[1],null==a)return!1;u[o]=a}return(1!==Object.keys(u).length||"other"in u)&&"one"in u&&"other"in u}var P="FETCHING_TRANSLATIONS",C="TRANSLATIONS_FETCHED",D="TRANSLATIONS_FETCH_FAILED",R="LOCALE_CHANGED",z="FETCHING_LOCALES",I="LOCALES_FETCHED",q="LOCALES_FETCH_FAILED",M={};function U(e,t){M[e]=M[e]||[],M[e].push(t)}function H(e,t){var r=M[e]||[],n=r.indexOf(t);-1!==n&&r.splice(n,1)}function J(e,t,r){(M[e]||[]).forEach((function(e){e(t,r)}))}var G=function(){function e(){s()(this,e),this.cdsHost="https://cds.svc.transifex.net",this.token="",this.secret="",this.filterTags="",this.cache=new m,this.missingPolicy=new y,this.errorPolicy=new g,this.stringRenderer=new b,this.currentLocale="",this.locales=[],this.languages=[]}var t,r,n,o;return l()(e,[{key:"init",value:function(e){var t=this;["cdsHost","token","secret","cache","filterTags","missingPolicy","errorPolicy","stringRenderer","currentLocale"].forEach((function(r){void 0!==e[r]&&(t[r]=e[r])}))}},{key:"translate",value:function(e,t){return this.translateLocale(this.currentLocale,e,t)}},{key:"translateLocale",value:function(e,t,r){try{var n=this.cache.get(F(t,r),e);if(n||(n=this.cache.get(O(t,r),e)),n&&n.startsWith("{???")&&B(t)){var i=t.substring(1,t.indexOf(",")).trim();n="{".concat(i).concat(n.substring(4))}var o=!1;if(n||(o=!0,n=t),r&&r._escapeVars){var a={};Object.keys(r).forEach((function(e){var t=r[e];a[e]=T(t)?A(t):t})),n=this.stringRenderer.render(n,e,a)}else n=this.stringRenderer.render(n,e,r);return o&&e&&(n=this.missingPolicy.handle(n,e)),T(n)||(n="".concat(n)),n}catch(n){return this.errorPolicy.handle(n,"".concat(t),e,r)}}},{key:"fetchTranslations",value:(o=a()(h.a.mark((function e(t){var r,n,i,o,a,u=arguments;return h.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((u.length>1&&void 0!==u[1]?u[1]:{}).refresh||!this.cache.hasTranslations(t)||this.cache.isStale(t)){e.next=3;break}return e.abrupt("return");case 3:e.prev=3,J(P,t,this),n=202;case 6:if(202!==n){e.next=15;break}return i="".concat(this.cdsHost,"/content/").concat(t),this.filterTags&&(i="".concat(i,"?filter[tags]=").concat(this.filterTags)),e.next=11,d.a.get(i,{headers:{Authorization:"Bearer ".concat(this.token),"Accept-version":"v2","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("2.0.
|
|
8
|
+
e.exports=function(e){return null!=e&&(r(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&r(e.slice(0,0))}(e)||!!e._isBuffer)}},function(e,t,r){"use strict";r.r(t),r.d(t,"generateKey",(function(){return F})),r.d(t,"generateHashedKey",(function(){return O})),r.d(t,"escape",(function(){return A})),r.d(t,"isString",(function(){return T})),r.d(t,"normalizeLocale",(function(){return N})),r.d(t,"isPluralized",(function(){return B})),r.d(t,"FETCHING_TRANSLATIONS",(function(){return P})),r.d(t,"TRANSLATIONS_FETCHED",(function(){return C})),r.d(t,"TRANSLATIONS_FETCH_FAILED",(function(){return D})),r.d(t,"LOCALE_CHANGED",(function(){return R})),r.d(t,"FETCHING_LOCALES",(function(){return z})),r.d(t,"LOCALES_FETCHED",(function(){return I})),r.d(t,"LOCALES_FETCH_FAILED",(function(){return q})),r.d(t,"onEvent",(function(){return U})),r.d(t,"offEvent",(function(){return H})),r.d(t,"sendEvent",(function(){return J})),r.d(t,"PseudoTranslationPolicy",(function(){return $})),r.d(t,"SourceStringPolicy",(function(){return Z})),r.d(t,"SourceErrorPolicy",(function(){return K})),r.d(t,"ThrowErrorPolicy",(function(){return V})),r.d(t,"MessageFormatRenderer",(function(){return X})),r.d(t,"tx",(function(){return Y})),r.d(t,"t",(function(){return Q}));var n=r(8),i=r.n(n),o=r(5),a=r.n(o),u=r(0),s=r.n(u),c=r(1),l=r.n(c),f=r(3),h=r.n(f),p=r(9),d=r.n(p),m=function(){function e(){s()(this,e),this.translationsByLocale={}}return l()(e,[{key:"update",value:function(e,t){this.translationsByLocale[e]=t}},{key:"getTranslations",value:function(e){return this.translationsByLocale[e]||{}}},{key:"hasTranslations",value:function(e){return!!this.translationsByLocale[e]}},{key:"isStale",value:function(e){return!this.hasTranslations(e)}},{key:"get",value:function(e,t){return this.getTranslations(t)[e]||""}}]),e}(),g=function(){function e(){s()(this,e)}return l()(e,[{key:"handle",value:function(e,t,r,n){return t}}]),e}(),y=function(){function e(){s()(this,e)}return l()(e,[{key:"handle",value:function(e,t){return e}}]),e}(),v=r(21),w=new(r.n(v).a),b=function(){function e(){s()(this,e)}return l()(e,[{key:"render",value:function(e,t,r){return w.compile(e)(r)}}]),e}(),x=r(4),k=r.n(x),S=r(22),E=r.n(S);function F(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t._key?t._key:t._context?"".concat(e,"::").concat(t._context):"".concat(e)}function O(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t._key)return t._key;var r="";return t._context&&(r=(r=t._context).replace(/,/g,":")),E()("5:".concat(e,":").concat(r))}function A(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function T(e){return"[object String]"===Object.prototype.toString.call(e)}function N(e){var t=e.split("-");return 1===t.length?e:[t[0],t[1].toUpperCase()].join("_")}var j=["zero","one","two","few","many","other"];function _(e){var t=e.indexOf("{");if(-1===t)return[null,null];var r=e.substring(0,t).trim();if("="===r[0]){if(r=r.substring(1),Number.isNaN(parseInt(r,10))||parseInt(r,10)!==parseFloat(r))return[null,null];if(r=parseInt(r,10),void 0===(r=j[r]))return[null,null]}else if(-1===j.indexOf(r))return[null,null];return[r,e.substring(t)]}function L(e){for(var t=0,r=!1,n=0;n<e.length;){var i=e[n];if("'"===i){var o=e[n+1];"'"===o?n+=1:r?r=!1:"{"!==o&&"}"!==o||(r=!0)}else if("{"===i)r||(t+=1);else if("}"===i&&(r||(t-=1),0===t))return[e.substring(1,n),e.substring(n+1).trim()];n+=1}return[null,null]}function B(e){var t=function(e){if(!(e.length>1&&"{"===e[0]&&"}"===e[e.length-1]))return[null,null];var t=e.indexOf(",");if(-1===t)return[null,null];var r=e.indexOf(",",t+1);if(-1===r)return[null,null];var n=e.substring(1,t).trim();return"plural"!==e.substring(t+1,r).trim()?[null,null]:[n,e.substring(r+1,e.length-1).trim()]}(e),r=k()(t,2),n=r[0],i=r[1];if(null==n)return!1;var o,a,u={},s=_(i),c=k()(s,2);if(o=c[0],i=c[1],null==o)return!1;var l=L(i.trim()),f=k()(l,2);if(a=f[0],i=f[1],null==a)return!1;for(u[o]=a;i.trim();){var h=_(i.trim()),p=k()(h,2);if(o=p[0],i=p[1],null==o)return!1;var d=L(i.trim()),m=k()(d,2);if(a=m[0],i=m[1],null==a)return!1;u[o]=a}return(1!==Object.keys(u).length||"other"in u)&&"one"in u&&"other"in u}var P="FETCHING_TRANSLATIONS",C="TRANSLATIONS_FETCHED",D="TRANSLATIONS_FETCH_FAILED",R="LOCALE_CHANGED",z="FETCHING_LOCALES",I="LOCALES_FETCHED",q="LOCALES_FETCH_FAILED",M={};function U(e,t){M[e]=M[e]||[],M[e].push(t)}function H(e,t){var r=M[e]||[],n=r.indexOf(t);-1!==n&&r.splice(n,1)}function J(e,t,r){(M[e]||[]).forEach((function(e){e(t,r)}))}var G=function(){function e(){s()(this,e),this.cdsHost="https://cds.svc.transifex.net",this.token="",this.secret="",this.filterTags="",this.cache=new m,this.missingPolicy=new y,this.errorPolicy=new g,this.stringRenderer=new b,this.currentLocale="",this.locales=[],this.languages=[]}var t,r,n,o;return l()(e,[{key:"init",value:function(e){var t=this;["cdsHost","token","secret","cache","filterTags","missingPolicy","errorPolicy","stringRenderer","currentLocale"].forEach((function(r){void 0!==e[r]&&(t[r]=e[r])}))}},{key:"translate",value:function(e,t){return this.translateLocale(this.currentLocale,e,t)}},{key:"translateLocale",value:function(e,t,r){try{var n=this.cache.get(F(t,r),e);if(n||(n=this.cache.get(O(t,r),e)),n&&n.startsWith("{???")&&B(t)){var i=t.substring(1,t.indexOf(",")).trim();n="{".concat(i).concat(n.substring(4))}var o=!1;if(n||(o=!0,n=t),r&&r._escapeVars){var a={};Object.keys(r).forEach((function(e){var t=r[e];a[e]=T(t)?A(t):t})),n=this.stringRenderer.render(n,e,a)}else n=this.stringRenderer.render(n,e,r);return o&&e&&(n=this.missingPolicy.handle(n,e)),T(n)||(n="".concat(n)),n}catch(n){return this.errorPolicy.handle(n,"".concat(t),e,r)}}},{key:"fetchTranslations",value:(o=a()(h.a.mark((function e(t){var r,n,i,o,a,u=arguments;return h.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((u.length>1&&void 0!==u[1]?u[1]:{}).refresh||!this.cache.hasTranslations(t)||this.cache.isStale(t)){e.next=3;break}return e.abrupt("return");case 3:e.prev=3,J(P,t,this),n=202;case 6:if(202!==n){e.next=15;break}return i="".concat(this.cdsHost,"/content/").concat(t),this.filterTags&&(i="".concat(i,"?filter[tags]=").concat(this.filterTags)),e.next=11,d.a.get(i,{headers:{Authorization:"Bearer ".concat(this.token),"Accept-version":"v2","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("2.0.1")}});case 11:r=e.sent,n=r.status,e.next=6;break;case 15:if(!(o=r.data)||!o.data){e.next=23;break}a={},Object.keys(o.data).forEach((function(e){o.data[e].string&&(a[e]=o.data[e].string)})),this.cache.update(t,a),J(C,t,this),e.next=25;break;case 23:throw J(D,t,this),new Error("Could not fetch translations");case 25:e.next=31;break;case 27:throw e.prev=27,e.t0=e.catch(3),J(D,t,this),e.t0;case 31:case"end":return e.stop()}}),e,this,[[3,27]])}))),function(e){return o.apply(this,arguments)})},{key:"getLocales",value:(n=a()(h.a.mark((function e(){var t,r,n,o=arguments;return h.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((o.length>0&&void 0!==o[0]?o[0]:{}).refresh||!(this.locales.length>0)){e.next=4;break}return e.abrupt("return",i()(this.locales));case 4:if(this.token){e.next=6;break}return e.abrupt("return",[]);case 6:e.prev=6,J(z,null,this),r=202;case 9:if(202!==r){e.next=16;break}return e.next=12,d.a.get("".concat(this.cdsHost,"/languages"),{headers:{Authorization:"Bearer ".concat(this.token),"Accept-version":"v2","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("2.0.1")}});case 12:t=e.sent,r=t.status,e.next=9;break;case 16:if(!(n=t.data)||!n.data){e.next=23;break}this.languages=n.data,this.locales=this.languages.map((function(e){return e.code})),J(I,null,this),e.next=25;break;case 23:throw J(q,null,this),new Error("Could not fetch languages");case 25:e.next=31;break;case 27:throw e.prev=27,e.t0=e.catch(6),J(q,null,this),e.t0;case 31:return e.abrupt("return",i()(this.locales));case 32:case"end":return e.stop()}}),e,this,[[6,27]])}))),function(){return n.apply(this,arguments)})},{key:"getCurrentLocale",value:function(){return this.currentLocale}},{key:"isCurrent",value:function(e){return e===this.currentLocale}},{key:"setCurrentLocale",value:(r=a()(h.a.mark((function e(t){return h.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isCurrent(t)){e.next=2;break}return e.abrupt("return");case 2:if(t){e.next=6;break}return this.currentLocale="",J(R,this.currentLocale,this),e.abrupt("return");case 6:return e.next=8,this.fetchTranslations(t);case 8:this.currentLocale=t,J(R,t,this);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getLanguages",value:(t=a()(h.a.mark((function e(){var t,r=arguments;return h.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:{},e.next=3,this.getLocales(t);case 3:return e.abrupt("return",i()(this.languages));case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),W={a:"ȧ",A:"Ȧ",b:"ƀ",B:"Ɓ",c:"ƈ",C:"Ƈ",d:"ḓ",D:"Ḓ",e:"ḗ",E:"Ḗ",f:"ƒ",F:"Ƒ",g:"ɠ",G:"Ɠ",h:"ħ",H:"Ħ",i:"ī",I:"Ī",j:"ĵ",J:"Ĵ",k:"ķ",K:"Ķ",l:"ŀ",L:"Ŀ",m:"ḿ",M:"Ḿ",n:"ƞ",N:"Ƞ",o:"ǿ",O:"Ǿ",p:"ƥ",P:"Ƥ",q:"ɋ",Q:"Ɋ",r:"ř",R:"Ř",s:"ş",S:"Ş",t:"ŧ",T:"Ŧ",v:"ṽ",V:"Ṽ",u:"ŭ",U:"Ŭ",w:"ẇ",W:"Ẇ",x:"ẋ",X:"Ẋ",y:"ẏ",Y:"Ẏ",z:"ẑ",Z:"Ẑ"},$=function(){function e(){s()(this,e)}return l()(e,[{key:"handle",value:function(e,t){return e.split(/__txnative__/).map((function(e){for(var t="",r=0;r<e.length;r+=1){var n=e.charAt(r);if(W[n]){var i=n.toLowerCase();t+="a"===i||"e"===i||"o"===i||"u"===i?W[n]+W[n]:W[n]}else t+=n}return t})).join("__txnative__")}}]),e}(),Z=y,K=g,V=function(){function e(){s()(this,e)}return l()(e,[{key:"handle",value:function(e,t,r,n){throw e||new Error('Error translating "'.concat(t,'"'))}}]),e}(),X=b,Y=new G,Q=Y.translate.bind(Y)}])}));
|
|
9
9
|
//# sourceMappingURL=browser.native.js.map
|
package/dist/node.native.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
|
-
t.exports=function(t){return null!=t&&(e(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&e(t.slice(0,0))}(t)||!!t._isBuffer)}},function(t,n,e){"use strict";e.r(n),e.d(n,"generateKey",(function(){return h})),e.d(n,"generateHashedKey",(function(){return p})),e.d(n,"escape",(function(){return m})),e.d(n,"isString",(function(){return g})),e.d(n,"normalizeLocale",(function(){return y})),e.d(n,"isPluralized",(function(){return x})),e.d(n,"FETCHING_TRANSLATIONS",(function(){return k})),e.d(n,"TRANSLATIONS_FETCHED",(function(){return S})),e.d(n,"TRANSLATIONS_FETCH_FAILED",(function(){return E})),e.d(n,"LOCALE_CHANGED",(function(){return O})),e.d(n,"FETCHING_LOCALES",(function(){return C})),e.d(n,"LOCALES_FETCHED",(function(){return _})),e.d(n,"LOCALES_FETCH_FAILED",(function(){return T})),e.d(n,"onEvent",(function(){return j})),e.d(n,"offEvent",(function(){return R})),e.d(n,"sendEvent",(function(){return A})),e.d(n,"PseudoTranslationPolicy",(function(){return P})),e.d(n,"SourceStringPolicy",(function(){return L})),e.d(n,"SourceErrorPolicy",(function(){return B})),e.d(n,"ThrowErrorPolicy",(function(){return $})),e.d(n,"MessageFormatRenderer",(function(){return D})),e.d(n,"tx",(function(){return q})),e.d(n,"t",(function(){return I}));var r=e(7),i=e.n(r);class o{constructor(){this.translationsByLocale={}}update(t,n){this.translationsByLocale[t]=n}getTranslations(t){return this.translationsByLocale[t]||{}}hasTranslations(t){return!!this.translationsByLocale[t]}isStale(t){return!this.hasTranslations(t)}get(t,n){return this.getTranslations(n)[t]||""}}class s{handle(t,n,e,r){return n}}class u{handle(t,n){return t}}var c=e(20);const a=new(e.n(c).a);class f{render(t,n,e){return a.compile(t)(e)}}var l=e(21),d=e.n(l);function h(t,n={}){return n._key?n._key:n._context?`${t}::${n._context}`:""+t}function p(t,n={}){if(n._key)return n._key;let e="";return n._context&&(e=n._context,e=e.replace(/,/g,":")),d()(`5:${t}:${e}`)}function m(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function g(t){return"[object String]"===Object.prototype.toString.call(t)}function y(t){const n=t.split("-");let e;return e=1===n.length?t:[n[0],n[1].toUpperCase()].join("_"),e}const b=["zero","one","two","few","many","other"];function w(t){const n=t.indexOf("{");if(-1===n)return[null,null];let e=t.substring(0,n).trim();if("="===e[0]){if(e=e.substring(1),Number.isNaN(parseInt(e,10))||parseInt(e,10)!==parseFloat(e))return[null,null];if(e=parseInt(e,10),e=b[e],void 0===e)return[null,null]}else if(-1===b.indexOf(e))return[null,null];return[e,t.substring(n)]}function v(t){let[n,e]=[0,!1],r=0;for(;r<t.length;){const i=t[r];if("'"===i){const n=t[r+1];"'"===n?r+=1:e?e=!1:"{"!==n&&"}"!==n||(e=!0)}else if("{"===i)e||(n+=1);else if("}"===i&&(e||(n-=1),0===n))return[t.substring(1,r),t.substring(r+1).trim()];r+=1}return[null,null]}function x(t){const[n,e]=function(t){if(!(t.length>1&&"{"===t[0]&&"}"===t[t.length-1]))return[null,null];const n=t.indexOf(",");if(-1===n)return[null,null];const e=t.indexOf(",",n+1);if(-1===e)return[null,null];const r=t.substring(1,n).trim();return"plural"!==t.substring(n+1,e).trim()?[null,null]:[r,t.substring(e+1,t.length-1).trim()]}(t);let r=e;if(null==n)return!1;const i={};let o,s;if([o,r]=w(r),null==o)return!1;if([s,r]=v(r.trim()),null==s)return!1;for(i[o]=s;r.trim();){if([o,r]=w(r.trim()),null==o)return!1;if([s,r]=v(r.trim()),null==s)return!1;i[o]=s}return(1!==Object.keys(i).length||"other"in i)&&"one"in i&&"other"in i}const k="FETCHING_TRANSLATIONS",S="TRANSLATIONS_FETCHED",E="TRANSLATIONS_FETCH_FAILED",O="LOCALE_CHANGED",C="FETCHING_LOCALES",_="LOCALES_FETCHED",T="LOCALES_FETCH_FAILED",N={};function j(t,n){N[t]=N[t]||[],N[t].push(n)}function R(t,n){const e=N[t]||[],r=e.indexOf(n);-1!==r&&e.splice(r,1)}function A(t,n,e){(N[t]||[]).forEach(t=>{t(n,e)})}const F={a:"ȧ",A:"Ȧ",b:"ƀ",B:"Ɓ",c:"ƈ",C:"Ƈ",d:"ḓ",D:"Ḓ",e:"ḗ",E:"Ḗ",f:"ƒ",F:"Ƒ",g:"ɠ",G:"Ɠ",h:"ħ",H:"Ħ",i:"ī",I:"Ī",j:"ĵ",J:"Ĵ",k:"ķ",K:"Ķ",l:"ŀ",L:"Ŀ",m:"ḿ",M:"Ḿ",n:"ƞ",N:"Ƞ",o:"ǿ",O:"Ǿ",p:"ƥ",P:"Ƥ",q:"ɋ",Q:"Ɋ",r:"ř",R:"Ř",s:"ş",S:"Ş",t:"ŧ",T:"Ŧ",v:"ṽ",V:"Ṽ",u:"ŭ",U:"Ŭ",w:"ẇ",W:"Ẇ",x:"ẋ",X:"Ẋ",y:"ẏ",Y:"Ẏ",z:"ẑ",Z:"Ẑ"};const P=class{handle(t,n){return t.split(/__txnative__/).map(t=>{let n="";for(let e=0;e<t.length;e+=1){const r=t.charAt(e);if(F[r]){const t=r.toLowerCase();n+="a"===t||"e"===t||"o"===t||"u"===t?F[r]+F[r]:F[r]}else n+=r}return n}).join("__txnative__")}},L=u,B=s,$=class{handle(t,n,e,r){throw t||new Error(`Error translating "${n}"`)}},D=f,q=new class{constructor(){this.cdsHost="https://cds.svc.transifex.net",this.token="",this.secret="",this.filterTags="",this.cache=new o,this.missingPolicy=new u,this.errorPolicy=new s,this.stringRenderer=new f,this.currentLocale="",this.locales=[],this.languages=[]}init(t){const n=this;["cdsHost","token","secret","cache","filterTags","missingPolicy","errorPolicy","stringRenderer","currentLocale"].forEach(e=>{void 0!==t[e]&&(n[e]=t[e])})}translate(t,n){return this.translateLocale(this.currentLocale,t,n)}translateLocale(t,n,e){try{let r=this.cache.get(h(n,e),t);if(r||(r=this.cache.get(p(n,e),t)),r&&r.startsWith("{???")&&x(n)){r=`{${n.substring(1,n.indexOf(",")).trim()}${r.substring(4)}`}let i=!1;if(r||(i=!0,r=n),e&&e._escapeVars){const n={};Object.keys(e).forEach(t=>{const r=e[t];n[t]=g(r)?m(r):r}),r=this.stringRenderer.render(r,t,n)}else r=this.stringRenderer.render(r,t,e);return i&&t&&(r=this.missingPolicy.handle(r,t)),g(r)||(r=""+r),r}catch(r){return this.errorPolicy.handle(r,""+n,t,e)}}async fetchTranslations(t,n={}){if(n.refresh||!this.cache.hasTranslations(t)||this.cache.isStale(t))try{let n;A(k,t,this);let e=202;for(;202===e;){let r=`${this.cdsHost}/content/${t}`;this.filterTags&&(r=`${r}?filter[tags]=${this.filterTags}`),n=await i.a.get(r,{headers:{Authorization:"Bearer "+this.token,"Accept-version":"v2","X-NATIVE-SDK":"txjs/node/2.0.
|
|
8
|
+
t.exports=function(t){return null!=t&&(e(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&e(t.slice(0,0))}(t)||!!t._isBuffer)}},function(t,n,e){"use strict";e.r(n),e.d(n,"generateKey",(function(){return h})),e.d(n,"generateHashedKey",(function(){return p})),e.d(n,"escape",(function(){return m})),e.d(n,"isString",(function(){return g})),e.d(n,"normalizeLocale",(function(){return y})),e.d(n,"isPluralized",(function(){return x})),e.d(n,"FETCHING_TRANSLATIONS",(function(){return k})),e.d(n,"TRANSLATIONS_FETCHED",(function(){return S})),e.d(n,"TRANSLATIONS_FETCH_FAILED",(function(){return E})),e.d(n,"LOCALE_CHANGED",(function(){return O})),e.d(n,"FETCHING_LOCALES",(function(){return C})),e.d(n,"LOCALES_FETCHED",(function(){return _})),e.d(n,"LOCALES_FETCH_FAILED",(function(){return T})),e.d(n,"onEvent",(function(){return j})),e.d(n,"offEvent",(function(){return R})),e.d(n,"sendEvent",(function(){return A})),e.d(n,"PseudoTranslationPolicy",(function(){return P})),e.d(n,"SourceStringPolicy",(function(){return L})),e.d(n,"SourceErrorPolicy",(function(){return B})),e.d(n,"ThrowErrorPolicy",(function(){return $})),e.d(n,"MessageFormatRenderer",(function(){return D})),e.d(n,"tx",(function(){return q})),e.d(n,"t",(function(){return I}));var r=e(7),i=e.n(r);class o{constructor(){this.translationsByLocale={}}update(t,n){this.translationsByLocale[t]=n}getTranslations(t){return this.translationsByLocale[t]||{}}hasTranslations(t){return!!this.translationsByLocale[t]}isStale(t){return!this.hasTranslations(t)}get(t,n){return this.getTranslations(n)[t]||""}}class s{handle(t,n,e,r){return n}}class u{handle(t,n){return t}}var c=e(20);const a=new(e.n(c).a);class f{render(t,n,e){return a.compile(t)(e)}}var l=e(21),d=e.n(l);function h(t,n={}){return n._key?n._key:n._context?`${t}::${n._context}`:""+t}function p(t,n={}){if(n._key)return n._key;let e="";return n._context&&(e=n._context,e=e.replace(/,/g,":")),d()(`5:${t}:${e}`)}function m(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function g(t){return"[object String]"===Object.prototype.toString.call(t)}function y(t){const n=t.split("-");let e;return e=1===n.length?t:[n[0],n[1].toUpperCase()].join("_"),e}const b=["zero","one","two","few","many","other"];function w(t){const n=t.indexOf("{");if(-1===n)return[null,null];let e=t.substring(0,n).trim();if("="===e[0]){if(e=e.substring(1),Number.isNaN(parseInt(e,10))||parseInt(e,10)!==parseFloat(e))return[null,null];if(e=parseInt(e,10),e=b[e],void 0===e)return[null,null]}else if(-1===b.indexOf(e))return[null,null];return[e,t.substring(n)]}function v(t){let[n,e]=[0,!1],r=0;for(;r<t.length;){const i=t[r];if("'"===i){const n=t[r+1];"'"===n?r+=1:e?e=!1:"{"!==n&&"}"!==n||(e=!0)}else if("{"===i)e||(n+=1);else if("}"===i&&(e||(n-=1),0===n))return[t.substring(1,r),t.substring(r+1).trim()];r+=1}return[null,null]}function x(t){const[n,e]=function(t){if(!(t.length>1&&"{"===t[0]&&"}"===t[t.length-1]))return[null,null];const n=t.indexOf(",");if(-1===n)return[null,null];const e=t.indexOf(",",n+1);if(-1===e)return[null,null];const r=t.substring(1,n).trim();return"plural"!==t.substring(n+1,e).trim()?[null,null]:[r,t.substring(e+1,t.length-1).trim()]}(t);let r=e;if(null==n)return!1;const i={};let o,s;if([o,r]=w(r),null==o)return!1;if([s,r]=v(r.trim()),null==s)return!1;for(i[o]=s;r.trim();){if([o,r]=w(r.trim()),null==o)return!1;if([s,r]=v(r.trim()),null==s)return!1;i[o]=s}return(1!==Object.keys(i).length||"other"in i)&&"one"in i&&"other"in i}const k="FETCHING_TRANSLATIONS",S="TRANSLATIONS_FETCHED",E="TRANSLATIONS_FETCH_FAILED",O="LOCALE_CHANGED",C="FETCHING_LOCALES",_="LOCALES_FETCHED",T="LOCALES_FETCH_FAILED",N={};function j(t,n){N[t]=N[t]||[],N[t].push(n)}function R(t,n){const e=N[t]||[],r=e.indexOf(n);-1!==r&&e.splice(r,1)}function A(t,n,e){(N[t]||[]).forEach(t=>{t(n,e)})}const F={a:"ȧ",A:"Ȧ",b:"ƀ",B:"Ɓ",c:"ƈ",C:"Ƈ",d:"ḓ",D:"Ḓ",e:"ḗ",E:"Ḗ",f:"ƒ",F:"Ƒ",g:"ɠ",G:"Ɠ",h:"ħ",H:"Ħ",i:"ī",I:"Ī",j:"ĵ",J:"Ĵ",k:"ķ",K:"Ķ",l:"ŀ",L:"Ŀ",m:"ḿ",M:"Ḿ",n:"ƞ",N:"Ƞ",o:"ǿ",O:"Ǿ",p:"ƥ",P:"Ƥ",q:"ɋ",Q:"Ɋ",r:"ř",R:"Ř",s:"ş",S:"Ş",t:"ŧ",T:"Ŧ",v:"ṽ",V:"Ṽ",u:"ŭ",U:"Ŭ",w:"ẇ",W:"Ẇ",x:"ẋ",X:"Ẋ",y:"ẏ",Y:"Ẏ",z:"ẑ",Z:"Ẑ"};const P=class{handle(t,n){return t.split(/__txnative__/).map(t=>{let n="";for(let e=0;e<t.length;e+=1){const r=t.charAt(e);if(F[r]){const t=r.toLowerCase();n+="a"===t||"e"===t||"o"===t||"u"===t?F[r]+F[r]:F[r]}else n+=r}return n}).join("__txnative__")}},L=u,B=s,$=class{handle(t,n,e,r){throw t||new Error(`Error translating "${n}"`)}},D=f,q=new class{constructor(){this.cdsHost="https://cds.svc.transifex.net",this.token="",this.secret="",this.filterTags="",this.cache=new o,this.missingPolicy=new u,this.errorPolicy=new s,this.stringRenderer=new f,this.currentLocale="",this.locales=[],this.languages=[]}init(t){const n=this;["cdsHost","token","secret","cache","filterTags","missingPolicy","errorPolicy","stringRenderer","currentLocale"].forEach(e=>{void 0!==t[e]&&(n[e]=t[e])})}translate(t,n){return this.translateLocale(this.currentLocale,t,n)}translateLocale(t,n,e){try{let r=this.cache.get(h(n,e),t);if(r||(r=this.cache.get(p(n,e),t)),r&&r.startsWith("{???")&&x(n)){r=`{${n.substring(1,n.indexOf(",")).trim()}${r.substring(4)}`}let i=!1;if(r||(i=!0,r=n),e&&e._escapeVars){const n={};Object.keys(e).forEach(t=>{const r=e[t];n[t]=g(r)?m(r):r}),r=this.stringRenderer.render(r,t,n)}else r=this.stringRenderer.render(r,t,e);return i&&t&&(r=this.missingPolicy.handle(r,t)),g(r)||(r=""+r),r}catch(r){return this.errorPolicy.handle(r,""+n,t,e)}}async fetchTranslations(t,n={}){if(n.refresh||!this.cache.hasTranslations(t)||this.cache.isStale(t))try{let n;A(k,t,this);let e=202;for(;202===e;){let r=`${this.cdsHost}/content/${t}`;this.filterTags&&(r=`${r}?filter[tags]=${this.filterTags}`),n=await i.a.get(r,{headers:{Authorization:"Bearer "+this.token,"Accept-version":"v2","X-NATIVE-SDK":"txjs/node/2.0.1"}}),e=n.status}const{data:r}=n;if(!r||!r.data)throw A(E,t,this),new Error("Could not fetch translations");{const n={};Object.keys(r.data).forEach(t=>{r.data[t].string&&(n[t]=r.data[t].string)}),this.cache.update(t,n),A(S,t,this)}}catch(n){throw A(E,t,this),n}}async getLocales(t={}){if(!!!t.refresh&&this.locales.length>0)return[...this.locales];if(!this.token)return[];try{let t;A(C,null,this);let n=202;for(;202===n;)t=await i.a.get(this.cdsHost+"/languages",{headers:{Authorization:"Bearer "+this.token,"Accept-version":"v2","X-NATIVE-SDK":"txjs/node/2.0.1"}}),n=t.status;const{data:e}=t;if(!e||!e.data)throw A(T,null,this),new Error("Could not fetch languages");this.languages=e.data,this.locales=this.languages.map(t=>t.code),A(_,null,this)}catch(t){throw A(T,null,this),t}return[...this.locales]}getCurrentLocale(){return this.currentLocale}isCurrent(t){return t===this.currentLocale}async setCurrentLocale(t){if(!this.isCurrent(t)){if(!t)return this.currentLocale="",void A(O,this.currentLocale,this);await this.fetchTranslations(t),this.currentLocale=t,A(O,t,this)}}async getLanguages(t={}){return await this.getLocales(t),[...this.languages]}},I=q.translate.bind(q)}])}));
|
|
9
9
|
//# sourceMappingURL=node.native.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transifex/native",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Transifex Native for Javascript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transifex",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"main": "dist/node.native.js",
|
|
15
15
|
"browser": "dist/browser.native.js",
|
|
16
|
-
"module": "src/index.js",
|
|
17
16
|
"types": "dist/node.native.d.ts",
|
|
18
17
|
"publishConfig": {
|
|
19
18
|
"access": "public"
|