{"id":16048267,"url":"https://github.com/i18next/i18next-gettext-converter","last_synced_at":"2025-05-15T01:07:02.771Z","repository":{"id":4532278,"uuid":"5672511","full_name":"i18next/i18next-gettext-converter","owner":"i18next","description":"converts gettext .mo or .po to 18next json format and vice versa","archived":false,"fork":false,"pushed_at":"2025-05-01T16:54:25.000Z","size":2273,"stargazers_count":199,"open_issues_count":10,"forks_count":56,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-05T17:38:31.809Z","etag":null,"topics":["gettext","json"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/i18next.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["jamuhl","adrai"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://locize.com"}},"created_at":"2012-09-04T13:03:34.000Z","updated_at":"2025-05-01T16:53:23.000Z","dependencies_parsed_at":"2024-02-01T18:08:47.026Z","dependency_job_id":"f18d7bda-f822-47b7-9f83-07e72d22fb9e","html_url":"https://github.com/i18next/i18next-gettext-converter","commit_stats":{"total_commits":393,"total_committers":39,"mean_commits":"10.076923076923077","dds":0.6055979643765903,"last_synced_commit":"6b86848c7e99a1da2670fa15f200745bb1f25fdf"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-gettext-converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-gettext-converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-gettext-converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-gettext-converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i18next","download_url":"https://codeload.github.com/i18next/i18next-gettext-converter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253000384,"owners_count":21838334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gettext","json"],"created_at":"2024-10-09T00:05:44.278Z","updated_at":"2025-05-15T01:06:57.729Z","avatar_url":"https://github.com/i18next.png","language":"JavaScript","funding_links":["https://github.com/sponsors/jamuhl","https://github.com/sponsors/adrai","https://locize.com"],"categories":[],"sub_categories":[],"readme":"# i18next-gettext-converter\n\n[![Build Status][build-badge]][build]\n[![npm package][npm-badge]][npm]\n[![Coverage Status][coveralls-badge]][coveralls]\n\n## Introduction\n\nProject goal is to convert files from gettext to i18next json format and vice versa.\n\n## Installation\n\n1. first install node.js from [nodejs.org](http://nodejs.org/).\n2. `npm install i18next-conv -g`\n\nFor i18next \u003c 2.0.0 use i18next-conv@1.11.0, for i18next \u003c 3.0.0 use i18next-conv@2.6.1, for i18next \u003c 12.0.0 use i18next-conv@\u003c8.\n\n## Usage\n\n### convert .mo or .po to i18next json\n\nin your console type:\n\n\n__for help:__\n\n````\ni18next-conv -h\n````\n\n__to convert a .mo or .po file to i18next json:__\n\n````\ni18next-conv -l [locale] -s [sourcePath] -t [targetPath]\n````\n\neg.: i18next-conv -l en -s ./locales/en.po -t ./locales/en/translation.json\n\n\n_if no target (-t) is specified file will be stored to [sourceDir]/[locale]/translation.json._\n\n__to convert i18next json to a .mo or .po file:__\n\n````\ni18next-conv -l [locale] -s [sourcePath] -t [targetPath]\n````\n\neg.: i18next-conv -l en -s ./locales/en.translation.json -t ./locales/en/translation.mo (or .po)\n\n_if no target (-t) is specified file will be stored to [sourceDir]/[locale]/translation.po._\n\n\n__for utf8-encoded po-files add these lines to your po file:__\n\n````\n\"Content-Type: text/plain; charset=UTF-8\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"\n````\n\nIt is necessary if you get corrupted output from the command above.\n\n__to filter incoming po-file translations, pass the path to a module that exports a filter function:__\n\n````\ni18next-conv -l [locale] -s [sourcePath] -t [targetPath] -f [filterPath]\n````\n\neg.: i18next-conv -l en -s ./locales/en.po -t ./locales/en/translation.json -f ./filter.js\n\nThe filter module should export a single function that accepts the gettext object, the locale and a callback\nas its arguments. For the full API of the gettext object, check [node-gettext](https://github.com/alexanderwallin/node-gettext).\nThe function can then add/edit/delete translations, invoking the callback with an error object and the\ntranslation table.\n\neg.\n\n```javascript\n// Delete all keys which do not belong to the frontend\nmodule.exports = function (gt, locale, callback) {\n  const clientSideSource = '/frontend/';\n  const domain = 'messages';\n  const translations = gt.catalogs[locale][domain].translations;\n  gt.setLocale(locale); // Needed for when getComment is called\n\n  Object.keys(translations).forEach(ctxt =\u003e {\n    Object.keys(translations[ctxt]).forEach(key =\u003e {\n      const comment = gt.getComment('messages', ctxt, key);\n      if (comment) {\n        if (comment.reference \u0026\u0026 comment.reference.indexOf(clientSideSource) === -1) {\n          delete translations[ctxt][key];\n        }\n      }\n    });\n  });\n\n  callback(null, translations);\n};\n```\n\n## Options\n\n```js\nprogram\n.version(i18nextConv.version)\n.option('-b, --base [path]', 'Specify path for the base language file. only take effect with -K option', '')\n.option('-f, --filter \u003cpath\u003e', 'Specify path to gettext filter')\n.option('-l, --language \u003clocale\u003e', 'Specify the language code, eg. \\'en\\'')\n.option('-p, --pot', 'Generate POT file.')\n.option('-s, --source \u003cpath\u003e', 'Specify path to read from')\n.option('-t, --target [path]', 'Specify path to write to', '')\n.option('-K, --keyasareference', 'Deal with the reference comment as a key', false)\n.option('-k, --keyseparator [path]', 'Specify keyseparator you want to use, defaults to ##', '##')\n.option('-P, --plurals \u003cpath\u003e', 'Specify path to plural forms definitions')\n.option('--project \u003cproject\u003e', 'Specify the project-id-version when converting json to gettext')\n.option('--quiet', 'Silence output', false)\n.option('--gettextDefaultCharset', 'Default charset when parsing gettext files with gettext-parser', 'UTF-8')\n.option('--skipUntranslated', 'Skip untranslated keys when converting into json', false)\n.option('--splitNewLine', 'Silence output', false)\n.option('--ctxSeparator [sep]', 'Specify the context separator', '_')\n.option('--ignorePlurals', 'Do not process the plurals')\n.option('--compatibilityJSON \u003cver\u003e', \"Set to 'v4' to generate i18next@21 compatible json files\")\n.option('--foldLength', 'Specify the character fold length for strings', 76)\n.option('--noDate', 'Removes timestamp related lines from output file (POT-Creation-Date and PO-Revision-Date lines)')\n.parse(process.argv);\n```\n\n## API\n\nThis module exposes a few functions to convert json to gettext and gettext to json. It accepts the same options as the cli.\n\n```js\nconst path = require('path');\nconst { readFileSync, writeFileSync } = require('fs');\nconst {\n  i18nextToPo,\n  i18nextToPot,\n  i18nextToMo,\n  gettextToI18next,\n} = require('i18next-conv');\n\nconst source = path.join(__dirname, '../locales/ua-UK/translation.json');\nconst options = {/* you options here */}\n\nfunction save(target) {\n  return result =\u003e {\n    writeFileSync(target, result);\n  };\n}\n\ni18nextToPo('ua-UK', readFileSync(source), options).then(save('../locales/ua-UK/translation.po'));\ni18nextToPot('ua-UK', readFileSync(source), options).then(save('../locales/ua-UK/translation.pot'));\ni18nextToMo('ua-UK', readFileSync(source), options).then(save('../locales/ua-UK/translation.mo'));\n\ngettextToI18next('ua-UK', readFileSync('../locales/ua-UK/translation.po'), options)\n.then(save('../locales/ua-UK/translation.json'));\n\n```\n\n\n## All credits go to\n\n- [andri9's node-gettext](https://github.com/andris9/node-gettext) for parsing .mo and .po files\n- [TJ Holowaychuk's commander.js](https://github.com/visionmedia/commander.js/) for console program\n\n## License\n\nSee the [LICENSE](LICENSE.md) file for license rights and limitations.\n\n[build-badge]: https://img.shields.io/github/actions/workflow/status/i18next/i18next-gettext-converter/test.yml?event=push\u0026style=flat-square\n[build]: https://github.com/i18next/i18next-gettext-converter/actions\n\n[npm-badge]: https://img.shields.io/npm/v/i18next-conv.svg?style=flat-square\n[npm]: https://www.npmjs.org/package/i18next-conv\n\n[coveralls-badge]: https://img.shields.io/coveralls/i18next/i18next-gettext-converter/master.svg?style=flat-square\n[coveralls]: https://coveralls.io/r/i18next/i18next-gettext-converter\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi18next%2Fi18next-gettext-converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi18next%2Fi18next-gettext-converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi18next%2Fi18next-gettext-converter/lists"}