https://github.com/locize/gettext-converter
po2js and js2po and i18next2po and po2i18next converter gettext resource utils
https://github.com/locize/gettext-converter
converter format gettext i18next javascript js json po
Last synced: 3 months ago
JSON representation
po2js and js2po and i18next2po and po2i18next converter gettext resource utils
- Host: GitHub
- URL: https://github.com/locize/gettext-converter
- Owner: locize
- Created: 2020-04-17T11:10:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-12T10:05:48.000Z (over 1 year ago)
- Last Synced: 2025-06-30T08:15:13.359Z (3 months ago)
- Topics: converter, format, gettext, i18next, javascript, js, json, po
- Language: JavaScript
- Size: 1.52 MB
- Stars: 6
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[](https://travis-ci.org/locize/gettext-converter) [](https://npmjs.org/package/gettext-converter)
## Download
The source is available for download from
[GitHub](https://github.com/locize/gettext-converter/archive/master.zip).
Alternatively, you can install using npm:```sh
npm install --save gettext-converter
```You can then `import` or `require()` gettext-converter as normal:
```js
import gettext from 'gettext-converter'
// or
const gettext = require('gettext-converter')const js = gettext.po2js(po)
```Or you can direclty `import` or `require()` its functions:
```js
import po2js from 'gettext-converter/po2js'
// or
const po2js = require('gettext-converter/cjs/po2js')
```## Usage
```js
const po = `msgid ""
msgstr ""
"Project-Id-Version: gettext-converter\n"
"mime-version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2020-04-17T10:46:16.313Z\n"
"PO-Revision-Date: 2020-04-17T10:46:16.313Z\n"msgid "my-key"
msgstr "myvalue"`const js = {
charset: 'utf-8',
headers: {
'Project-Id-Version': 'gettext-converter',
'mime-version': '1.0',
'Content-Type': 'text/plain; charset=utf-8',
'Content-Transfer-Encoding': '8bit',
'Plural-Forms': 'nplurals=2; plural=(n != 1)',
'POT-Creation-Date': '2020-04-17T10:46:16.313Z',
'PO-Revision-Date': '2020-04-17T10:46:16.313Z'
},
translations: {
'': {
'': {
msgid: '',
msgstr: [
'Project-Id-Version: gettext-converter\n' +
'mime-version: 1.0\n' +
'Content-Type: text/plain; charset=utf-8\n' +
'Content-Transfer-Encoding: 8bit\n' +
'Plural-Forms: nplurals=2; plural=(n != 1)\n' +
'POT-Creation-Date: 2020-04-17T10:46:16.313Z\n' +
'PO-Revision-Date: 2020-04-17T10:46:16.313Z\n'
]
},
'my-key': { msgid: 'my-key', msgstr: [ 'myvalue' ] }
}
}import po2js from 'gettext-converter/po2js'
const res = po2js(po)
// res is like jsimport js2po from 'gettext-converter/js2po'
const res = js2po(js)
// res is like poconst i18nextJs = { 'my-key': 'myvalue' }
import po2i18next from 'gettext-converter/po2i18next'
const res = po2i18next(po)
// res is like i18nextJsimport i18next2po from 'gettext-converter/i18next2po'
const res = i18next2po('en', i18nextJs)
// res is like po
```### i18next json format v4 support
```javascript
const i18nextJs = {
'key_one': 'a value',
'key_other': 'some values'
}import i18next2po from 'gettext-converter/i18next2po'
const res = i18next2po('en', i18nextJs, { compatibilityJSON: 'v4' })import po2i18next from 'gettext-converter/po2i18next'
const res = po2i18next(po, { compatibilityJSON: 'v4' })
```