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

stonejs-tools

v1.5.0

Published

Tools for extracting/compiling translatable strings from Javascript/HTML source

Downloads

4,042

Readme

Stone.js Tools

Lint and test NPM Version License Discord

Tools for extracting/compiling translatable strings from Javascript/HTML sources.

Getting Started

To start using the Stone.js tools, you first have to install them globally:

npm install -g stonejs-tools

Internationalization

See the Stone.js documentation to learn how to internationalize your application:

  • https://github.com/flozz/stone.js

Extracting Translatable Strings

To extract translatable strings from your Javascript and HTML sources, you should use the stonejs extract command:

stonejs extract [options] <source js/html> <output pot>
  • <source js/html>: all Javascript and HTML files from which translatable string will be extracted (globbing allowed)
  • <output pot>: the output translation template (.pot)

The available options are:

  • --funtions: list of the gettext function names (default=_,gettext,lazyGettext)
  • --pluralFunctions: list of the ngettext function names (default=ngettext,lazyNgettext)
  • --contextFunctions: list of the pgettext function names (default=pgettext,lazyPgettext)
  • --pluralContextFunctions: list of the npgettext function names (default=npgettext,lazyNpgettext)
  • --quiet, -q: do not output progress log to stdout

Examples:

stonejs extract "src/**/*.js" locales/catalog.pot

stonejs extract --functions="_,gettext,lazyGettext" "src/**/*.js" "*.html" locales/catalog.pot

Translating to a New Language

To start translating to a new langage, just copy the translation template file (.pot) and update the Language and the Plural-Forms fields.

Example: translating to French

First copy the .pot file:

cp locales/catalog.pot locales/fr.po

Then edit it:

"Language: fr\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

NOTE: A list of plural forms for many languages is is available here:

  • http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html

Updating Translations

If you have already translated your app but you have new strings to translate, you can update your .po files to add the new strings to them.

First, extract again your translatable strings to recreate the translation template file (.pot) with the stonejs extract command (see above).

Then you can update your translation files (.po) using the stonejs update command:

stonejs update [options] <po files> <source pot>
  • <po files>: translation files (.po) to update (globbing allowed)
  • <source pot>: the source translation template (.pot)

The available options are:

  • --quiet, -q: do not output progress log to stdout

Example:

stonejs locales/*.po locales/catalog.pot

Building Translations

To be used by Stone.js, your translation must be built into one ore more JSON or Javascript files using the stonejs build command:

stonejs build [options] <po files> <output>
  • <po files>: translation files (.po) to build (globbing allowed)
  • <output>: The output directory where built files will be created (or output file if you used the --merge option)

The available options are:

  • --merge: Merge all languages into a single file (default: false)
  • --format: The output format: json, javascript or js (default: json)
  • --quiet, -q: do not output progress log to stdout

Examples:

stonejs build --format=json locales/*.po locales

stonejs build --merge locales/*.po locales/catalogs.json

stonejs build --format=js --merge locales/*.po locales/catalogs.js

Support this project

Want to support this project?

Changelog

  • [NEXT] (changes on master but not released yet):

    • Nothing yet ;)
  • v1.5.0:

    • Added support of string with context (pgettext, npgettext,...) (@Krenodeno, #32)
    • Updated dependencies
  • v1.4.0: Update JS parser and enable latest ES syntaxes

  • v1.3.0: Add the line and the column of syntax errors (#25)

  • v1.2.0:

    • Support of plurals (ngettext()) (@jbghoul, #11)
    • Support of gettext_noop() (@jbghoul, #16)
    • Update dependencies
  • v1.1.0:

    • ES6 modules (import / export) support
    • JSX support
    • dependencies updates
    • WARNING: octal literals are not supported anymore!
  • v1.0.8: Adds the .twig extention as HTML file list

  • v1.0.7: Allows string to be extracted from es2015 (ES6) sources

  • v1.0.6: Force encoding to UTF-8 when reading/writing files

  • v1.0.5: Fixes crashes with wrong call of logging functions

  • v1.0.4: Fixes path issue on Window (issue #2)

  • v1.0.3: Fixes crash when the merged po file does not contain line references

  • v1.0.2:

    • Fixes crash when parsing js files containing syntax errors
    • Reporting improved (extracted string ans skipped files count, syntax errors)
  • v1.0.1: Makes stonejs command working on Unix

  • v1.0.0: First Release