npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pitcher/machine-gettext

v0.1.2

Published

Add machine translations to gettext .po files

Downloads

1

Readme

machine-gettext

Build Status

machine-gettext is a node module for adding machine translations to GNU gettext .po files. To translate content, it uses Google translate cloud service.

this is a fork of https://github.com/signavio/machine-gettext

Installation

Install machine-gettext by running npm install -g machine-gettext.

Usage

You can use machine-gettext via the command line or require it in a JavaScript file.

Command line

On the command line you can run machine-gettext with the following arguments:

  • -in, --input: Relative path to input file

  • -out, --output: Relative path to output file

  • -f, --fuzzy: If specified, mark added translation as fuzzy

  • -o, --overwrite: If specified, overwrite existing fuzzy translations

The following example writes all missing translations as non-fuzzy msgstrs into messages and overwrites fuzzy messages:

machine-gettext -i=messages.po -o=messages.po -m=non-fuzzy-overwrite

JavaScript

You can also require the module as translateGettext in a JavaScript file and execute translateGettext as a function with the following arguments:

  • input (string): Relative path to input file

  • markAsFuzzy (boolean): If true, mark added translation as fuzzy

  • overwrite (boolean): If true, overwrite existing fuzzy translations

  • callback (function): Executed after all messages have been processed. Takes a gettext-parser.po file object as its argument.

  • output (string, optional): Relative path to output file

The following example loads the content of ./messages.po, adds missing translations and logs the new content:

const translateGettext = require('translateGettext')

poFile = parser.po.parse(fileSystem.readFileSync('./messages.po'))
translateGettext(poFile, true, false, processedPoFile => {
    console.log(processedPoFile)
})

Note: The example code marks the new translations as fuzzy and doesn't overwrite existing fuzzy translations.

Contribution

Contributions are welcome. Make sure you run the tests with npm run test before creating a pull request and add test cases that cover the contributed code.

Possible improvement are, for example:

  • explicitely set the target language (currently determined via the .po file header),

  • allow integration with alternative translation services,

  • better support for interpolation and pluralization,

  • support list of terms that shouldn't be translated (for example: product names),

  • translation memory support.

Authors