po-extract

A CLI tool for creating `react-intl`-compatible dictionaries from gettext `.po`-files

Usage no npm install needed!

<script type="module">
  import poExtract from 'https://cdn.skypack.dev/po-extract';
</script>

README

po-extract

NPM version CI workflow

A CLI tool for creating react-intl-compatible dictionaries from gettext .po-files.

What for? Many translators and software translation companies prefer to work with standardized dictionaries in the .po format, while developers are more comfortable working with language strings in a JavaScript or TypeScript compatible format.

Pre requirements

  • node.js: >=8.*

Installation

Install it with yarn:

yarn add po-extract --dev

Or with npm:

npm install po-extract --save-dev

Usage

  1. Add scripts to package.json:
"scripts": {
  + "po:build": "po-extract",
  + "po:watch": "po-extract --watch",
  1. Create .po-files (example). By default, the library looks for the directory dictionaries in the root of the project, you can change it, see CLI Options.

  2. Create target directory. By default, the library uses the src/dictionaries directory in the root of the project, you can change it, see CLI Options.

  3. Run script to generate react-intl-compatible dictionaries:

yarn run po:build

Or with npm:

npm po:build

See full example.

CLI Options

Option Type Default Description
--targetDir string ./dictionaries Target directory with .po files
--outDir string ./src/dictionaries Save output to the directory
--outExt string .js Output files extensions
--watch boolean false Run the extractor in watch mode

License

MIT