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

crusca-cli

v1.0.0

Published

Node.js command line client for crusca, the ES6 compatible gettext alternative to extract translation strings

Downloads

17

Readme

crusca-cli

crusca-cli is the Node client for crusca, a drop-in replacement for xgettext to extract translation strings from Javascript files.

xgettext falls short on ES6 template strings, that are incidentally the best and more modern way to create translation strings in JS clients.


From this approach that implies an String.prototype.format hack in place

  const str1 = t('Organisation {0} is now {1} #orgStatus').format(orgName, orgStatus);
  const str2 = t('Fill in the {0} #academy').format('<strong>{0}</strong>').format(this.state.title);

To this purely native approach

  const str1 = t`Organisation ${orgName} is now ${orgStatus} #orgStatus`;
  const str2 = t`Fill in the ${this.state.title} #academy`;

In it's very simplest form, this is it

# from this
find app/assets -type f -iname '*.js' | xargs xgettext --no-wrap --default-domain=javascripts --keyword=t --from-code=UTF-8 -o $pot_file

# to this
node_modules/.bin/crusca-cli -i app/assets -o $pot_file

Usage

crusca-cli -i path/to/files -o output.pot [-e -g -c -v]

Examples

Scanning the directory /Users/domo/projects/myPrj to look for .js files and extract strings using all the default parameters.

crusca-cli -i /Users/domo/projects/myPrj -o myPrj.pot

Parse a single file and extract strings from it.
Note: any --ignore or --ext option will be ignored when parsing a single file.

crusca-cli -i file.js -o strings.pot

Installation

You can either install crusca-cli as a global package or local to your project.

globally

npm install -g crusca-cli

You can then use it anywhere by simply calling crusca-cli

locally

npm install --save-dev crusca-cli

crusca-cli will then be available in node_modules/.bin/crusca-cli.
You can either use it from an NPM-script simply by calling it or you can reference to it's path to access it from anywhere, like a shell script.

E.g.

"scripts": {
  "extract": "crusca-cli -i ./src -o strings.pot -e .js -e .jsx"
}

or

#!/bin/bash

prj_dir=./src
output=strings.pot

node_modules/.bin/crusca-cli -i $prj_dir -o $output

Config File

crusca-cli can be configured using a config file which takes the same options listed in the options section, except --config obviously.

{
  "ignore": [
    "bower_components",
    "node_modules"
  ],
  "extensions": ["js", "jsx"]
}

Options

Bold options are required

| Options | Default | Description | |---------------|:--------:|-----------------------------------------------------------| | -i, --in | -- | File or directory to search for translation strings | | -o, --out | -- | Output file that will contain the extracted strings | | -e, --ext | .js | Whitelist file extensions you want to parse (adds leading dot, if missing).Multiple entries are allowed | | -g, --ignore | [] | Blacklist file or directories you don't want to scan.Support minimatch glob expressions. Multiple entries are allowed | | -c, --config | ./cruscarc | Custom config path | | -v, --verbose | false | Enable chatty version | | -q, --quite | false | Completely silent on success | | -h, --help | -- | Show help |

Configurations Priority

It is important to note that there is a priority when supplying options

config_file (default or custom with -c)
├── cli_arguments
├───── default_arguments

For example
crusca-cli -i some/folder -o strings.pot -c ./conf -e js -e jsx -g test

Where ./conf is

{
  "ext": "js"
}

Will only consider .js files, because the config has higher priority, while still ignoring the folder test, since it has not been overridden in the config file

TODOs

  • [x] get the same params of .cruscarc from command line
  • [ ] add crusca options to crusca-cli config file and command line
  • [x] implement --ignore and --ext as cli options
  • [ ] implement --verbose, --in, --out in cruscarc
  • [ ] put defaults in a separate place
  • [ ] output JSON to console (--json, -j)
  • [x] add tests

License

The MIT License (MIT)

Copyright (c) 2016 Domenico Matteo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.