po2json-i18next
v1.0.1
Published
Convert Django .po files to i18next-compatible JSON
Maintainers
Readme
po2json-i18next
Convert Django .po files to i18next-compatible JSON with zero dependencies.
Features
- 🚀 Blazing fast - Pure Node.js implementation
- 📦 Zero dependencies
- 🌍 Automatic language detection from PO metadata
- 💡 Supports basic PO syntax (msgid, msgstr)
- 🔧 Flexible output - CLI or programmatic use
QuickStart
npx po2json-i18next input.po output.json
Option 2: Package Scripts
Add to your package.json:
{
"scripts": {
"convert-po": "po2json-i18next locales/input.po public/locales/output.json"
}
}Then run:
npm run convert-po
Option 4: Programmatic Use
javascript
const { parsePo } = require('po2json-i18next');
const fs = require('fs');
const poContent = fs.readFileSync('input.po', 'utf8');
const { translations } = parsePo(poContent);
console.log(translations); // { "Hello": "Hello", ... }
CLI Options
Parameter Description Example <input.po> Path to source .po file locales/en.po <output.json> Path for output JSON public/locales/en.json --pretty Pretty-print JSON output po2json input.po output.json --pretty
Example
input.po:
msgid "Hello" msgstr "Hello"
msgid "Welcome" msgstr "Welcome"
output.json:
{ "translation": { "Hello": "Hello", "Welcome": "Welcome" } }
Development
Clone the repository:
git clone https://github.com/your/po2json-i18next.git
cd po2json-i18nextInstall dependencies:
npm installRun tests:
npm testContributing
Pull requests are welcome! For major changes, please open an issue first.
License MIT © 2023 [Pavel Kalinin]
