How to use the gettext-parser.po.compile 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 WordPress / gutenberg / packages / babel-plugin-makepot / src / index.js View on Github external
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;
				},
			},
github laget-se / react-gettext-parser / src / json2pot.js View on Github external
// 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()
}
github Automattic / sensei / scripts / pot-dist-references.js View on Github external
// 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 );
};
github WordPress / gutenberg / i18n / babel-plugin.js View on Github external
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;
				},
			},
github westonruter / spoken-word / src / i18n / babel-plugin.js View on Github external
// 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;
				}
			}
github Automattic / wp-calypso / packages / babel-plugin-i18n-calypso / src / index.js View on Github external
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 );
				},
			},
github binary-com / binary-static / scripts / gettext.js View on Github external
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`),
github Automattic / wp-calypso / packages / webpack-generate-pot-plugin / index.js View on Github external
const saveFile = () => {
			if ( isEmpty( strings ) ) {
				return;
			}
			const data = merge( {}, baseData, { translations: strings } );

			const compiled = po.compile( data );

			writeFileSync( this.opts.filename, compiled );
		};

gettext-parser

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

MIT
Latest version published 3 months ago

Package Health Score

79 / 100
Full package analysis