otus-localization
Version:
A translation tool for Angular i18n(angular-t9n)
1 lines • 11.5 kB
JavaScript
(self.webpackChunkotus_translation=self.webpackChunkotus_translation||[]).push([[504],{7125:(b,v,n)=>{"use strict";n.d(v,{C:()=>T});var A=n(9862);function T(l){let d=new A.LE;return l.page&&(d=d.set("page",l.page.toString())),l.entriesPerPage&&(d=d.set("entriesPerPage",l.entriesPerPage.toString())),l.sort&&l.sort.active&&l.sort.direction&&(d=d.set("sort",`${"desc"===l.sort.direction?"!":""}${l.sort.active}`)),l.filter&&(d=Object.keys(l.filter).filter(O=>l.filter[O]).reduce((O,S)=>O.set(S,l.filter[S]),d)),d}},2233:(b,v,n)=>{"use strict";n.r(v),n.d(v,{ExportComponent:()=>F});var A=n(6814),T=n(6223),l=n(2296),d=n(3680),O=n(5683),S=n(5940),u=n(8525),U=n(2939),C=n(5619),_=n(8645),a=n(8180),f=n(9773),r=n(4664),E=n(9397),x=n(5861),L=n(217),M=n(2096),P=n(7398),I=n(6306),h=n(2511),t=n(5879),$=n(9862);let y=(()=>{class p{constructor(e,o){this._translationTargetService=e,this.http=o}export(e){return this._translationTargetService.target.pipe((0,a.q)(1),(0,r.w)(o=>this._fetchUnits().pipe((0,P.U)(i=>i.map(({id:s,description:c,meaning:g,source:R,target:N})=>({Id:s,Description:c,Meaning:g,Source:R,Target:N}))),(0,r.w)(function(){var i=(0,x.Z)(function*(s){const{utils:c,writeFile:g}=yield n.e(486).then(n.bind(n,1486)),N=c.json_to_sheet(s,{header:["Id","Description","Meaning","Source","Target"]}),m=c.book_new();c.book_append_sheet(m,N,o.language),g(m,`t9n-${o.language}-${e.state||"all"}.xlsx`)});return function(s){return i.apply(this,arguments)}}()))))}exportJson(e){return this._translationTargetService.target.pipe((0,a.q)(1),(0,r.w)(o=>this._fetchUnits().pipe((0,a.q)(1),(0,P.U)(i=>Object.fromEntries(""===e.state?i.map(s=>[s.id,s.target]):i.filter(s=>s.state===e.state).map(s=>[s.id,s.target]))),(0,P.U)(i=>{let s;try{s=JSON.parse(localStorage.getItem("ids")||"[]"),Array.isArray(s)||(s=[])}catch{s=[]}const c=Object.fromEntries(s.map(R=>[R,i[R]])),g=Object.fromEntries(Object.entries(i).filter(R=>!(R[0]in c)));return{...c,...g}}),(0,r.w)(i=>{const s=new Blob([JSON.stringify(i,null,2)],{});return(0,L.saveAs)(s,`messages.${o.language}.json`),Promise.resolve()}))))}exportJsonFile(){return this._translationTargetService.target.pipe((0,a.q)(1),(0,r.w)(()=>this._fetchUnits().pipe((0,a.q)(1),(0,P.U)(e=>Object.fromEntries(e.filter(o=>"translated"===o.state).map(o=>[o.id,o.target]))),(0,P.U)(e=>{let o;try{o=JSON.parse(localStorage.getItem("ids")||"[]"),Array.isArray(o)||(o=[])}catch{o=[]}const i=Object.fromEntries(o.map(c=>[c,e[c]])),s=Object.fromEntries(Object.entries(e).filter(c=>!(c[0]in i)));return{...i,...s}}),(0,r.w)(e=>{const o=new Blob([JSON.stringify(e,null,4)],{}),i=new FormData;return i.append("file",o),this.http.post("/api/targets/saveTranslatedFile",i,{})}))),(0,I.K)(e=>{throw e}))}_fetchUnits(e=0){return this._translationTargetService.units({page:e,entriesPerPage:250}).pipe((0,r.w)(o=>o._links.next?this._fetchUnits(++e).pipe((0,P.U)(i=>o._embedded.entries.concat(i))):(0,M.of)(o._embedded.entries)))}static{this.\u0275fac=function(o){return new(o||p)(t.LFG(h.V),t.LFG($.eN))}}static{this.\u0275prov=t.Yz7({token:p,factory:p.\u0275fac})}}return p})();var G=n(9992),X=n(7289);function D(p,w){1&p&&t._UZ(0,"mat-spinner")}let F=(()=>{class p{constructor(e,o,i,s,c,g){this._exportService=e,this.common=i,this.http=s,this.snackBar=c,this._importService=g,this.loading=new C.X(!1),this.destroy$=new _.x,this.configuration=o.group({state:"translated"})}export(){this.loading.next(!0),this.common.fileFormat.pipe((0,a.q)(1),(0,f.R)(this.destroy$),(0,r.w)(e=>"Excel"===e?this._exportService.export(this.configuration.value):this._exportService.exportJson(this.configuration.value))).subscribe(()=>{this.loading.next(!1)})}ngOnDestroy(){this.destroy$.next(!0)}updateHandler(){this.common.loading$.next(!0),this.http.get("/api/targets/loadTranslatedFile",{responseType:"arraybuffer"}).pipe((0,E.b)(()=>{this.common.loading$.next(!0)})).subscribe({next:e=>{const o=[new File([e],"target.json")];this._importService.importJson(o,"translated").then(()=>{this.snackBar.open("Load Success","",{horizontalPosition:"center",verticalPosition:"top",duration:2e3}),this._exportService.exportJsonFile().subscribe({next:i=>{i.code?this.snackBar.open("Update Failed","ERROR",{horizontalPosition:"center",verticalPosition:"top",duration:3e3}):this.snackBar.open("Update Successs","",{horizontalPosition:"center",verticalPosition:"top",duration:2e3})},error:i=>{console.log(i),this.snackBar.open("Update Failed","ERROR",{horizontalPosition:"center",verticalPosition:"top",duration:3e3}),this.common.loading$.next(!1)},complete:()=>{this.common.loading$.next(!1)}})}).catch(()=>{this.snackBar.open("Load Failed","ERROR",{horizontalPosition:"center",verticalPosition:"top",duration:3e3})})},error:()=>{this.snackBar.open("Load Failed","ERROR",{horizontalPosition:"center",verticalPosition:"top",duration:3e3})}})}commitHandler(){this.common.loading$.next(!0),this.http.get("/api/targets/gitCommit").subscribe({next:e=>{e.code?this.snackBar.open("Commit Failed","ERROR",{horizontalPosition:"center",verticalPosition:"top",duration:3e3}):this.snackBar.open("\u63d0\u4ea4\u6210\u529f","",{horizontalPosition:"center",verticalPosition:"top",duration:2e3})},error:e=>{console.log(e),this.snackBar.open("Commit Failed","ERROR",{horizontalPosition:"center",verticalPosition:"top",duration:3e3}),this.common.loading$.next(!1)},complete:()=>{this.common.loading$.next(!1)}})}syncHandler(){this.common.loading$.next(!0),this.http.get("/api/targets/syncLocalization").subscribe({next:e=>{e.code?this.snackBar.open("Sync Failed","ERROR",{horizontalPosition:"center",verticalPosition:"top",duration:3e3}):this.snackBar.open("\u540c\u6b65\u6210\u529f","",{horizontalPosition:"center",verticalPosition:"top",duration:2e3})},error:e=>{console.log(e),this.snackBar.open("Sync Failed","ERROR",{horizontalPosition:"center",verticalPosition:"top",duration:3e3}),this.common.loading$.next(!1)},complete:()=>{this.common.loading$.next(!1)}})}static{this.\u0275fac=function(o){return new(o||p)(t.Y36(y),t.Y36(T.QS),t.Y36(X.v),t.Y36($.eN),t.Y36(U.ux),t.Y36(G.Y))}}static{this.\u0275cmp=t.Xpm({type:p,selectors:[["t9n-export"]],standalone:!0,features:[t._Bn([y,G.Y]),t.jDz],decls:29,vars:10,consts:function(){let e,o,i,s,c,g,R,N;return e=$localize`:␟56ce628f52f921438948b48e5da9ad842efb392f␟4307494807191907833:Export translation units to ${"\ufffd0\ufffd"}:INTERPOLATION:`,o=$localize`:␟684798705c72c14b4f99f3d190c07a43157afa66␟5724896985467124877:Export all translation units or filter by translation state.`,i=$localize`:␟dfc3c34e182ea73c5d784ff7c8135f087992dac1␟1616102757855967475:All`,s=$localize`:␟53647666ac3abdac9ad0cbc0564cc8a2ead09c04␟2937311350146031865:Initial`,c=$localize`:␟2d5820ffb1bf91459a6048abaef0dbb811b343cc␟5706198276541510303:Translated`,g=$localize`:␟a4a1911975d1421d0a019e902c93e29f540ada91␟4467880638322247833:Reviewed`,R=$localize`:␟5233e7292acd46d01dfa207d4921e4a723110ed2␟4609200447119745819:Final`,N=$localize`:␟5f19586aba912ec6eb123ec5ab609a3bcc073066␟7462301153729425254:Export`,[e,["mat-raised-button","","color","primary",2,"margin-right","16px",3,"click"],["mat-raised-button","",2,"margin-right","16px",3,"click"],["mat-raised-button","",3,"click"],o,[3,"formGroup","ngSubmit"],["formControlName","state"],["value",""],i,["value","initial"],s,["value","translated"],c,["value","reviewed"],g,["value","final"],R,["mat-raised-button","",3,"disabled"],N,[4,"ngIf"]]},template:function(o,i){1&o&&(t.TgZ(0,"h2"),t.SDv(1,0),t.ALo(2,"async"),t.qZA(),t.TgZ(3,"button",1),t.NdJ("click",function(){return i.updateHandler()}),t._uU(4," Auto Update(\u66f4\u65b0\u6587\u4ef6)\n"),t.qZA(),t.TgZ(5,"button",2),t.NdJ("click",function(){return i.commitHandler()}),t._uU(6,"Commit(\u63d0\u4ea4)"),t.qZA(),t.TgZ(7,"button",3),t.NdJ("click",function(){return i.syncHandler()}),t._uU(8,"Sync(\u5c06\u63d0\u4ea4\u540c\u6b65\u5230\u53f0\u5f0f\u673a)"),t.qZA(),t.TgZ(9,"p"),t.SDv(10,4),t.qZA(),t.TgZ(11,"form",5),t.NdJ("ngSubmit",function(){return i.export()}),t.TgZ(12,"mat-form-field")(13,"mat-select",6)(14,"mat-option",7),t.SDv(15,8),t.qZA(),t.TgZ(16,"mat-option",9),t.SDv(17,10),t.qZA(),t.TgZ(18,"mat-option",11),t.SDv(19,12),t.qZA(),t.TgZ(20,"mat-option",13),t.SDv(21,14),t.qZA(),t.TgZ(22,"mat-option",15),t.SDv(23,16),t.qZA()()(),t.TgZ(24,"button",17),t.SDv(25,18),t.ALo(26,"async"),t.qZA()(),t.YNc(27,D,1,0,"mat-spinner",19),t.ALo(28,"async")),2&o&&(t.xp6(2),t.pQV(t.lcZ(2,4,i.common.fileFormat)),t.QtT(1),t.xp6(9),t.Q6J("formGroup",i.configuration),t.xp6(13),t.Q6J("disabled",t.lcZ(26,6,i.loading)),t.xp6(3),t.Q6J("ngIf",t.lcZ(28,8,i.loading)))},dependencies:[T.UX,T._Y,T.JJ,T.JL,T.sg,T.u,O.lN,O.KE,u.LD,u.gD,d.ey,d.Ng,l.ot,l.lW,A.O5,S.Cq,S.Ou,A.Ov,U.ZX],styles:["[_nghost-%COMP%]{display:block;padding:0 1.5rem}form[_ngcontent-%COMP%]{display:inline-flex;flex-direction:column;margin-bottom:1rem}"],changeDetection:0})}}return p})()},217:function(b,v){var n,T;void 0!==(T="function"==typeof(n=function(){"use strict";function d(_,a,f){var r=new XMLHttpRequest;r.open("GET",_),r.responseType="blob",r.onload=function(){C(r.response,a,f)},r.onerror=function(){console.error("could not download file")},r.send()}function O(_){var a=new XMLHttpRequest;a.open("HEAD",_,!1);try{a.send()}catch{}return 200<=a.status&&299>=a.status}function S(_){try{_.dispatchEvent(new MouseEvent("click"))}catch{var a=document.createEvent("MouseEvents");a.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),_.dispatchEvent(a)}}var u="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,U=u.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),C=u.saveAs||("object"!=typeof window||window!==u?function(){}:"download"in HTMLAnchorElement.prototype&&!U?function(_,a,f){var r=u.URL||u.webkitURL,E=document.createElement("a");E.download=a=a||_.name||"download",E.rel="noopener","string"==typeof _?(E.href=_,E.origin===location.origin?S(E):O(E.href)?d(_,a,f):S(E,E.target="_blank")):(E.href=r.createObjectURL(_),setTimeout(function(){r.revokeObjectURL(E.href)},4e4),setTimeout(function(){S(E)},0))}:"msSaveOrOpenBlob"in navigator?function(_,a,f){if(a=a||_.name||"download","string"!=typeof _)navigator.msSaveOrOpenBlob(function l(_,a){return typeof a>"u"?a={autoBom:!1}:"object"!=typeof a&&(console.warn("Deprecated: Expected third argument to be a object"),a={autoBom:!a}),a.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(_.type)?new Blob(["\ufeff",_],{type:_.type}):_}(_,f),a);else if(O(_))d(_,a,f);else{var r=document.createElement("a");r.href=_,r.target="_blank",setTimeout(function(){S(r)})}}:function(_,a,f,r){if((r=r||open("","_blank"))&&(r.document.title=r.document.body.innerText="downloading..."),"string"==typeof _)return d(_,a,f);var E="application/octet-stream"===_.type,x=/constructor/i.test(u.HTMLElement)||u.safari,L=/CriOS\/[\d]+/.test(navigator.userAgent);if((L||E&&x||U)&&typeof FileReader<"u"){var M=new FileReader;M.onloadend=function(){var h=M.result;h=L?h:h.replace(/^data:[^;]*;/,"data:attachment/file;"),r?r.location.href=h:location=h,r=null},M.readAsDataURL(_)}else{var P=u.URL||u.webkitURL,I=P.createObjectURL(_);r?r.location=I:location.href=I,r=null,setTimeout(function(){P.revokeObjectURL(I)},4e4)}});u.saveAs=C.saveAs=C,b.exports=C})?n.apply(v,[]):n)&&(b.exports=T)}}]);