fill-pot-po
Advanced tools
Comparing version
@@ -48,3 +48,3 @@ import Vinyl from 'vinyl'; | ||
*/ | ||
declare const _default: (options: Options) => PreparedOptions; | ||
declare const _default: (options: Options, defaultWriteFiles?: boolean) => PreparedOptions; | ||
@@ -51,0 +51,0 @@ declare const testOptions: { |
@@ -1,4 +0,4 @@ | ||
var Pe=Object.create;var A=Object.defineProperty;var Se=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty;var _e=(e,r)=>{for(var t in r)A(e,t,{get:r[t],enumerable:!0})},ee=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ye(r))!we.call(e,o)&&o!==t&&A(e,o,{get:()=>r[o],enumerable:!(n=Se(r,o))||n.enumerable});return e};var m=(e,r,t)=>(t=e!=null?Pe(be(e)):{},ee(r||!e||!e.__esModule?A(t,"default",{value:e,enumerable:!0}):t,e)),xe=e=>ee(A({},"__esModule",{value:!0}),e);var Le={};_e(Le,{default:()=>Ee,prepareOptions:()=>R,sync:()=>Q,testOptions:()=>he});module.exports=xe(Le);var Re=()=>typeof document>"u"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,y=Re();var H=m(require("fs")),B=m(require("vinyl")),ge=require("safe-buffer"),z=m(require("gettext-parser")),v=m(require("ansi-colors")),Oe=m(require("color-support"));var te=m(require("util")),j=m(require("ansi-colors")),re=m(require("color-support")),ne=require("fs");j.default.enabled=!!(0,re.default)().hasBasic;var $e=JSON.parse((0,ne.readFileSync)(new URL("../package.json",y),"utf-8")),M=class{message;category;constructor(r,t=""){this.message=r,this.category=t.slice(0,1).toUpperCase()+t.slice(1).toLowerCase()}toString(){return`${j.default.cyan($e.name)} ${j.default.bold.red(`${this.category}Error`)} ${this.message}`}[te.inspect.custom](){return this.toString()}},b=M;var x=require("path"),le=m(require("vinyl"));var se=m(require("vinyl"));var _=e=>Object.prototype.toString.call(e)==="[object Array]",oe=e=>Object.prototype.toString.call(e)==="[object Object]",g=e=>Object.prototype.toString.call(e)==="[object String]",ie=e=>Object.prototype.toString.call(e)==="[object Boolean]",E=e=>_(e)?!!e.reduce((r,t)=>g(t)&&r,!0):!1,ae=e=>_(e)?!!e.reduce((r,t)=>se.default.isVinyl(t)&&r,!0):!1,Z=(e,r)=>{if(!g(e)||!g(r))throw new Error("pathLineSort: a or b not a string");let t,n;if([e,t]=e.split(":"),[r,n]=r.split(":"),e=e.replace(/(^\/|\/$)/g,""),r=r.replace(/(^\/|\/$)/g,""),e===r){if((!t||t==="")&&n&&n.length)return-1;if((!n||n==="")&&t&&t.length)return 1;if(t&&t.length&&n&&n.length)return parseInt(t)-parseInt(n)}let o=e.split("/"),s=r.split("/"),i=o.length,l=s.length,u=Math.max(i,l);for(let c=0;c<u;c++){if(c>=l||!s[c])return-1;if(c>=i||!o[c])return 1;let[f,d]=o[c].split(/\.(?=[^.]*$)/g),[O,h]=s[c].split(/\.(?=[^.]*$)/g),F=d&&d!=="",D=h&&h!=="";if(!F&&D)return-1;if(F&&!D||f.toUpperCase()>O.toUpperCase())return 1;if(f.toUpperCase()<O.toUpperCase())return-1;if(d&&h){if(d.toUpperCase()>h.toUpperCase())return 1;if(d.toUpperCase()<h.toUpperCase())return-1}}return 0};var P=class extends b{constructor(r){super(r,"options")}},ve=e=>{if(oe(e)){if("potSources"in e&&!g(e.potSources)&&!E(e.potSources)&&!le.default.isVinyl(e.potSources)&&!ae(e.potSources))throw new P("Option potSources should be a string or Vinyl object, or an array of those.");if("poSources"in e&&e.poSources!==null&&!g(e.poSources)&&!E(e.poSources))throw new P("Option poSources should be a glob string or glob array.");if("wrapLength"in e&&(typeof e.wrapLength!="number"||0>=e.wrapLength))throw new P("If set, option wrapLength should be a number higher than 0.");let r=["srcDir","destDir","domain"];for(let n of r)if(n in e)if(g(e[n])){if(e[n].match(/\n/))throw new P(`Option ${n} can't contain newline characters.`)}else throw new P(`Option ${n} should be a string.`);let t=["writeFiles","returnPOT","domainFromPOTPath","domainInPOPath","defaultContextAsFallback","appendNonIncludedFromPO","includePORevisionDate","includeGenerator","logResults"];for(let n of t)if(n in e&&!ie(e[n]))throw new P(`Option ${n} should be a boolean.`)}else{if(g(e)||E(e))return{poSources:e};if(typeof e<"u")throw new P("Options should be an object of options, glob string or glob array.");return{}}return e},ke=e=>{let r=(0,x.resolve)();return typeof e.potSources<"u"&&(_(e.potSources)||(e.potSources=[e.potSources]),e.potSources=e.potSources.map(t=>g(t)?t.trim():t).filter(t=>!g(t)||t.length>0)),typeof e.poSources<"u"&&e.poSources!==null&&(_(e.poSources)||(e.poSources=[e.poSources]),e.poSources=e.poSources.map(t=>t.trim()).filter(t=>t.length>0)),e.srcDir&&(e.srcDir=(0,x.resolve)(e.srcDir.trim()),e.srcDir=`${(0,x.relative)(r,e.srcDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.destDir&&(e.destDir=(0,x.resolve)(e.destDir.trim()),e.destDir=`${(0,x.relative)(r,e.destDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.wrapLength&&(e.wrapLength=Math.ceil(e.wrapLength)),e},R=e=>{e=ve(e),e=ke(e);let t=Object.assign({},{potSources:["**/*.pot","!node_modules/**"],poSources:null,srcDir:"",domainInPOPath:!0,domainFromPOTPath:!0,domain:"",srcGlobOptions:{},wrapLength:77,defaultContextAsFallback:!1,appendNonIncludedFromPO:!1,includePORevisionDate:!1,includeGenerator:!0,returnPOT:!1,writeFiles:!0,destDir:"",logResults:!1,_pot_input_files:[],_po_input_files:[]},e);if(t.domainFromPOTPath===!1&&t.domainInPOPath===!0&&0>=t.domain.length)throw new P("Option domain should be a non-empty string when domainFromPOTPath is false and domainInPOPath is true.");if(t.returnPOT&&!t.writeFiles)throw new P("If option returnPOT is true, option writeFiles must be true or no PO files will be generated.");return t};var $=require("path"),pe=require("safe-buffer"),q=require("matched"),C=require("fs"),ue=m(require("gettext-parser")),fe=m(require("vinyl")),S=m(require("ansi-colors")),me=m(require("color-support"));var de=require("fs");S.default.enabled=!!(0,me.default)().hasBasic;var ce=JSON.parse((0,de.readFileSync)(new URL("../package.json",y),"utf-8")),L=e=>{if(_(e.potSources)&&e.potSources.length&&g(e.potSources[0])&&(e.potSources=(0,q.sync)(e.potSources)),e._potFilenames=e.potSources.map(r=>g(r)?r:r.path),0>=e.potSources.length)throw new b("No POT files found to process.");if(1<e.potSources.length&&e.poSources)throw new b(`When processing multiple POT files, leave option poSources empty. | ||
Else, the same generated PO files will be overwritten for each POT file.`,"options");return e},I=(e,r)=>{let t=(0,$.basename)(e,".pot"),n=r.domainFromPOTPath?t:r.domain,o=r.srcDir?r.srcDir:`${(0,$.dirname)(e)}/`,s=[];if(r.poSources)s.push(...r.poSources);else{let l="[a-z][a-z]?([a-z])?(_[A-Z][A-Z]?([A-Z]))?(_formal)",u=r.domainInPOPath?`${n}-`:"";s.push(`${o}${u}${l}.po`)}return(0,q.sync)(s,r.srcGlobOptions).sort(Z)},U=(e,r,t,n)=>{let o=JSON.parse(JSON.stringify(e));o=Ce(o,r,n);let s=Fe(o,n),i=(0,$.basename)(t);return n.writeFiles&&De(`${n.destDir}${i}`,s),new fe.default({contents:pe.Buffer.from(s),path:i})},Ce=(e,r,t)=>{var n,o,s,i,l,u,c,f,d,O,h,F,D;for(let[a,T]of Object.entries(e.translations))for(let[p,w]of Object.entries(T))r.translations[a]&&r.translations[a][p]&&r.translations[a][p].msgstr.length===w.msgstr.length?e.translations[a][p].msgstr=[...r.translations[a][p].msgstr]:t.defaultContextAsFallback&&r.translations[""]&&r.translations[""][p]&&r.translations[""][p].msgstr.length===w.msgstr.length&&(e.translations[a][p].msgstr=[...r.translations[""][p].msgstr],e.translations[a][p].comments={...((n=e.translations[a][p])==null?void 0:n.comments)??{},flag:["fuzzy",(s=(o=e.translations[a][p])==null?void 0:o.comments)==null?void 0:s.flag].filter(J=>J).join(", ")},r.translations[""][p].comments={...((i=r.translations[""][p])==null?void 0:i.comments)??{},translator:[`NOTE: re-used for same message, but with context '${a}'`,(u=(l=r.translations[""][p])==null?void 0:l.comments)==null?void 0:u.translator].filter(J=>J).join(` | ||
`)});if(t.appendNonIncludedFromPO)for(let[a,T]of Object.entries(r.translations)){e.translations[a]||(e.translations[a]={});for(let[p,w]of Object.entries(T))e.translations[a][p]||(e.translations[a][p]=w,e.translations[a][p].comments={...((c=e.translations[a][p])==null?void 0:c.comments)??{},...(d=(f=e.translations[a][p])==null?void 0:f.comments)!=null&&d.translator&&((O=w==null?void 0:w.comments)!=null&&O.translator.match(/^DEPRECATED$/gm))?{}:{translator:g((F=(h=e.translations[a][p])==null?void 0:h.comments)==null?void 0:F.translator)?`DEPRECATED | ||
`+(((D=e.translations[a][p].comments)==null?void 0:D.translator)??""):"DEPRECATED"}})}if(t.includePORevisionDate){let a=new Date,T=[`${a.getUTCFullYear()}`,`-${String(a.getUTCMonth()+1).padStart(2,"0")}`,`-${String(a.getUTCDate()).padStart(2,"0")}`,` ${String(a.getUTCHours()).padStart(2,"0")}`,`:${String(a.getUTCMinutes()).padStart(2,"0")}`,"+0000"].join("");e.headers["po-revision-date"]=T}return t.includeGenerator&&(e.headers["X-Generator"]=`${ce.name}/${ce.version}`),e},Fe=(e,r)=>ue.default.po.compile(e,{foldLength:r.wrapLength,sort:(t,n)=>{var i,l,u,c,f,d;let o=(l=(i=n.comments)==null?void 0:i.translator)==null?void 0:l.match(/^DEPRECATED$/gm),s=(c=(u=t.comments)==null?void 0:u.translator)==null?void 0:c.match(/^DEPRECATED$/gm);return!s&&o?-1:s&&!o?1:(f=n.comments)!=null&&f.reference?(d=t.comments)!=null&&d.reference?(t=t.comments.reference.trim().split(/\s+/)[0],n=n.comments.reference.trim().split(/\s+/)[0],Z(t,n)):1:-1}}),De=(e,r)=>{let t=(0,$.dirname)(e);(0,C.existsSync)(t)||(0,C.mkdirSync)(t,{recursive:!0}),(0,C.writeFileSync)(e,r.toString())},N=(e,r,t,n)=>{e.forEach((o,s)=>{var f,d;let i=(0,$.basename)(o),l=(f=r[s])==null?void 0:f.map(O=>O),u=(d=t[s])==null?void 0:d.map(O=>O.path),c=l.reduce((O,h)=>Math.max(h.length,O),0);console.log(""),u&&u.length?(console.log(` ${S.default.bold.green("\u25A0")} ${S.default.white(i)}`),u.forEach((O,h)=>{console.log([" ",`${S.default.cyan(l[h].padEnd(c," "))}`,` ${S.default.gray("\u2014\u25BA")} `,`${S.default.yellow(n)}${S.default.yellow(O)}`].join(""))})):(console.log(` ${S.default.gray("\u25A0")} ${S.default.white(i)}`),console.log(` ${S.default.gray("No PO files found.")}`))}),console.log("")};v.default.enabled=!!(0,Oe.default)().hasBasic;var Te=(e,r,t)=>{H.readFile(e,(n,o)=>{n&&t(n);let s=z.default.po.parse(o);r(s)})},Ve=(e,r,t,n)=>{let o=B.default.isVinyl(e),s=o?e.path:e,i=I(s,r);if(i.length)if(o){r.returnPOT&&r._pot_input_files.push(e);let l=z.default.po.parse(e.contents);t([l,i])}else H.readFile(s,(l,u)=>{l&&n(l),r.returnPOT&&r._pot_input_files.push(new B.default({contents:ge.Buffer.from(u),path:s}));let c=z.default.po.parse(u);t([c,i])});else t(null)},k=(e,r)=>{if(typeof e!="function")throw new b("fillPotPo() requires a callback function as first parameter");let t;try{t=L(R(r))}catch(n){e([!1,n.toString()]);return}t._pot_input_files=[],t._po_input_files=[],Promise.all(t.potSources.map(n=>{let o=B.default.isVinyl(n)?n.relative:n;return new Promise((s,i)=>{Ve(n,t,s,i)}).then(async s=>{if(!s)return t._po_input_files.push([]),[];let i=s[0],l=s[1];return t._po_input_files.push(l),await Promise.all(l.map(c=>new Promise((f,d)=>{Te(c,f,d)}).then(f=>U(i,f,c,t)).catch(f=>{throw new b(`${v.default.bold(f.message)} ${v.default.gray(`(PO ${v.default.white(c)})`)}`)})))}).catch(s=>{throw new b(`${s.message} ${v.default.gray(`(POT ${v.default.white(o)})`)}`)})})).then(n=>{if(t.logResults&&N(t._potFilenames,t._po_input_files,n,t.destDir),t.returnPOT){e([!0,t._pot_input_files]);return}e([!0,[].concat(...n)])}).catch(n=>{e([!1,n.toString()])}).finally(()=>{t._pot_input_files=[],t._po_input_files=[]})};var Y=m(require("fs")),W=m(require("vinyl")),K=m(require("gettext-parser"));var G=[],X=[],V=[],Ae=(e,r,t)=>{let n=[];for(let o of e){let s=Y.readFileSync(o).toString(),i=K.default.po.parse(s);n.push(U(r,i,o,t))}V.push(n)},je=(e,r)=>{let t=W.default.isVinyl(e),n=t?e.path:e,o=I(n,r);if(X.push(o),o.length){let s="";if(t)r.returnPOT&&G.push(e),s=e.contents;else{let l=Y.readFileSync(n);s=l.toString(),r.returnPOT&&G.push(new W.default({contents:l,path:n}))}let i=K.default.po.parse(s);Ae(o,i,r)}else V.push([])},Q=e=>{G=[],X=[],V=[];let r=L(R(e));return r.potSources.forEach(t=>{je(t,r)}),r.logResults&&N(r._potFilenames,X,V,r.destDir),r.returnPOT?G:[].concat(...V)};var he={wrapLength:77,defaultContextAsFallback:!0,appendNonIncludedFromPO:!0,includePORevisionDate:!1,includeGenerator:!1},Ee=k;typeof module<"u"&&(k.sync=Q,k.testOptions=he,k.prepareOptions=R,module.exports=k,module.exports.default=k);0&&(module.exports={prepareOptions,sync,testOptions}); | ||
var Pe=Object.create;var A=Object.defineProperty;var Se=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty;var _e=(e,t)=>{for(var r in t)A(e,r,{get:t[r],enumerable:!0})},ee=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ye(t))!we.call(e,o)&&o!==r&&A(e,o,{get:()=>t[o],enumerable:!(n=Se(t,o))||n.enumerable});return e};var m=(e,t,r)=>(r=e!=null?Pe(be(e)):{},ee(t||!e||!e.__esModule?A(r,"default",{value:e,enumerable:!0}):r,e)),xe=e=>ee(A({},"__esModule",{value:!0}),e);var Le={};_e(Le,{default:()=>Ee,prepareOptions:()=>R,sync:()=>Q,testOptions:()=>he});module.exports=xe(Le);var Re=()=>typeof document>"u"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,y=Re();var H=m(require("fs")),B=m(require("vinyl")),ge=require("safe-buffer"),z=m(require("gettext-parser")),v=m(require("ansi-colors")),Oe=m(require("color-support"));var te=m(require("util")),j=m(require("ansi-colors")),re=m(require("color-support")),ne=require("fs");j.default.enabled=!!(0,re.default)().hasBasic;var $e=JSON.parse((0,ne.readFileSync)(new URL("../package.json",y),"utf-8")),M=class{constructor(t,r=""){this.message=t,this.category=r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()}toString(){return`${j.default.cyan($e.name)} ${j.default.bold.red(`${this.category}Error`)} ${this.message}`}[te.inspect.custom](){return this.toString()}},b=M;var x=require("path"),le=m(require("vinyl"));var se=m(require("vinyl"));var _=e=>Object.prototype.toString.call(e)==="[object Array]",oe=e=>Object.prototype.toString.call(e)==="[object Object]",g=e=>Object.prototype.toString.call(e)==="[object String]",ie=e=>Object.prototype.toString.call(e)==="[object Boolean]",E=e=>_(e)?!!e.reduce((t,r)=>g(r)&&t,!0):!1,ae=e=>_(e)?!!e.reduce((t,r)=>se.default.isVinyl(r)&&t,!0):!1,Z=(e,t)=>{if(!g(e)||!g(t))throw new Error("pathLineSort: a or b not a string");let r,n;if([e,r]=e.split(":"),[t,n]=t.split(":"),e=e.replace(/(^\/|\/$)/g,""),t=t.replace(/(^\/|\/$)/g,""),e===t){if((!r||r==="")&&n&&n.length)return-1;if((!n||n==="")&&r&&r.length)return 1;if(r&&r.length&&n&&n.length)return parseInt(r)-parseInt(n)}let o=e.split("/"),s=t.split("/"),i=o.length,l=s.length,u=Math.max(i,l);for(let c=0;c<u;c++){if(c>=l||!s[c])return-1;if(c>=i||!o[c])return 1;let[f,d]=o[c].split(/\.(?=[^.]*$)/g),[O,h]=s[c].split(/\.(?=[^.]*$)/g),F=d&&d!=="",D=h&&h!=="";if(!F&&D)return-1;if(F&&!D||f.toUpperCase()>O.toUpperCase())return 1;if(f.toUpperCase()<O.toUpperCase())return-1;if(d&&h){if(d.toUpperCase()>h.toUpperCase())return 1;if(d.toUpperCase()<h.toUpperCase())return-1}}return 0};var P=class extends b{constructor(t){super(t,"options")}},ve=e=>{if(oe(e)){if("potSources"in e&&!g(e.potSources)&&!E(e.potSources)&&!le.default.isVinyl(e.potSources)&&!ae(e.potSources))throw new P("Option potSources should be a string or Vinyl object, or an array of those.");if("poSources"in e&&e.poSources!==null&&!g(e.poSources)&&!E(e.poSources))throw new P("Option poSources should be a glob string or glob array.");if("wrapLength"in e&&(typeof e.wrapLength!="number"||0>=e.wrapLength))throw new P("If set, option wrapLength should be a number higher than 0.");let t=["srcDir","destDir","domain"];for(let n of t)if(n in e)if(g(e[n])){if(e[n].match(/\n/))throw new P(`Option ${n} can't contain newline characters.`)}else throw new P(`Option ${n} should be a string.`);let r=["writeFiles","returnPOT","domainFromPOTPath","domainInPOPath","defaultContextAsFallback","appendNonIncludedFromPO","includePORevisionDate","includeGenerator","logResults"];for(let n of r)if(n in e&&!ie(e[n]))throw new P(`Option ${n} should be a boolean.`)}else{if(g(e)||E(e))return{poSources:e};if(typeof e<"u")throw new P("Options should be an object of options, glob string or glob array.");return{}}return e},ke=e=>{let t=(0,x.resolve)();return typeof e.potSources<"u"&&(_(e.potSources)||(e.potSources=[e.potSources]),e.potSources=e.potSources.map(r=>g(r)?r.trim():r).filter(r=>!g(r)||r.length>0)),typeof e.poSources<"u"&&e.poSources!==null&&(_(e.poSources)||(e.poSources=[e.poSources]),e.poSources=e.poSources.map(r=>r.trim()).filter(r=>r.length>0)),e.srcDir&&(e.srcDir=(0,x.resolve)(e.srcDir.trim()),e.srcDir=`${(0,x.relative)(t,e.srcDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.destDir&&(e.destDir=(0,x.resolve)(e.destDir.trim()),e.destDir=`${(0,x.relative)(t,e.destDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.wrapLength&&(e.wrapLength=Math.ceil(e.wrapLength)),e},R=(e,t=!0)=>{e=ve(e),e=ke(e);let n=Object.assign({},{potSources:["**/*.pot","!node_modules/**"],poSources:null,srcDir:"",domainInPOPath:!0,domainFromPOTPath:!0,domain:"",srcGlobOptions:{},wrapLength:77,defaultContextAsFallback:!1,appendNonIncludedFromPO:!1,includePORevisionDate:!1,includeGenerator:!0,returnPOT:!1,writeFiles:!!t,destDir:"",logResults:!1,_pot_input_files:[],_po_input_files:[]},e);if(n.domainFromPOTPath===!1&&n.domainInPOPath===!0&&0>=n.domain.length)throw new P("Option domain should be a non-empty string when domainFromPOTPath is false and domainInPOPath is true.");if(n.returnPOT&&!n.writeFiles)throw new P("If option returnPOT is true, option writeFiles must be true or no PO files will be generated.");return n};var $=require("path"),pe=require("safe-buffer"),q=require("matched"),C=require("fs"),ue=m(require("gettext-parser")),fe=m(require("vinyl")),S=m(require("ansi-colors")),me=m(require("color-support"));var de=require("fs");S.default.enabled=!!(0,me.default)().hasBasic;var ce=JSON.parse((0,de.readFileSync)(new URL("../package.json",y),"utf-8")),L=e=>{if(_(e.potSources)&&e.potSources.length&&g(e.potSources[0])&&(e.potSources=(0,q.sync)(e.potSources)),e._potFilenames=e.potSources.map(t=>g(t)?t:t.path),0>=e.potSources.length)throw new b("No POT files found to process.");if(1<e.potSources.length&&e.poSources)throw new b(`When processing multiple POT files, leave option poSources empty. | ||
Else, the same generated PO files will be overwritten for each POT file.`,"options");return e},I=(e,t)=>{let r=(0,$.basename)(e,".pot"),n=t.domainFromPOTPath?r:t.domain,o=t.srcDir?t.srcDir:`${(0,$.dirname)(e)}/`,s=[];if(t.poSources)s.push(...t.poSources);else{let l="[a-z][a-z]?([a-z])?(_[A-Z][A-Z]?([A-Z]))?(_formal)",u=t.domainInPOPath?`${n}-`:"";s.push(`${o}${u}${l}.po`)}return(0,q.sync)(s,t.srcGlobOptions).sort(Z)},U=(e,t,r,n)=>{let o=JSON.parse(JSON.stringify(e));o=Ce(o,t,n);let s=Fe(o,n),i=(0,$.basename)(r);return n.writeFiles&&De(`${n.destDir}${i}`,s),new fe.default({contents:pe.Buffer.from(s),path:i})},Ce=(e,t,r)=>{var n,o,s,i,l,u,c,f,d,O,h,F,D;for(let[a,T]of Object.entries(e.translations))for(let[p,w]of Object.entries(T))t.translations[a]&&t.translations[a][p]&&t.translations[a][p].msgstr.length===w.msgstr.length?e.translations[a][p].msgstr=[...t.translations[a][p].msgstr]:r.defaultContextAsFallback&&t.translations[""]&&t.translations[""][p]&&t.translations[""][p].msgstr.length===w.msgstr.length&&(e.translations[a][p].msgstr=[...t.translations[""][p].msgstr],e.translations[a][p].comments={...((n=e.translations[a][p])==null?void 0:n.comments)??{},flag:["fuzzy",(s=(o=e.translations[a][p])==null?void 0:o.comments)==null?void 0:s.flag].filter(J=>J).join(", ")},t.translations[""][p].comments={...((i=t.translations[""][p])==null?void 0:i.comments)??{},translator:[`NOTE: re-used for same message, but with context '${a}'`,(u=(l=t.translations[""][p])==null?void 0:l.comments)==null?void 0:u.translator].filter(J=>J).join(` | ||
`)});if(r.appendNonIncludedFromPO)for(let[a,T]of Object.entries(t.translations)){e.translations[a]||(e.translations[a]={});for(let[p,w]of Object.entries(T))e.translations[a][p]||(e.translations[a][p]=w,e.translations[a][p].comments={...((c=e.translations[a][p])==null?void 0:c.comments)??{},...(d=(f=e.translations[a][p])==null?void 0:f.comments)!=null&&d.translator&&((O=w==null?void 0:w.comments)!=null&&O.translator.match(/^DEPRECATED$/gm))?{}:{translator:g((F=(h=e.translations[a][p])==null?void 0:h.comments)==null?void 0:F.translator)?`DEPRECATED | ||
`+(((D=e.translations[a][p].comments)==null?void 0:D.translator)??""):"DEPRECATED"}})}if(r.includePORevisionDate){let a=new Date,T=[`${a.getUTCFullYear()}`,`-${String(a.getUTCMonth()+1).padStart(2,"0")}`,`-${String(a.getUTCDate()).padStart(2,"0")}`,` ${String(a.getUTCHours()).padStart(2,"0")}`,`:${String(a.getUTCMinutes()).padStart(2,"0")}`,"+0000"].join("");e.headers["po-revision-date"]=T}return r.includeGenerator&&(e.headers["X-Generator"]=`${ce.name}/${ce.version}`),e},Fe=(e,t)=>ue.default.po.compile(e,{foldLength:t.wrapLength,sort:(r,n)=>{var i,l,u,c,f,d;let o=(l=(i=n.comments)==null?void 0:i.translator)==null?void 0:l.match(/^DEPRECATED$/gm),s=(c=(u=r.comments)==null?void 0:u.translator)==null?void 0:c.match(/^DEPRECATED$/gm);return!s&&o?-1:s&&!o?1:(f=n.comments)!=null&&f.reference?(d=r.comments)!=null&&d.reference?(r=r.comments.reference.trim().split(/\s+/)[0],n=n.comments.reference.trim().split(/\s+/)[0],Z(r,n)):1:-1}}),De=(e,t)=>{let r=(0,$.dirname)(e);(0,C.existsSync)(r)||(0,C.mkdirSync)(r,{recursive:!0}),(0,C.writeFileSync)(e,t.toString())},N=(e,t,r,n)=>{e.forEach((o,s)=>{var f,d;let i=(0,$.basename)(o),l=(f=t[s])==null?void 0:f.map(O=>O),u=(d=r[s])==null?void 0:d.map(O=>O.path),c=l.reduce((O,h)=>Math.max(h.length,O),0);console.log(""),u&&u.length?(console.log(` ${S.default.bold.green("\u25A0")} ${S.default.white(i)}`),u.forEach((O,h)=>{console.log([" ",`${S.default.cyan(l[h].padEnd(c," "))}`,` ${S.default.gray("\u2014\u25BA")} `,`${S.default.yellow(n)}${S.default.yellow(O)}`].join(""))})):(console.log(` ${S.default.gray("\u25A0")} ${S.default.white(i)}`),console.log(` ${S.default.gray("No PO files found.")}`))}),console.log("")};v.default.enabled=!!(0,Oe.default)().hasBasic;var Te=(e,t,r)=>{H.readFile(e,(n,o)=>{n&&r(n);let s=z.default.po.parse(o);t(s)})},Ve=(e,t,r,n)=>{let o=B.default.isVinyl(e),s=o?e.path:e,i=I(s,t);if(i.length)if(o){t.returnPOT&&t._pot_input_files.push(e);let l=z.default.po.parse(e.contents);r([l,i])}else H.readFile(s,(l,u)=>{l&&n(l),t.returnPOT&&t._pot_input_files.push(new B.default({contents:ge.Buffer.from(u),path:s}));let c=z.default.po.parse(u);r([c,i])});else r(null)},k=(e,t)=>{if(typeof e!="function")throw new b("fillPotPo() requires a callback function as first parameter");let r;try{r=L(R(t))}catch(n){e([!1,n.toString()]);return}r._pot_input_files=[],r._po_input_files=[],Promise.all(r.potSources.map(n=>{let o=B.default.isVinyl(n)?n.relative:n;return new Promise((s,i)=>{Ve(n,r,s,i)}).then(async s=>{if(!s)return r._po_input_files.push([]),[];let i=s[0],l=s[1];return r._po_input_files.push(l),await Promise.all(l.map(c=>new Promise((f,d)=>{Te(c,f,d)}).then(f=>U(i,f,c,r)).catch(f=>{throw new b(`${v.default.bold(f.message)} ${v.default.gray(`(PO ${v.default.white(c)})`)}`)})))}).catch(s=>{throw new b(`${s.message} ${v.default.gray(`(POT ${v.default.white(o)})`)}`)})})).then(n=>{if(r.logResults&&N(r._potFilenames,r._po_input_files,n,r.destDir),r.returnPOT){e([!0,r._pot_input_files]);return}e([!0,[].concat(...n)])}).catch(n=>{e([!1,n.toString()])}).finally(()=>{r._pot_input_files=[],r._po_input_files=[]})};var Y=m(require("fs")),W=m(require("vinyl")),K=m(require("gettext-parser"));var G=[],X=[],V=[],Ae=(e,t,r)=>{let n=[];for(let o of e){let s=Y.readFileSync(o).toString(),i=K.default.po.parse(s);n.push(U(t,i,o,r))}V.push(n)},je=(e,t)=>{let r=W.default.isVinyl(e),n=r?e.path:e,o=I(n,t);if(X.push(o),o.length){let s="";if(r)t.returnPOT&&G.push(e),s=e.contents;else{let l=Y.readFileSync(n);s=l.toString(),t.returnPOT&&G.push(new W.default({contents:l,path:n}))}let i=K.default.po.parse(s);Ae(o,i,t)}else V.push([])},Q=e=>{G=[],X=[],V=[];let t=L(R(e));return t.potSources.forEach(r=>{je(r,t)}),t.logResults&&N(t._potFilenames,X,V,t.destDir),t.returnPOT?G:[].concat(...V)};var he={wrapLength:77,defaultContextAsFallback:!0,appendNonIncludedFromPO:!0,includePORevisionDate:!1,includeGenerator:!1},Ee=k;typeof module<"u"&&(k.sync=Q,k.testOptions=he,k.prepareOptions=R,module.exports=k,module.exports.default=k);0&&(module.exports={prepareOptions,sync,testOptions}); |
{ | ||
"name": "fill-pot-po", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "Create pre-filled PO files from POT file, using previous PO files.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -163,3 +163,3 @@ # fill-pot-po [![GitHub release (latest SemVer)][release-image]][release-url] [![NPM version][npm-image]][npm-url] | ||
For actual source code, see [**`getPOFilepaths()`**](https://github.com/vHeemstra/fill-pot-po/blob/main/src/shared.js#L50) in **src/shared.js**. | ||
For actual source code, see [**`getPOFilepaths()`**](https://github.com/vHeemstra/fill-pot-po/blob/main/src/shared.ts#L134) in **src/shared.js**. | ||
@@ -166,0 +166,0 @@ See also options [`poSources`](#posources), [`srcDir`](#srcdir), [`domainInPOPath`](#domaininpopath), [`domainFromPOTPath`](#domainfrompotpath) and [`domain`](#domain). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
44637
0.09%