@transifex/native 2.0.0-rc1 → 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/browser.native.js.map +1 -1
- package/dist/node.native.d.ts +9 -8
- package/dist/node.native.js +1 -1
- package/dist/node.native.js.map +1 -1
- package/package.json +2 -2
- package/src/index.d.ts +9 -8
- package/webpack.config.js +2 -2
package/dist/node.native.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export const tx
|
|
3
|
-
export const t
|
|
4
|
-
export const PseudoTranslationPolicy:
|
|
5
|
-
export const SourceStringPolicy:
|
|
6
|
-
export const SourceErrorPolicy:
|
|
7
|
-
export const ThrowErrorPolicy:
|
|
8
|
-
export const MessageFormatRenderer:
|
|
1
|
+
declare module '@transifex/native' {
|
|
2
|
+
export const tx: any;
|
|
3
|
+
export const t: any;
|
|
4
|
+
export const PseudoTranslationPolicy: any;
|
|
5
|
+
export const SourceStringPolicy: any;
|
|
6
|
+
export const SourceErrorPolicy: any;
|
|
7
|
+
export const ThrowErrorPolicy: any;
|
|
8
|
+
export const MessageFormatRenderer: any;
|
|
9
|
+
}
|
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
|