0.2.2 • Published 7 years ago

meetup-trn-extractor v0.2.2

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

Meetup TRN Extractor

Build Status Coverage Status

A utility to extract copy from JavaScript files for translation

Installation

npm i --save meetup-trn-extractor

Example usage

This will look for trn (case insensitive) function calls within the searched files in the format:

  trn(key: string, body: string, params?: Object)

CLI

./node_modules/.bin/meetup-trn-extractor [options]

Options:
  --files, -f               glob pattern for input files (wrap in '', or escape
                            * with \*)                       [string] [required]
  --outfile, -o             Send the output to a file                   [string]
  --exclude-empty-trns, -x  Exclude files that do not contain TRNs
                                                      [boolean] [default: false]
  --babylon-plugins, -p     Any number of Babylon plugins
                                                        [array] [default: ["*"]]
  --help                    Show help                                  [boolean]

Examples:
  ./node_modules/.bin/meetup-trn-extractor
  --files='src/**/*!(.test).js'
  --outfile=output.json
  --exclude-empty-trns
  --babylon-plugins jsx flow
  ./node_modules/.bin/meetup-trn-extractor -f src/\*\*/\*!(.test).js -o output.json -p flow jsx

Node

import Extractor from 'meetup-trn-extractor'

const extractor = new Extractor({
  // https://github.com/babel/babylon#options
  babylonConfig: { sourceType: 'module', plugins: ['*'] },
  trnFnName: 'trn'
})

// Extractor.extract(globPattern: string) => Promise<Object[]>
extractor.extract('src/**/*.js').then((trns: Object[]) => console.log(trns))

Example output

[
  {
    "file": "/usr/local/git_repo/meetup-trunk/static/script/mu/shared/validator.js",
    "trns": []
  },
  {
    "file": "/usr/local/git_repo/meetup-trunk/static/script/mu/shared/validatorRules.js",
    "trns": [
      {
        "key": "validation.isChecked",
        "body": "This checkbox is required.",
        "params": []
      },
      {
        "key": "validation.error.minLength",
        "body": "Should be at least {MIN} characters",
        "params": [
          "MIN"
        ]
      }
    ]
  }
]

Caveats

This currently does not extract trns from trn calls in the following formats

  // don't concat strings
  trn('some.key', 'some ' + 'copy') // won't work
  trn(['some', 'key'].join('.'), 'some copy') // won't work

  trn('some.key', 'some copy') // will work

Contributing

Versioning

npm version major|minor|patch to create a git commit + tag incrementing the major, minor or patch version in package.json. git push && git push --tags to push the version commit + tag to GitHub.

Publishing

npm publish to publish the latest version to NPM.

0.2.2

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago