Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
memo[ msgctxt ][ msgid ] = translation;
} );
}
return memo;
}, {} );
// Merge translations from individual files into headers
const data = merge( {}, baseData, { translations } );
// Ideally we could wait until Babel has finished parsing
// all files or at least asynchronously write, but the
// Babel loader doesn't expose these entry points and async
// write may hit file lock (need queue).
const compiled = po.compile( data );
writeFileSync( state.opts.output || DEFAULT_OUTPUT, compiled );
this.hasPendingWrite = false;
},
},
// Allow the consumer to transform headers
const transformHeaders = opts.transformHeaders
? opts.transformHeaders
: x => x
const transformedPotJson = {
...potJson,
headers: transformHeaders(potJson.headers),
}
const compilerOpts = {}
if (opts.noWrap === true) {
compilerOpts.foldLength = 0
}
const pot = po.compile(transformedPotJson, compilerOpts)
return pot.toString()
}
// Loop through message objects.
Object.keys( context ).forEach( ( messageKey ) => {
const message = context[ messageKey ];
const { reference } = message.comments;
if ( reference ) {
message.comments.reference = getReferenceWithDist(
reference,
chunksMapBySource
);
}
} );
} );
return po.compile( potObject );
};
memo[ msgctxt ][ msgid ] = translation;
} );
}
return memo;
}, {} );
// Merge translations from individual files into headers
const data = merge( {}, baseData, { translations } );
// Ideally we could wait until Babel has finished parsing
// all files or at least asynchronously write, but the
// Babel loader doesn't expose these entry points and async
// write may hit file lock (need queue).
const compiled = po.compile( data );
writeFileSync( state.opts.output || DEFAULT_OUTPUT, compiled );
this.hasPendingWrite = false;
},
},
// By spec, enumeration order of object keys cannot be
// guaranteed, but in practice most runtimes respect order
// in which keys are inserted. We rely on this to specify
// ordering alphabetically by file, line. A better solution
// is to support or reimplement translations as array.
data.translations.messages = fromPairs( sortBy(
toPairs( data.translations.messages ),
( [ , translation ] ) => translation.comments.reference
) );
// Ideally we could wait until Babel has finished parsing
// all files or at least asynchronously write, but Babel
// doesn't expose these entry points and async write may
// hit file lock (need queue).
const compiled = po.compile( data );
writeFileSync( state.opts.output || DEFAULT_OUTPUT, compiled );
this.hasPendingWrite = false;
}
}
exit( path, state ) {
if ( isEmpty( strings ) ) {
return;
}
const data = merge( {}, baseData, { translations: strings } );
const compiled = po.compile( data );
const dir = state.opts.dir || DEFAULT_DIR;
! existsSync( dir ) && mkdirSync( dir, { recursive: true } );
const { filename } = this.file.opts;
const pathname = relative( '.', filename )
.split( sep )
.join( '-' );
writeFileSync( dir + pathname + '.pot', compiled );
},
},
parsed.translations[''] = {};
source_strings.sort().forEach(entry => {
const idx = old_strings.indexOf(entry);
if (idx === -1) {
new_strings.push(entry);
} else {
old_strings.splice(idx, 1);
}
parsed.translations[''][entry] = {
msgid : entry,
msgstr: [''],
};
});
const output = po.compile(parsed, { foldLength: 0 });
fs.writeFileSync(
Path.join(common.root_path, translations_dir, 'messages.pot'),
output,
'utf8'
);
process.stdout.write(common.messageEnd(Date.now() - start_time, true));
process.stdout.write(` (messages.pot: ${source_strings.length.toLocaleString()} entries)\n`);
printList('New strings', new_strings, 'greenBright');
printList('Deleted strings', old_strings, 'redBright');
console.log(
'\n\n',
color.cyanBright('Summary\n'),
color.yellowBright(`${'='.repeat(20)}\n`),
const saveFile = () => {
if ( isEmpty( strings ) ) {
return;
}
const data = merge( {}, baseData, { translations: strings } );
const compiled = po.compile( data );
writeFileSync( this.opts.filename, compiled );
};