Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
path.resolve(
baseLocaleDir,
language.code,
"LC_MESSAGES/messages.po"
)
);
mergedPOFile = fs.readFileSync(mergedPOFileOutputPath);
log("Finished merging .po file for " + language.code);
} catch(e) {
logError("Error merging .po file for " + language.code);
}
gt.addTranslations(
language.code,
"messages",
gettextParser.po.parse(mergedPOFile)
);
gt.setTextDomain("messages");
gt.setLocale(language.code);
// Localize the config for the current language.
walk(thisConfig, (val, prop, obj) => {
if (typeof val === "string") {
if (configGettextRegex.test(val)) {
val = val
.replace(configGettextRegex, "")
.replace(/\)$/, "");
obj[prop] = gt.gettext(val);
}
}
});
log("Finished localizing config for " + language.code);
xgettext(['test/fixtures/non-ascii.hbs'], { output: '-' }, function (po) {
var context = gt.po.parse(po, 'utf-8').translations[''];
assert('Строка' in context);
done();
});
});
function convertPOTToPHP( potFile, phpFile, options ) {
const poContents = fs.readFileSync( potFile );
const parsedPO = gettextParser.po.parse( poContents );
let output = [];
for ( const context of Object.keys( parsedPO.translations ) ) {
const translations = parsedPO.translations[ context ];
const newOutput = Object.values( translations )
.map( ( translation ) => convertTranslationToPHP( translation, options.textdomain, context ) )
.filter( ( php ) => php !== '' );
output = [ ...output, ...newOutput ];
}
const fileOutput = fileHeader + output.join( ',' + NEWLINE + NEWLINE ) + fileFooter;
fs.writeFileSync( phpFile, fileOutput );
function parsePoFile(filePath) {
const content = fs.readFileSync(filePath);
return gettextParser.po.parse(content);
}
function convertPOTToPHP( potFile, phpFile, options ) {
const poContents = fs.readFileSync( potFile );
const parsedPO = gettextParser.po.parse( poContents );
let output = [];
for ( const context of Object.keys( parsedPO.translations ) ) {
const translations = parsedPO.translations[ context ];
const newOutput = Object.values( translations )
.map( ( translation ) => convertTranslationToPHP( translation, options.textdomain, context ) )
.filter( php => php !== '' );
output = [ ...output, ...newOutput ];
}
const fileOutput = fileHeader + output.join( ',' + NEWLINE + NEWLINE ) + fileFooter;
fs.writeFileSync( phpFile, fileOutput );
export function parsePoData(filepath) {
if (poDataCache[filepath]) return poDataCache[filepath];
const poRaw = fs.readFileSync(filepath);
const parsedPo = gettextParser.po.parse(poRaw.toString());
const translations = parsedPo.translations;
const headers = parsedPo.headers;
const data = { translations, headers };
poDataCache[filepath] = data;
return data;
}
const path = require('path');
const fs = require('fs');
const gettextParser = require('gettext-parser');
const languages = require('./languages.json');
const translationDir = __dirname;
const poDir = path.join(translationDir, 'po');
const jsonDir = path.join(translationDir, 'json');
for (let language of Object.keys(languages)) {
const poPath = path.join(poDir, `${language}.po`);
const jsonPath = path.join(jsonDir, `${language}.json`);
const translationData = gettextParser.po.parse(fs.readFileSync(poPath, {encoding:'utf-8'}), 'utf-8');
const json = {};
const translations = translationData.translations[''];
for (let key of Object.keys(translations)) {
if (key && translations[key].msgstr[0]) {
json[key] = translations[key].msgstr[0];
}
}
fs.writeFileSync(jsonPath, JSON.stringify(json, null, 2), {encoding: 'utf-8'});
}
poFiles.forEach( function( thisFile ) {
thisLang = thisFile.replace("i18n/locale/","").replace("/datebox.po","");
thisContents = gettextParser.po.parse( fs.readFileSync( thisFile ) );
gt.addTranslations( "", thisLang, thisContents );
allLang[ thisLang ] = buildLang( thisLang );
thisJS = makeSingleFile( thisLang, allLang[ thisLang ] );
fs.writeFileSync(
outFilePrefix + thisLang + ".utf8.js",
thisJS
);
minJS = UglifyJS.minify( thisJS, {
mangle : true,
compress : true,
output : {