How to use the gettext-parser.po function in gettext-parser

To help you get started, we’ve selected a few gettext-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapseed / platform / scripts / static-build.js View on Github external
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);
github gmarty / xgettext / test / index.js View on Github external
xgettext(['test/fixtures/non-ascii.hbs'], { output: '-' }, function (po) {
      var context = gt.po.parse(po, 'utf-8').translations[''];

      assert('Строка' in context);

      done();
    });
  });
github WordPress / gutenberg / packages / i18n / tools / pot-to-php.js View on Github external
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 );
github laurent22 / joplin / Tools / build-translation.js View on Github external
function parsePoFile(filePath) {
	const content = fs.readFileSync(filePath);
	return gettextParser.po.parse(content);
}
github WordPress / gutenberg / bin / pot-to-php.js View on Github external
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 );
github ttag-org / babel-plugin-ttag / src / po-helpers.js View on Github external
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;
}
github tidepool-org / blip / translations / jsonFromPo.js View on Github external
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'});
}
github jtsage / jtsage-datebox / build / build-i18n.js View on Github external
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   : {

gettext-parser

Parse and compile gettext po and mo files to/from json, nothing more, nothing less

MIT
Latest version published 9 months ago

Package Health Score

72 / 100
Full package analysis