narp
A workflow utility to ease localization in JS(X) apps by automizing the following steps:
narp push
- Extraction of strings from source code (react-gettext-parser)
- Merging upstream and local translations in order to support translations in branches (pot-merge)
- Uploading POT resources to the translation service you use (Transifex or POEditor)
narp pull
- Download PO translations from the translation service
- Converting PO to JSON (gettext-parser)
- Writing the JSON translations to where you want it
The JSON translations are formatted for node-gettext.
Table of Contents
Installation
To use it easily, install narp globally with:
npm install -g narp
To use it in an automatization pipeline in your project, install it as a dev dependency:
npm install --save-dev narp
Usage
Using the CLI
narp -h
narp push [<credentials>] [--fresh]
narp pull [<credentials>]
narp extract [./path/to/comps]
Optionally put a path as arg 2 to just extract from the folder.
Protip, pipe to file if you want to use it.
Using the API
import { push, pull } from 'narp';
const configs = {
};
push(configs).then().catch();
pull(configs).then().catch();
Configuration
Options
This is the shape of narp's configuration. It can be provided as an object to the pull()
and push()
functions, or defined as a JSON object in .narprc
.
{
"vendor": {
"name": "pick one"
"credentials": {
"token": "do not store this in a file"
},
"options": {
"organization": "organization-slug",
"project": "project-id",
"sourceLanguage": "en",
"resource": null,
}
},
"extract": {
"source": null,
"componentPropsMap": { },
"funcArgumentsMap": { },
"trim": false,
"trimLines": false,
"trimNewlines": false,
},
"output": "messages.json",
"fresh": false,
"verbose": false
}
How to provide credentials
You will have to provide different credentials depending on the translation service you use. Transifex requires a username and password, whilst POEditor requires an API token.
Authorizing to Transifex
There are three ways of providing an API token:
a. Via the --token
argument
b. Via the NARP_VENDOR_TOKEN
environment variable
c. Via the vendor.credentials.token
config passed to the API functions
Never store secret tokens in your code!
Authorizing to POEditor
There are three ways of providing an API token:
a. Via the --token
argument
b. Via the NARP_VENDOR_TOKEN
environment variable
c. Via the vendor.credentials.token
config passed to the API functions
Never store secret tokens in your code!
.narprc
.narprc
is narp's configuration file. Any configurations you put there will be parsed and applied whenever you use narp.
Migrations
Migrating from v2 to v3
v3 introduced vendors, which replaces the hard-coded Transifex support with a modularised vendor support, adding POEditor into the mix. To transition your Transifex configuration, you change .narprc
from
{
"transifex": {
"username": "yourusername",
"project": "yourproject",
"resource": "yourresource",
"sourceLang": "xx"
},
}
to
{
"vendor": {
"name": "transifex",
"credentials": {
"username": "yourusername"
},
"options": {
"project": "yourproject",
"resource": "yourresource",
"sourceLanguage": "xx"
}
},
}
Migrating from v3 to v5
Updated to use the new Transifex API. Change .narprc
from
{
"vendor": {
"name": "transifex",
"credentials": {
"username": "yourusername"
},
"options": {
"project": "yourproject",
"resource": "yourresource",
"sourceLanguage": "xx"
}
},
}
to
{
"vendor": {
"name": "transifex",
"options": {
"organization": "yourorganization",
"project": "yourproject",
"resource": "yourresource",
"sourceLanguage": "xx"
}
},
}
Development
Creating builds
npm run build
npm run build -- --watch
Making it globally available while testing
cd path/to/narp && npm link
Releases
Follow semver when bumping the version number, commit it and run
npm publish