Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

gettext-converter

locize289.8kMIT1.3.0

po2js and js2po and i18next2po and po2i18next converter gettext resource utils

gettext, json, js, translation, converter

readme

travis npm

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

npm install --save gettext-converter

You can then import or require() gettext-converter as normal:

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:

import po2js from 'gettext-converter/po2js'
// or
const po2js = require('gettext-converter/cjs/po2js')

Usage


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 js

import js2po from 'gettext-converter/js2po'
const res = js2po(js)
// res is like po


const i18nextJs = { 'my-key': 'myvalue' }

import po2i18next from 'gettext-converter/po2i18next'
const res = po2i18next(po)
// res is like i18nextJs

import i18next2po from 'gettext-converter/i18next2po'
const res = i18next2po('en', i18nextJs)
// res is like po

i18next json format v4 support

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' })

changelog

1.3.0

  • feat: introduce fallbackToMsgId option 12

1.2.4

  • fix: key separator at the end of string not handled properly 9

1.2.3

  • fix keyasareference option causes "corrupted" po file 7

1.2.2

  • do not crash when ns is null

1.2.1

  • fix suffix fallback in flatten

1.2.0

  • compatibility with i18next-conv

1.1.3

  • fix esm import

1.1.2

  • overriding the plurals option for i18next-gettext-converter

1.1.1

  • separate i18next2js

1.1.0

  • introduce i18next v4 json format support

1.0.8

  • plurals fix for kk

1.0.7

  • plurals for tl

1.0.6

  • plurals for ht and iw

1.0.5

  • fix Macedonian plural formula
  • transpile also esm

1.0.4

  • fix plural rules for python

1.0.3

  • fix export for node v14 cjs

1.0.2

  • fix export for dynamic imports

1.0.1

  • plurals: dev fallback

1.0.0

  • first version