@transifex/native 3.2.1 → 3.2.2
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/README.md +35 -1
- package/dist/browser.native.js +1 -1
- package/dist/node.native.js +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.transifex.com">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/transifex/transifex-javascript/master/media/transifex.png" height="60">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<i>Transifex Native is a full end-to-end, cloud-based localization stack for moderns apps.</i>
|
|
8
|
+
</p>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="https://github.com/transifex/transifex-javascript/actions/workflows/npm-publish.yml/badge.svg">
|
|
11
|
+
<a href="https://www.npmjs.com/package/@transifex/native">
|
|
12
|
+
<img src="https://img.shields.io/npm/v/@transifex/native.svg">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://developers.transifex.com/docs/native">
|
|
15
|
+
<img src="https://img.shields.io/badge/docs-transifex.com-blue">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
# Transifex Native SDK: JavaScript i18n
|
|
2
20
|
|
|
3
21
|
A general purpose Javascript library for localizing web apps using [Transifex Native](https://www.transifex.com/native/).
|
|
4
22
|
|
|
@@ -12,6 +30,22 @@ Related packages:
|
|
|
12
30
|
|
|
13
31
|
Learn more about Transifex Native in the [Transifex Developer Hub](https://developers.transifex.com/docs/native).
|
|
14
32
|
|
|
33
|
+
# How it works
|
|
34
|
+
|
|
35
|
+
**Step1**: Create a Transifex Native project in [Transifex](https://www.transifex.com).
|
|
36
|
+
|
|
37
|
+
**Step2**: Grab credentials.
|
|
38
|
+
|
|
39
|
+
**Step3**: Internationalize the code using the SDK.
|
|
40
|
+
|
|
41
|
+
**Step4**: Push source phrases using the `@transifex/cli` tool.
|
|
42
|
+
|
|
43
|
+
**Step5**: Translate the app using over-the-air updates.
|
|
44
|
+
|
|
45
|
+
No translation files required.
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
15
49
|
# Upgrade to v2
|
|
16
50
|
|
|
17
51
|
If you are upgrading from the `1.x.x` version, please read this [migration guide](https://github.com/transifex/transifex-javascript/blob/HEAD/UPGRADE_TO_V2.md), as there are breaking changes in place.
|
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 j})),r.d(t,"generateHashedKey",(function(){return T})),r.d(t,"escape",(function(){return N})),r.d(t,"isString",(function(){return _})),r.d(t,"normalizeLocale",(function(){return L})),r.d(t,"isPluralized",(function(){return D})),r.d(t,"sleep",(function(){return I})),r.d(t,"FETCHING_TRANSLATIONS",(function(){return R})),r.d(t,"TRANSLATIONS_FETCHED",(function(){return z})),r.d(t,"TRANSLATIONS_FETCH_FAILED",(function(){return M})),r.d(t,"LOCALE_CHANGED",(function(){return q})),r.d(t,"FETCHING_LOCALES",(function(){return U})),r.d(t,"LOCALES_FETCHED",(function(){return H})),r.d(t,"LOCALES_FETCH_FAILED",(function(){return J})),r.d(t,"onEvent",(function(){return G})),r.d(t,"offEvent",(function(){return $})),r.d(t,"sendEvent",(function(){return Z})),r.d(t,"PseudoTranslationPolicy",(function(){return Q})),r.d(t,"SourceStringPolicy",(function(){return ee})),r.d(t,"SourceErrorPolicy",(function(){return te})),r.d(t,"ThrowErrorPolicy",(function(){return re})),r.d(t,"MessageFormatRenderer",(function(){return ne})),r.d(t,"createNativeInstance",(function(){return ie})),r.d(t,"tx",(function(){return oe})),r.d(t,"t",(function(){return ae}));var n=r(8),i=r.n(n),o=r(23),a=r.n(o),s=r(4),u=r.n(s),c=r(2),l=r.n(c),f=r(3),h=r.n(f),p=r(0),d=r.n(p),m=r(5),g=r.n(m),y=function(){function e(){l()(this,e),this.translationsByLocale={}}return h()(e,[{key:"update",value:function(e,t){this.translationsByLocale[e]||(this.translationsByLocale[e]={}),Object.assign(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}(),v=function(){function e(){l()(this,e)}return h()(e,[{key:"handle",value:function(e,t,r,n){return t}}]),e}(),w=function(){function e(){l()(this,e)}return h()(e,[{key:"handle",value:function(e,t){return e}}]),e}(),b=r(10),x=r.n(b),k={},S=function(){function e(){l()(this,e)}return h()(e,[{key:"render",value:function(e,t,r){var n=(t||"").split("_")[0];if(!k[n])try{k[n]=new x.a(n)}catch(e){k[n]=new x.a}return k[n].compile(e)(r)}}]),e}(),E=r(6),O=r.n(E),F=r(24),A=r.n(F);function j(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 T(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,":")),A()("5:".concat(e,":").concat(r))}function N(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function _(e){return"[object String]"===Object.prototype.toString.call(e)}function L(e){var t=e.split("-");return 1===t.length?e:[t[0],t[1].toUpperCase()].join("_")}var P=["zero","one","two","few","many","other"];function B(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=P[r]))return[null,null]}else if(-1===P.indexOf(r))return[null,null];return[r,e.substring(t)]}function C(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 D(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=O()(t,2),n=r[0],i=r[1];if(null==n)return!1;var o,a,s={},u=B(i),c=O()(u,2);if(o=c[0],i=c[1],null==o)return!1;var l=C(i.trim()),f=O()(l,2);if(a=f[0],i=f[1],null==a)return!1;for(s[o]=a;i.trim();){var h=B(i.trim()),p=O()(h,2);if(o=p[0],i=p[1],null==o)return!1;var d=C(i.trim()),m=O()(d,2);if(a=m[0],i=m[1],null==a)return!1;s[o]=a}return(1!==Object.keys(s).length||"other"in s)&&"one"in s&&"other"in s}function I(e){return new Promise((function(t){setTimeout((function(){t()}),e)}))}var R="FETCHING_TRANSLATIONS",z="TRANSLATIONS_FETCHED",M="TRANSLATIONS_FETCH_FAILED",q="LOCALE_CHANGED",U="FETCHING_LOCALES",H="LOCALES_FETCHED",J="LOCALES_FETCH_FAILED",W={};function G(e,t){W[e]=W[e]||[],W[e].push(t)}function $(e,t){var r=W[e]||[],n=r.indexOf(t);-1!==n&&r.splice(n,1)}function Z(e,t,r){(W[e]||[]).forEach((function(e){e(t,r)}))}function K(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function V(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?K(Object(r),!0).forEach((function(t){a()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):K(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var X=function(){function e(){l()(this,e),this.cdsHost="https://cds.svc.transifex.net",this.token="",this.secret="",this.filterTags="",this.cache=new y,this.missingPolicy=new w,this.errorPolicy=new v,this.stringRenderer=new S,this.currentLocale="",this.locales=[],this.languages=[],this.childInstances=[]}var t,r,n,o,a,s,c,f;return h()(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])})),this.fetchedTags={}}},{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(j(t,r),e);if(n||(n=this.cache.get(T(t,r),e)),n&&n.startsWith("{???")&&D(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)?N(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)),_(n)||(n="".concat(n)),n}catch(n){return this.errorPolicy.handle(n,"".concat(t),e,r)}}},{key:"fetchTranslations",value:(f=u()(d.a.mark((function e(t){var r,n,i,o,a,s,u,c=arguments;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=c.length>1&&void 0!==c[1]?c[1]:{},n=r.filterTags||this.filterTags,r.refresh||this.cache.isStale(t)||!(!n&&this.cache.hasTranslations(t)||n&&-1!==(this.fetchedTags[t]||[]).indexOf(n))){e.next=4;break}return e.abrupt("return");case 4:n&&(t in this.fetchedTags||(this.fetchedTags[t]=[]),-1===this.fetchedTags[t].indexOf(n)&&this.fetchedTags[t].push(n)),e.prev=5,Z(R,{localeCode:t,filterTags:n},this),o=202;case 8:if(202!==o){e.next=17;break}return a="".concat(this.cdsHost,"/content/").concat(t),n&&(a="".concat(a,"?filter[tags]=").concat(n)),e.next=13,g.a.get(a,{headers:{Authorization:"Bearer ".concat(this.token),"Accept-version":"v2","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("3.2.1")}});case 13:i=e.sent,o=i.status,e.next=8;break;case 17:if(!(s=i.data)||!s.data){e.next=25;break}u={},Object.keys(s.data).forEach((function(e){s.data[e].string&&(u[e]=s.data[e].string)})),this.cache.update(t,u),Z(z,{localeCode:t,filterTags:n},this),e.next=27;break;case 25:throw Z(M,{localeCode:t,filterTags:n},this),new Error("Could not fetch translations");case 27:e.next=33;break;case 29:throw e.prev=29,e.t0=e.catch(5),Z(M,{localeCode:t,filterTags:n},this),e.t0;case 33:case"end":return e.stop()}}),e,this,[[5,29]])}))),function(e){return f.apply(this,arguments)})},{key:"invalidateCDS",value:(c=u()(d.a.mark((function e(){var t,r,n,i=arguments;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:{},this.token){e.next=3;break}throw new Error("token is not defined");case 3:if(this.secret){e.next=5;break}throw new Error("secret is not defined");case 5:return r=t.purge?"purge":"invalidate",e.next=8,g.a.post("".concat(this.cdsHost,"/").concat(r),{},{headers:{Authorization:"Bearer ".concat(this.token,":").concat(this.secret),"Accept-version":"v2","Content-Type":"application/json;charset=utf-8","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("3.2.1")}});case 8:return n=e.sent,e.abrupt("return",n.data);case 10:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"pushSource",value:(s=u()(d.a.mark((function e(t){var r,n,i,o,a,s,u,c=arguments;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=c.length>1&&void 0!==c[1]?c[1]:{},this.token){e.next=3;break}throw new Error("token is not defined");case 3:if(this.secret){e.next=5;break}throw new Error("secret is not defined");case 5:return n={Authorization:"Bearer ".concat(this.token,":").concat(this.secret),"Accept-version":"v2","Content-Type":"application/json;charset=utf-8","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("3.2.1")},e.next=8,g.a.post("".concat(this.cdsHost,"/content"),{data:t,meta:{purge:!!r.purge,override_tags:!!r.overrideTags}},{headers:n});case 8:if(i=e.sent,o="".concat(this.cdsHost).concat(i.data.data.links.job),!r.noWait){e.next=12;break}return e.abrupt("return",{jobUrl:o});case 12:a={status:""};case 13:return e.next=15,I(1500);case 15:return e.next=17,g.a.get(o,{headers:n});case 17:s=e.sent,u=s.data.data,a=V(V({},u.details||{}),{},{errors:u.errors||[],status:u.status});case 20:if("pending"===a.status||"processing"===a.status){e.next=13;break}case 21:return e.abrupt("return",V({jobUrl:o},a));case 22:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"getLocales",value:(a=u()(d.a.mark((function e(){var t,r,n,o=arguments;return d.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,Z(U,null,this),r=202;case 9:if(202!==r){e.next=16;break}return e.next=12,g.a.get("".concat(this.cdsHost,"/languages"),{headers:{Authorization:"Bearer ".concat(this.token),"Accept-version":"v2","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("3.2.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})),Z(H,null,this),e.next=25;break;case 23:throw Z(J,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),Z(J,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 a.apply(this,arguments)})},{key:"getCurrentLocale",value:function(){return this.currentLocale}},{key:"isCurrent",value:function(e){return e===this.currentLocale}},{key:"setCurrentLocale",value:(o=u()(d.a.mark((function e(t){return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isCurrent(t)){e.next=4;break}return e.next=3,this._syncInstances(this.childInstances);case 3:return e.abrupt("return");case 4:if(t){e.next=10;break}return this.currentLocale="",e.next=8,this._syncInstances(this.childInstances);case 8:return Z(q,this.currentLocale,this),e.abrupt("return");case 10:return e.next=12,this.fetchTranslations(t);case 12:return this.currentLocale=t,e.next=15,this._syncInstances(this.childInstances);case 15:Z(q,t,this);case 16:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"getLanguages",value:(n=u()(d.a.mark((function e(){var t,r=arguments;return d.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 n.apply(this,arguments)})},{key:"controllerOf",value:(r=u()(d.a.mark((function e(t){return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t!==this){e.next=2;break}throw new Error("Cannot add self as instance");case 2:if(-1===t.childInstances.indexOf(this)){e.next=4;break}throw new Error("Cycle reference error, instance is controller of this");case 4:return this.childInstances.push(t),e.next=7,this._syncInstances([t]);case 7:return e.abrupt("return",t);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"_syncInstances",value:(t=u()(d.a.mark((function e(t){var r,n;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.getCurrentLocale())){e.next=15;break}n=0;case 3:if(!(n<t.length)){e.next=15;break}if(t[n].getCurrentLocale()===r){e.next=12;break}return e.prev=5,e.next=8,t[n].fetchTranslations(r);case 8:e.next=12;break;case 10:e.prev=10,e.t0=e.catch(5);case 12:n++,e.next=3;break;case 15:t.forEach((function(e){e.getCurrentLocale()!==r&&(e.currentLocale=r,Z(q,r,e))}));case 16:case"end":return e.stop()}}),e,this,[[5,10]])}))),function(e){return t.apply(this,arguments)})}]),e}(),Y={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:"Ẑ"};var Q=function(){function e(){l()(this,e)}return h()(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(Y[n]){var i=n.toLowerCase();t+="a"===i||"e"===i||"o"===i||"u"===i?Y[n]+Y[n]:Y[n]}else t+=n}return t})).join("__txnative__")}}]),e}(),ee=w,te=v,re=function(){function e(){l()(this,e)}return h()(e,[{key:"handle",value:function(e,t,r,n){throw e||new Error('Error translating "'.concat(t,'"'))}}]),e}(),ne=S,ie=function(e){var t=new X;return t.t=t.translate.bind(t),e&&t.init(e),t},oe=new X,ae=oe.translate.bind(oe)}])}));
|
|
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 j})),r.d(t,"generateHashedKey",(function(){return T})),r.d(t,"escape",(function(){return N})),r.d(t,"isString",(function(){return _})),r.d(t,"normalizeLocale",(function(){return L})),r.d(t,"isPluralized",(function(){return D})),r.d(t,"sleep",(function(){return I})),r.d(t,"FETCHING_TRANSLATIONS",(function(){return R})),r.d(t,"TRANSLATIONS_FETCHED",(function(){return z})),r.d(t,"TRANSLATIONS_FETCH_FAILED",(function(){return M})),r.d(t,"LOCALE_CHANGED",(function(){return q})),r.d(t,"FETCHING_LOCALES",(function(){return U})),r.d(t,"LOCALES_FETCHED",(function(){return H})),r.d(t,"LOCALES_FETCH_FAILED",(function(){return J})),r.d(t,"onEvent",(function(){return G})),r.d(t,"offEvent",(function(){return $})),r.d(t,"sendEvent",(function(){return Z})),r.d(t,"PseudoTranslationPolicy",(function(){return Q})),r.d(t,"SourceStringPolicy",(function(){return ee})),r.d(t,"SourceErrorPolicy",(function(){return te})),r.d(t,"ThrowErrorPolicy",(function(){return re})),r.d(t,"MessageFormatRenderer",(function(){return ne})),r.d(t,"createNativeInstance",(function(){return ie})),r.d(t,"tx",(function(){return oe})),r.d(t,"t",(function(){return ae}));var n=r(8),i=r.n(n),o=r(23),a=r.n(o),s=r(4),u=r.n(s),c=r(2),l=r.n(c),f=r(3),h=r.n(f),p=r(0),d=r.n(p),m=r(5),g=r.n(m),y=function(){function e(){l()(this,e),this.translationsByLocale={}}return h()(e,[{key:"update",value:function(e,t){this.translationsByLocale[e]||(this.translationsByLocale[e]={}),Object.assign(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}(),v=function(){function e(){l()(this,e)}return h()(e,[{key:"handle",value:function(e,t,r,n){return t}}]),e}(),w=function(){function e(){l()(this,e)}return h()(e,[{key:"handle",value:function(e,t){return e}}]),e}(),b=r(10),x=r.n(b),k={},S=function(){function e(){l()(this,e)}return h()(e,[{key:"render",value:function(e,t,r){var n=(t||"").split("_")[0];if(!k[n])try{k[n]=new x.a(n)}catch(e){k[n]=new x.a}return k[n].compile(e)(r)}}]),e}(),E=r(6),O=r.n(E),F=r(24),A=r.n(F);function j(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 T(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,":")),A()("5:".concat(e,":").concat(r))}function N(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function _(e){return"[object String]"===Object.prototype.toString.call(e)}function L(e){var t=e.split("-");return 1===t.length?e:[t[0],t[1].toUpperCase()].join("_")}var P=["zero","one","two","few","many","other"];function B(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=P[r]))return[null,null]}else if(-1===P.indexOf(r))return[null,null];return[r,e.substring(t)]}function C(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 D(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=O()(t,2),n=r[0],i=r[1];if(null==n)return!1;var o,a,s={},u=B(i),c=O()(u,2);if(o=c[0],i=c[1],null==o)return!1;var l=C(i.trim()),f=O()(l,2);if(a=f[0],i=f[1],null==a)return!1;for(s[o]=a;i.trim();){var h=B(i.trim()),p=O()(h,2);if(o=p[0],i=p[1],null==o)return!1;var d=C(i.trim()),m=O()(d,2);if(a=m[0],i=m[1],null==a)return!1;s[o]=a}return(1!==Object.keys(s).length||"other"in s)&&"one"in s&&"other"in s}function I(e){return new Promise((function(t){setTimeout((function(){t()}),e)}))}var R="FETCHING_TRANSLATIONS",z="TRANSLATIONS_FETCHED",M="TRANSLATIONS_FETCH_FAILED",q="LOCALE_CHANGED",U="FETCHING_LOCALES",H="LOCALES_FETCHED",J="LOCALES_FETCH_FAILED",W={};function G(e,t){W[e]=W[e]||[],W[e].push(t)}function $(e,t){var r=W[e]||[],n=r.indexOf(t);-1!==n&&r.splice(n,1)}function Z(e,t,r){(W[e]||[]).forEach((function(e){e(t,r)}))}function K(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function V(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?K(Object(r),!0).forEach((function(t){a()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):K(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var X=function(){function e(){l()(this,e),this.cdsHost="https://cds.svc.transifex.net",this.token="",this.secret="",this.filterTags="",this.cache=new y,this.missingPolicy=new w,this.errorPolicy=new v,this.stringRenderer=new S,this.currentLocale="",this.locales=[],this.languages=[],this.childInstances=[]}var t,r,n,o,a,s,c,f;return h()(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])})),this.fetchedTags={}}},{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(j(t,r),e);if(n||(n=this.cache.get(T(t,r),e)),n&&n.startsWith("{???")&&D(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)?N(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)),_(n)||(n="".concat(n)),n}catch(n){return this.errorPolicy.handle(n,"".concat(t),e,r)}}},{key:"fetchTranslations",value:(f=u()(d.a.mark((function e(t){var r,n,i,o,a,s,u,c=arguments;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=c.length>1&&void 0!==c[1]?c[1]:{},n=r.filterTags||this.filterTags,r.refresh||this.cache.isStale(t)||!(!n&&this.cache.hasTranslations(t)||n&&-1!==(this.fetchedTags[t]||[]).indexOf(n))){e.next=4;break}return e.abrupt("return");case 4:n&&(t in this.fetchedTags||(this.fetchedTags[t]=[]),-1===this.fetchedTags[t].indexOf(n)&&this.fetchedTags[t].push(n)),e.prev=5,Z(R,{localeCode:t,filterTags:n},this),o=202;case 8:if(202!==o){e.next=17;break}return a="".concat(this.cdsHost,"/content/").concat(t),n&&(a="".concat(a,"?filter[tags]=").concat(n)),e.next=13,g.a.get(a,{headers:{Authorization:"Bearer ".concat(this.token),"Accept-version":"v2","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("3.2.2")}});case 13:i=e.sent,o=i.status,e.next=8;break;case 17:if(!(s=i.data)||!s.data){e.next=25;break}u={},Object.keys(s.data).forEach((function(e){s.data[e].string&&(u[e]=s.data[e].string)})),this.cache.update(t,u),Z(z,{localeCode:t,filterTags:n},this),e.next=27;break;case 25:throw Z(M,{localeCode:t,filterTags:n},this),new Error("Could not fetch translations");case 27:e.next=33;break;case 29:throw e.prev=29,e.t0=e.catch(5),Z(M,{localeCode:t,filterTags:n},this),e.t0;case 33:case"end":return e.stop()}}),e,this,[[5,29]])}))),function(e){return f.apply(this,arguments)})},{key:"invalidateCDS",value:(c=u()(d.a.mark((function e(){var t,r,n,i=arguments;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:{},this.token){e.next=3;break}throw new Error("token is not defined");case 3:if(this.secret){e.next=5;break}throw new Error("secret is not defined");case 5:return r=t.purge?"purge":"invalidate",e.next=8,g.a.post("".concat(this.cdsHost,"/").concat(r),{},{headers:{Authorization:"Bearer ".concat(this.token,":").concat(this.secret),"Accept-version":"v2","Content-Type":"application/json;charset=utf-8","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("3.2.2")}});case 8:return n=e.sent,e.abrupt("return",n.data);case 10:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"pushSource",value:(s=u()(d.a.mark((function e(t){var r,n,i,o,a,s,u,c=arguments;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=c.length>1&&void 0!==c[1]?c[1]:{},this.token){e.next=3;break}throw new Error("token is not defined");case 3:if(this.secret){e.next=5;break}throw new Error("secret is not defined");case 5:return n={Authorization:"Bearer ".concat(this.token,":").concat(this.secret),"Accept-version":"v2","Content-Type":"application/json;charset=utf-8","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("3.2.2")},e.next=8,g.a.post("".concat(this.cdsHost,"/content"),{data:t,meta:{purge:!!r.purge,override_tags:!!r.overrideTags}},{headers:n});case 8:if(i=e.sent,o="".concat(this.cdsHost).concat(i.data.data.links.job),!r.noWait){e.next=12;break}return e.abrupt("return",{jobUrl:o});case 12:a={status:""};case 13:return e.next=15,I(1500);case 15:return e.next=17,g.a.get(o,{headers:n});case 17:s=e.sent,u=s.data.data,a=V(V({},u.details||{}),{},{errors:u.errors||[],status:u.status});case 20:if("pending"===a.status||"processing"===a.status){e.next=13;break}case 21:return e.abrupt("return",V({jobUrl:o},a));case 22:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"getLocales",value:(a=u()(d.a.mark((function e(){var t,r,n,o=arguments;return d.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,Z(U,null,this),r=202;case 9:if(202!==r){e.next=16;break}return e.next=12,g.a.get("".concat(this.cdsHost,"/languages"),{headers:{Authorization:"Bearer ".concat(this.token),"Accept-version":"v2","X-NATIVE-SDK":"txjs/".concat("browser","/").concat("3.2.2")}});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})),Z(H,null,this),e.next=25;break;case 23:throw Z(J,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),Z(J,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 a.apply(this,arguments)})},{key:"getCurrentLocale",value:function(){return this.currentLocale}},{key:"isCurrent",value:function(e){return e===this.currentLocale}},{key:"setCurrentLocale",value:(o=u()(d.a.mark((function e(t){return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isCurrent(t)){e.next=4;break}return e.next=3,this._syncInstances(this.childInstances);case 3:return e.abrupt("return");case 4:if(t){e.next=10;break}return this.currentLocale="",e.next=8,this._syncInstances(this.childInstances);case 8:return Z(q,this.currentLocale,this),e.abrupt("return");case 10:return e.next=12,this.fetchTranslations(t);case 12:return this.currentLocale=t,e.next=15,this._syncInstances(this.childInstances);case 15:Z(q,t,this);case 16:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"getLanguages",value:(n=u()(d.a.mark((function e(){var t,r=arguments;return d.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 n.apply(this,arguments)})},{key:"controllerOf",value:(r=u()(d.a.mark((function e(t){return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t!==this){e.next=2;break}throw new Error("Cannot add self as instance");case 2:if(-1===t.childInstances.indexOf(this)){e.next=4;break}throw new Error("Cycle reference error, instance is controller of this");case 4:return this.childInstances.push(t),e.next=7,this._syncInstances([t]);case 7:return e.abrupt("return",t);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"_syncInstances",value:(t=u()(d.a.mark((function e(t){var r,n;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.getCurrentLocale())){e.next=15;break}n=0;case 3:if(!(n<t.length)){e.next=15;break}if(t[n].getCurrentLocale()===r){e.next=12;break}return e.prev=5,e.next=8,t[n].fetchTranslations(r);case 8:e.next=12;break;case 10:e.prev=10,e.t0=e.catch(5);case 12:n++,e.next=3;break;case 15:t.forEach((function(e){e.getCurrentLocale()!==r&&(e.currentLocale=r,Z(q,r,e))}));case 16:case"end":return e.stop()}}),e,this,[[5,10]])}))),function(e){return t.apply(this,arguments)})}]),e}(),Y={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:"Ẑ"};var Q=function(){function e(){l()(this,e)}return h()(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(Y[n]){var i=n.toLowerCase();t+="a"===i||"e"===i||"o"===i||"u"===i?Y[n]+Y[n]:Y[n]}else t+=n}return t})).join("__txnative__")}}]),e}(),ee=w,te=v,re=function(){function e(){l()(this,e)}return h()(e,[{key:"handle",value:function(e,t,r,n){throw e||new Error('Error translating "'.concat(t,'"'))}}]),e}(),ne=S,ie=function(e){var t=new X;return t.t=t.translate.bind(t),e&&t.init(e),t},oe=new X,ae=oe.translate.bind(oe)}])}));
|
|
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&&(n(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&n(t.slice(0,0))}(t)||!!t._isBuffer)}},function(t,e,n){"use strict";n.r(e),n.d(e,"generateKey",(function(){return p})),n.d(e,"generateHashedKey",(function(){return m})),n.d(e,"escape",(function(){return g})),n.d(e,"isString",(function(){return y})),n.d(e,"normalizeLocale",(function(){return w})),n.d(e,"isPluralized",(function(){return k})),n.d(e,"sleep",(function(){return S})),n.d(e,"FETCHING_TRANSLATIONS",(function(){return E})),n.d(e,"TRANSLATIONS_FETCHED",(function(){return O})),n.d(e,"TRANSLATIONS_FETCH_FAILED",(function(){return C})),n.d(e,"LOCALE_CHANGED",(function(){return _})),n.d(e,"FETCHING_LOCALES",(function(){return T})),n.d(e,"LOCALES_FETCHED",(function(){return N})),n.d(e,"LOCALES_FETCH_FAILED",(function(){return j})),n.d(e,"onEvent",(function(){return R})),n.d(e,"offEvent",(function(){return F})),n.d(e,"sendEvent",(function(){return P})),n.d(e,"PseudoTranslationPolicy",(function(){return $})),n.d(e,"SourceStringPolicy",(function(){return I})),n.d(e,"SourceErrorPolicy",(function(){return D})),n.d(e,"ThrowErrorPolicy",(function(){return q})),n.d(e,"MessageFormatRenderer",(function(){return z})),n.d(e,"createNativeInstance",(function(){return M})),n.d(e,"tx",(function(){return U})),n.d(e,"t",(function(){return H}));var r=n(1),i=n.n(r);class o{constructor(){this.translationsByLocale={}}update(t,e){this.translationsByLocale[t]||(this.translationsByLocale[t]={}),Object.assign(this.translationsByLocale[t],e)}getTranslations(t){return this.translationsByLocale[t]||{}}hasTranslations(t){return!!this.translationsByLocale[t]}isStale(t){return!this.hasTranslations(t)}get(t,e){return this.getTranslations(e)[t]||""}}class s{handle(t,e,n,r){return e}}class u{handle(t,e){return t}}var c=n(9),a=n.n(c);const f={};class l{render(t,e,n){const r=(e||"").split("_")[0];if(!f[r])try{f[r]=new a.a(r)}catch(t){f[r]=new a.a}return f[r].compile(t)(n)}}var d=n(22),h=n.n(d);function p(t,e={}){return e._key?e._key:e._context?`${t}::${e._context}`:""+t}function m(t,e={}){if(e._key)return e._key;let n="";return e._context&&(n=e._context,n=n.replace(/,/g,":")),h()(`5:${t}:${n}`)}function g(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function y(t){return"[object String]"===Object.prototype.toString.call(t)}function w(t){const e=t.split("-");let n;return n=1===e.length?t:[e[0],e[1].toUpperCase()].join("_"),n}const b=["zero","one","two","few","many","other"];function v(t){const e=t.indexOf("{");if(-1===e)return[null,null];let n=t.substring(0,e).trim();if("="===n[0]){if(n=n.substring(1),Number.isNaN(parseInt(n,10))||parseInt(n,10)!==parseFloat(n))return[null,null];if(n=parseInt(n,10),n=b[n],void 0===n)return[null,null]}else if(-1===b.indexOf(n))return[null,null];return[n,t.substring(e)]}function x(t){let[e,n]=[0,!1],r=0;for(;r<t.length;){const i=t[r];if("'"===i){const e=t[r+1];"'"===e?r+=1:n?n=!1:"{"!==e&&"}"!==e||(n=!0)}else if("{"===i)n||(e+=1);else if("}"===i&&(n||(e-=1),0===e))return[t.substring(1,r),t.substring(r+1).trim()];r+=1}return[null,null]}function k(t){const[e,n]=function(t){if(!(t.length>1&&"{"===t[0]&&"}"===t[t.length-1]))return[null,null];const e=t.indexOf(",");if(-1===e)return[null,null];const n=t.indexOf(",",e+1);if(-1===n)return[null,null];const r=t.substring(1,e).trim();return"plural"!==t.substring(e+1,n).trim()?[null,null]:[r,t.substring(n+1,t.length-1).trim()]}(t);let r=n;if(null==e)return!1;const i={};let o,s;if([o,r]=v(r),null==o)return!1;if([s,r]=x(r.trim()),null==s)return!1;for(i[o]=s;r.trim();){if([o,r]=v(r.trim()),null==o)return!1;if([s,r]=x(r.trim()),null==s)return!1;i[o]=s}return(1!==Object.keys(i).length||"other"in i)&&"one"in i&&"other"in i}function S(t){return new Promise(e=>{setTimeout(()=>{e()},t)})}const E="FETCHING_TRANSLATIONS",O="TRANSLATIONS_FETCHED",C="TRANSLATIONS_FETCH_FAILED",_="LOCALE_CHANGED",T="FETCHING_LOCALES",N="LOCALES_FETCHED",j="LOCALES_FETCH_FAILED",A={};function R(t,e){A[t]=A[t]||[],A[t].push(e)}function F(t,e){const n=A[t]||[],r=n.indexOf(e);-1!==r&&n.splice(r,1)}function P(t,e,n){(A[t]||[]).forEach(t=>{t(e,n)})}class L{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 l,this.currentLocale="",this.locales=[],this.languages=[],this.childInstances=[]}init(t){const e=this;["cdsHost","token","secret","cache","filterTags","missingPolicy","errorPolicy","stringRenderer","currentLocale"].forEach(n=>{void 0!==t[n]&&(e[n]=t[n])}),this.fetchedTags={}}translate(t,e){return this.translateLocale(this.currentLocale,t,e)}translateLocale(t,e,n){try{let r=this.cache.get(p(e,n),t);if(r||(r=this.cache.get(m(e,n),t)),r&&r.startsWith("{???")&&k(e)){r=`{${e.substring(1,e.indexOf(",")).trim()}${r.substring(4)}`}let i=!1;if(r||(i=!0,r=e),n&&n._escapeVars){const e={};Object.keys(n).forEach(t=>{const r=n[t];e[t]=y(r)?g(r):r}),r=this.stringRenderer.render(r,t,e)}else r=this.stringRenderer.render(r,t,n);return i&&t&&(r=this.missingPolicy.handle(r,t)),y(r)||(r=""+r),r}catch(r){return this.errorPolicy.handle(r,""+e,t,n)}}async fetchTranslations(t,e={}){const n=e.filterTags||this.filterTags;if(e.refresh||this.cache.isStale(t)||!(!n&&this.cache.hasTranslations(t)||n&&-1!==(this.fetchedTags[t]||[]).indexOf(n))){n&&(t in this.fetchedTags||(this.fetchedTags[t]=[]),-1===this.fetchedTags[t].indexOf(n)&&this.fetchedTags[t].push(n));try{let e;P(E,{localeCode:t,filterTags:n},this);let r=202;for(;202===r;){let o=`${this.cdsHost}/content/${t}`;n&&(o=`${o}?filter[tags]=${n}`),e=await i.a.get(o,{headers:{Authorization:"Bearer "+this.token,"Accept-version":"v2","X-NATIVE-SDK":"txjs/node/3.2.
|
|
8
|
+
t.exports=function(t){return null!=t&&(n(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&n(t.slice(0,0))}(t)||!!t._isBuffer)}},function(t,e,n){"use strict";n.r(e),n.d(e,"generateKey",(function(){return p})),n.d(e,"generateHashedKey",(function(){return m})),n.d(e,"escape",(function(){return g})),n.d(e,"isString",(function(){return y})),n.d(e,"normalizeLocale",(function(){return w})),n.d(e,"isPluralized",(function(){return k})),n.d(e,"sleep",(function(){return S})),n.d(e,"FETCHING_TRANSLATIONS",(function(){return E})),n.d(e,"TRANSLATIONS_FETCHED",(function(){return O})),n.d(e,"TRANSLATIONS_FETCH_FAILED",(function(){return C})),n.d(e,"LOCALE_CHANGED",(function(){return _})),n.d(e,"FETCHING_LOCALES",(function(){return T})),n.d(e,"LOCALES_FETCHED",(function(){return N})),n.d(e,"LOCALES_FETCH_FAILED",(function(){return j})),n.d(e,"onEvent",(function(){return R})),n.d(e,"offEvent",(function(){return F})),n.d(e,"sendEvent",(function(){return P})),n.d(e,"PseudoTranslationPolicy",(function(){return $})),n.d(e,"SourceStringPolicy",(function(){return I})),n.d(e,"SourceErrorPolicy",(function(){return D})),n.d(e,"ThrowErrorPolicy",(function(){return q})),n.d(e,"MessageFormatRenderer",(function(){return z})),n.d(e,"createNativeInstance",(function(){return M})),n.d(e,"tx",(function(){return U})),n.d(e,"t",(function(){return H}));var r=n(1),i=n.n(r);class o{constructor(){this.translationsByLocale={}}update(t,e){this.translationsByLocale[t]||(this.translationsByLocale[t]={}),Object.assign(this.translationsByLocale[t],e)}getTranslations(t){return this.translationsByLocale[t]||{}}hasTranslations(t){return!!this.translationsByLocale[t]}isStale(t){return!this.hasTranslations(t)}get(t,e){return this.getTranslations(e)[t]||""}}class s{handle(t,e,n,r){return e}}class u{handle(t,e){return t}}var c=n(9),a=n.n(c);const f={};class l{render(t,e,n){const r=(e||"").split("_")[0];if(!f[r])try{f[r]=new a.a(r)}catch(t){f[r]=new a.a}return f[r].compile(t)(n)}}var d=n(22),h=n.n(d);function p(t,e={}){return e._key?e._key:e._context?`${t}::${e._context}`:""+t}function m(t,e={}){if(e._key)return e._key;let n="";return e._context&&(n=e._context,n=n.replace(/,/g,":")),h()(`5:${t}:${n}`)}function g(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function y(t){return"[object String]"===Object.prototype.toString.call(t)}function w(t){const e=t.split("-");let n;return n=1===e.length?t:[e[0],e[1].toUpperCase()].join("_"),n}const b=["zero","one","two","few","many","other"];function v(t){const e=t.indexOf("{");if(-1===e)return[null,null];let n=t.substring(0,e).trim();if("="===n[0]){if(n=n.substring(1),Number.isNaN(parseInt(n,10))||parseInt(n,10)!==parseFloat(n))return[null,null];if(n=parseInt(n,10),n=b[n],void 0===n)return[null,null]}else if(-1===b.indexOf(n))return[null,null];return[n,t.substring(e)]}function x(t){let[e,n]=[0,!1],r=0;for(;r<t.length;){const i=t[r];if("'"===i){const e=t[r+1];"'"===e?r+=1:n?n=!1:"{"!==e&&"}"!==e||(n=!0)}else if("{"===i)n||(e+=1);else if("}"===i&&(n||(e-=1),0===e))return[t.substring(1,r),t.substring(r+1).trim()];r+=1}return[null,null]}function k(t){const[e,n]=function(t){if(!(t.length>1&&"{"===t[0]&&"}"===t[t.length-1]))return[null,null];const e=t.indexOf(",");if(-1===e)return[null,null];const n=t.indexOf(",",e+1);if(-1===n)return[null,null];const r=t.substring(1,e).trim();return"plural"!==t.substring(e+1,n).trim()?[null,null]:[r,t.substring(n+1,t.length-1).trim()]}(t);let r=n;if(null==e)return!1;const i={};let o,s;if([o,r]=v(r),null==o)return!1;if([s,r]=x(r.trim()),null==s)return!1;for(i[o]=s;r.trim();){if([o,r]=v(r.trim()),null==o)return!1;if([s,r]=x(r.trim()),null==s)return!1;i[o]=s}return(1!==Object.keys(i).length||"other"in i)&&"one"in i&&"other"in i}function S(t){return new Promise(e=>{setTimeout(()=>{e()},t)})}const E="FETCHING_TRANSLATIONS",O="TRANSLATIONS_FETCHED",C="TRANSLATIONS_FETCH_FAILED",_="LOCALE_CHANGED",T="FETCHING_LOCALES",N="LOCALES_FETCHED",j="LOCALES_FETCH_FAILED",A={};function R(t,e){A[t]=A[t]||[],A[t].push(e)}function F(t,e){const n=A[t]||[],r=n.indexOf(e);-1!==r&&n.splice(r,1)}function P(t,e,n){(A[t]||[]).forEach(t=>{t(e,n)})}class L{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 l,this.currentLocale="",this.locales=[],this.languages=[],this.childInstances=[]}init(t){const e=this;["cdsHost","token","secret","cache","filterTags","missingPolicy","errorPolicy","stringRenderer","currentLocale"].forEach(n=>{void 0!==t[n]&&(e[n]=t[n])}),this.fetchedTags={}}translate(t,e){return this.translateLocale(this.currentLocale,t,e)}translateLocale(t,e,n){try{let r=this.cache.get(p(e,n),t);if(r||(r=this.cache.get(m(e,n),t)),r&&r.startsWith("{???")&&k(e)){r=`{${e.substring(1,e.indexOf(",")).trim()}${r.substring(4)}`}let i=!1;if(r||(i=!0,r=e),n&&n._escapeVars){const e={};Object.keys(n).forEach(t=>{const r=n[t];e[t]=y(r)?g(r):r}),r=this.stringRenderer.render(r,t,e)}else r=this.stringRenderer.render(r,t,n);return i&&t&&(r=this.missingPolicy.handle(r,t)),y(r)||(r=""+r),r}catch(r){return this.errorPolicy.handle(r,""+e,t,n)}}async fetchTranslations(t,e={}){const n=e.filterTags||this.filterTags;if(e.refresh||this.cache.isStale(t)||!(!n&&this.cache.hasTranslations(t)||n&&-1!==(this.fetchedTags[t]||[]).indexOf(n))){n&&(t in this.fetchedTags||(this.fetchedTags[t]=[]),-1===this.fetchedTags[t].indexOf(n)&&this.fetchedTags[t].push(n));try{let e;P(E,{localeCode:t,filterTags:n},this);let r=202;for(;202===r;){let o=`${this.cdsHost}/content/${t}`;n&&(o=`${o}?filter[tags]=${n}`),e=await i.a.get(o,{headers:{Authorization:"Bearer "+this.token,"Accept-version":"v2","X-NATIVE-SDK":"txjs/node/3.2.2"}}),r=e.status}const{data:o}=e;if(!o||!o.data)throw P(C,{localeCode:t,filterTags:n},this),new Error("Could not fetch translations");{const e={};Object.keys(o.data).forEach(t=>{o.data[t].string&&(e[t]=o.data[t].string)}),this.cache.update(t,e),P(O,{localeCode:t,filterTags:n},this)}}catch(e){throw P(C,{localeCode:t,filterTags:n},this),e}}}async invalidateCDS(t={}){if(!this.token)throw new Error("token is not defined");if(!this.secret)throw new Error("secret is not defined");const e=t.purge?"purge":"invalidate";return(await i.a.post(`${this.cdsHost}/${e}`,{},{headers:{Authorization:`Bearer ${this.token}:${this.secret}`,"Accept-version":"v2","Content-Type":"application/json;charset=utf-8","X-NATIVE-SDK":"txjs/node/3.2.2"}})).data}async pushSource(t,e={}){if(!this.token)throw new Error("token is not defined");if(!this.secret)throw new Error("secret is not defined");const n={Authorization:`Bearer ${this.token}:${this.secret}`,"Accept-version":"v2","Content-Type":"application/json;charset=utf-8","X-NATIVE-SDK":"txjs/node/3.2.2"},r=await i.a.post(this.cdsHost+"/content",{data:t,meta:{purge:!!e.purge,override_tags:!!e.overrideTags}},{headers:n}),o=`${this.cdsHost}${r.data.data.links.job}`;if(e.noWait)return{jobUrl:o};let s={status:""};do{await S(1500);const t=await i.a.get(o,{headers:n}),{data:e}=t.data;s={...e.details||{},errors:e.errors||[],status:e.status}}while("pending"===s.status||"processing"===s.status);return{jobUrl:o,...s}}async getLocales(t={}){if(!!!t.refresh&&this.locales.length>0)return[...this.locales];if(!this.token)return[];try{let t;P(T,null,this);let e=202;for(;202===e;)t=await i.a.get(this.cdsHost+"/languages",{headers:{Authorization:"Bearer "+this.token,"Accept-version":"v2","X-NATIVE-SDK":"txjs/node/3.2.2"}}),e=t.status;const{data:n}=t;if(!n||!n.data)throw P(j,null,this),new Error("Could not fetch languages");this.languages=n.data,this.locales=this.languages.map(t=>t.code),P(N,null,this)}catch(t){throw P(j,null,this),t}return[...this.locales]}getCurrentLocale(){return this.currentLocale}isCurrent(t){return t===this.currentLocale}async setCurrentLocale(t){if(this.isCurrent(t))await this._syncInstances(this.childInstances);else{if(!t)return this.currentLocale="",await this._syncInstances(this.childInstances),void P(_,this.currentLocale,this);await this.fetchTranslations(t),this.currentLocale=t,await this._syncInstances(this.childInstances),P(_,t,this)}}async getLanguages(t={}){return await this.getLocales(t),[...this.languages]}async controllerOf(t){if(t===this)throw new Error("Cannot add self as instance");if(-1!==t.childInstances.indexOf(this))throw new Error("Cycle reference error, instance is controller of this");return this.childInstances.push(t),await this._syncInstances([t]),t}async _syncInstances(t){const e=this.getCurrentLocale();if(e)for(let n=0;n<t.length;n++)if(t[n].getCurrentLocale()!==e)try{await t[n].fetchTranslations(e)}catch(t){}t.forEach(t=>{t.getCurrentLocale()!==e&&(t.currentLocale=e,P(_,e,t))})}}const B={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 $=class{handle(t,e){return t.split(/__txnative__/).map(t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charAt(n);if(B[r]){const t=r.toLowerCase();e+="a"===t||"e"===t||"o"===t||"u"===t?B[r]+B[r]:B[r]}else e+=r}return e}).join("__txnative__")}},I=u,D=s,q=class{handle(t,e,n,r){throw t||new Error(`Error translating "${e}"`)}},z=l,M=function(t){const e=new L;return e.t=e.translate.bind(e),t&&e.init(t),e},U=new L,H=U.translate.bind(U)}])}));
|
|
9
9
|
//# sourceMappingURL=node.native.js.map
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transifex/native",
|
|
3
|
-
"version": "3.2.
|
|
4
|
-
"description": "Transifex Native
|
|
3
|
+
"version": "3.2.2",
|
|
4
|
+
"description": "i18n framework using Transifex Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transifex",
|
|
7
7
|
"i18n",
|
|
8
8
|
"l10n",
|
|
9
|
-
"localization"
|
|
9
|
+
"localization",
|
|
10
|
+
"internationalization",
|
|
11
|
+
"globalization",
|
|
12
|
+
"translation"
|
|
10
13
|
],
|
|
11
14
|
"author": "Transifex",
|
|
12
15
|
"homepage": "https://github.com/transifex/transifex-javascript/tree/master/packages/native",
|