fill-pot-po
Advanced tools
Comparing version
{ | ||
"name": "fill-pot-po", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Create pre-filled PO files from POT file, using previous PO files.", | ||
@@ -48,6 +48,6 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"eslint": "^8.16.0", | ||
"eslint-plugin-jest": "^26.4.5", | ||
"eslint": "^8.17.0", | ||
"eslint-plugin-jest": "^26.5.3", | ||
"jest": "^28.1.0" | ||
} | ||
} |
@@ -8,3 +8,3 @@ 'use strict'; | ||
const Vinyl = require('vinyl'); | ||
const { readFile } = require('fs'); | ||
const fs = require('fs'); | ||
const gettextParser = require('gettext-parser'); | ||
@@ -32,3 +32,3 @@ | ||
// Async - Read, parse and process PO file | ||
readFile(po_filepath, (err, file_content) => { | ||
fs.readFile(po_filepath, (err, file_content) => { | ||
if (err) reject(err); | ||
@@ -74,3 +74,3 @@ const po_object = gettextParser.po.parse(file_content); | ||
// Async - Read and parse POT file | ||
readFile(pot_filepath, (err, pot_content) => { | ||
fs.readFile(pot_filepath, (err, pot_content) => { | ||
if (err) reject(err); | ||
@@ -108,2 +108,3 @@ | ||
// Reset | ||
pot_input_files = []; | ||
@@ -152,5 +153,5 @@ po_input_files = []; | ||
}) ).then(pot_results => { | ||
}) ).then(po_output_files => { | ||
if (options.logResults) { | ||
logResults(options._potFilenames, po_input_files, pot_results, options.destDir); | ||
logResults(options._potFilenames, po_input_files, po_output_files, options.destDir); | ||
} | ||
@@ -164,4 +165,4 @@ | ||
// Flatten into array with all PO files | ||
pot_results = [].concat(...pot_results); | ||
cb([true, pot_results]); | ||
po_output_files = [].concat(...po_output_files); | ||
cb([true, po_output_files]); | ||
}).catch(error => { | ||
@@ -168,0 +169,0 @@ cb([false, error.toString()]); |
@@ -6,4 +6,14 @@ 'use strict'; | ||
// See: https://stackoverflow.com/a/54047219/2142071 | ||
const the_module = module.exports = fillPotPo; | ||
the_module.sync = fillPotPoSync; | ||
// Default options for generating PO files | ||
// used in tests as the correct ones. | ||
the_module.testOptions = { | ||
wrapLength: 77, | ||
defaultContextAsFallback: true, | ||
appendNonIncludedFromPO: true, | ||
includePORevisionDate: false, | ||
includeGenerator: false, | ||
}; |
@@ -189,15 +189,2 @@ 'use strict'; | ||
} | ||
// TODO: move undublicate to POT generator | ||
// Extra - Remove duplicate translator comments | ||
// Fix for gulp-wp-pot's POT generation | ||
if ( entry.comments?.extracted ) { | ||
let comments = entry.comments.extracted.split('\n'); | ||
new_po_object.translations[ ctxt ][ msgid ].comments.extracted = comments.reduce((ar, v) => { | ||
if (0 > ar.indexOf(v)) { | ||
ar.push(v); | ||
} | ||
return ar; | ||
}, []).join('\n'); | ||
} | ||
} | ||
@@ -322,3 +309,3 @@ } | ||
const po_filepaths_in = pos_in[i]?.map(po => po); | ||
const po_filepaths_out = pos_out[i]?.map(po => po[0]); | ||
const po_filepaths_out = pos_out[i]?.map(po => po.path); | ||
const max_length_in = po_filepaths_in.reduce((p, c) => (Math.max(c.length, p)), 0); | ||
@@ -325,0 +312,0 @@ |
'use strict'; | ||
const Vinyl = require('vinyl'); | ||
const { readFileSync } = require('fs'); | ||
const fs = require('fs'); | ||
const gettextParser = require('gettext-parser'); | ||
@@ -32,3 +32,3 @@ | ||
// Sync - Read and parse PO file | ||
const po_content = readFileSync(po_filepath).toString(); | ||
const po_content = fs.readFileSync(po_filepath).toString(); | ||
const po_object = gettextParser.po.parse(po_content); | ||
@@ -72,3 +72,3 @@ | ||
// Sync - Read POT file | ||
pot_content = readFileSync(pot_filepath); | ||
pot_content = fs.readFileSync(pot_filepath); | ||
@@ -93,2 +93,4 @@ if (options.returnPOT) { | ||
// Reset | ||
pot_input_files = []; | ||
po_input_files = []; | ||
po_output_files = []; | ||
@@ -95,0 +97,0 @@ |
42898
-0.39%931
-0.11%