Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (source) {
this.cacheable && this.cacheable()
var callback = this.async()
// Parse the language out of the file
var language = source.match(/Language: ([\w]*)/)
language = language ? language[1] : 'en'
// Convert to i18next format (already stringified)
converter.gettextToI18next(language, source, options).then(function (data) {
callback(null, "module.exports = " + data + ";")
})
}
let translationId = path.join(
lang,
path.basename(id, '.po')
);
/**
* Translation asset data.
* @type {TranslationAsset}
*/
let translation = this.translations[translationId] = this.translations[translationId] || {
asset: this.emitAsset(`${translationId}.json`),
data: {},
};
// convert .po file into JSON
let json = await gettextToI18next(lang, fs.readFileSync(id));
// merge with previous data
translation.data = Object.assign({}, translation.data, JSON.parse(json));
// just export the asset url
return `export default import.meta.ROLLUP_ASSET_URL_${translation.asset};`;
},
const convertToFlatFormat = (opt, data, lng, cb) => {
if (!cb) {
cb = lng;
lng = undefined;
}
try {
if (opt.format === 'json' || opt.format === 'flat') {
cb(null, flatten(JSON.parse(data.toString())));
return;
}
if (opt.format === 'po' || opt.format === 'gettext') {
try {
gettextToI18next(opt.referenceLanguage, data.toString(), {
persistMsgIdPlural: true,
ignoreCtx: true
}).then((ret) => {
try {
cb(null, flatten(JSON.parse(ret.toString())));
} catch (err) {
cb(err);
}
}, cb);
} catch (err) {
cb(err);
}
return;
}
if (opt.format === 'po_i18next' || opt.format === 'gettext_i18next') {
try {