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

makemessages

v0.4.1

Published

Extract and compile messages to localize a web app

Downloads

3

Readme

makemessages

NPM version NPM license

Extract and compile messages to localize a web app using Regular Expressions.

This package intends to work simliar to django's makemessages and compilemessages commands.

Installation

Local

npm i makemessages

Global

npm i -g makemessages

Usage

Configuring CLI

Local

Change your package.json:

{
  // ...
  "scripts": {
    "makemessages": "makemessages",
    "compilemessages": "compilemessages",
    // ...
  }
  // ...
}
npm run makemessages -- -c "./makemessages.json"
npm run compilemessages -- -c "./compilemessages.json"

Global

makemessages -c "./makemessages.json"
compilemessages -c "./compilemessages.json"

Configuration

makemessages json configuration file must have a list to how to process your files

Example:

[
  {
    "type": "po", // Valid types: po (only .po files implemented for now)
    "input": "./path/to/your/source/**/*.js", // glob pattern to search your files
    "output": "./path/to/locale/po/", // if there is already some previous file in this folder, next result will be a merge between existing messages and new found ones
    "functions": [ // Array<string> that will initiate regular expression objects to look for your messages
        "(?:^|[^$\\w\\s.])\\s*gettext\\s*\\(\\s*['\"](?<singular>.*?)['\"]\\s*\\)",
        "(?:^|[^$\\w\\s.])\\s*pgettext\\s*\\(\\s*['\"](?<context>.*?)['\"]\\s*,\\s*['\"](?<singular>.*?)['\"]\\s*\\)",
        "(?:^|[^$\\w\\s.])\\s*ngettext\\s*\\(\\s*['\"](?<singular>.*?)['\"]\\s*,\\s*['\"](?<plural>.*?)['\"]\\s*,\\s*(?<number>\\d*)\\s*\\)",
        "(?:^|[^$\\w\\s.])\\s*npgettext\\s*\\(\\s*['\"](?<context>.*?)['\"]\\s*,\\s*['\"](?<singular>.*?)['\"]\\s*,\\s*['\"](?<plural>.*?)['\"]\\s*,\\s*(?<number>\\d*)\\s*\\)"
    ],
    "languages": {
      "en": "English",
      "pt": "Portuguese",
      "pt-br": "Brazilian Portuguese"
    },
    "meta": { // meta data that will be inserted into your .po files
      "copyright": {
        "domain": "example.com",
        "package": "example"
      },
      "maintainer": {
        "name": "Developer",
        "email": "[email protected]"
      },
      "Project-Id-Version": "0.0.1",
      "Report-Msgid-Bugs-To": "[email protected]",
      "Language-Team": "Team Example"
    }
  }
]

compilemessages.json example

[
  {
    "input": {
      "type": "po",
      "target": "./path/to/locale/po/*.po" 
    },
    "output": {
      "type": "json",
      "target": "./path/to/locale/json/"
    }
  },
  {
    "input": {
      "type": "po",
      "target": "./path/to/locale/po/*.po" 
    },
    "output": {
      "type": "javascript",
      "target": "./path/to/locale/js/",
      "functions": { // Optional: change functions names
        "gettext": "gettext",
        "ngettext": "ngettext",
        "pgettext": "pgettext",
        "npgettext": "npgettext"
      }
    }
  }
]

Expected output

./path/to/locale/
  po/
    en.po
    pt.po
    pt-br.po
  json/
    en.json
    pt.json
    pt-br.json
  js/
    en.js
    pt.js
    pt-br.js

Next features

PO

  • Remove Old Messages - Configurable
  • Semantic Comments following GNU PO format