{"id":25623,"library":"gettext-to-messageformat","title":"gettext-to-messageformat","description":"Converts gettext .po, .pot, and .mo files into messageformat-compatible JSON. Version 0.4.0, released as a stable library with no further updates expected. It uses gettext-parser under the hood and provides functions parsePo and parseMo that return headers, a plural function, and translations object. The plural function can be derived from the Plural-Forms header or provided manually. Key differentiator: bridges the gap between gettext tooling and messageformat-based internationalization in JavaScript, with support for plural forms and context.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/eemeli/gettext-to-messageformat","tags":["javascript","messageformat","gettext","po","plural-forms","i18n"],"install":[{"cmd":"npm install gettext-to-messageformat","lang":"bash","label":"npm"},{"cmd":"yarn add gettext-to-messageformat","lang":"bash","label":"yarn"},{"cmd":"pnpm add gettext-to-messageformat","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Parses .po/.mo files","package":"gettext-parser","optional":false}],"imports":[{"note":"CommonJS require works; no default export.","wrong":"const parsePo = require('gettext-to-messageformat').parsePo","symbol":"parsePo","correct":"const { parsePo } = require('gettext-to-messageformat')"},{"note":"ESM import only with named exports; no default export.","wrong":"import parseMo from 'gettext-to-messageformat'","symbol":"parseMo","correct":"import { parseMo } from 'gettext-to-messageformat'"},{"note":"Both CJS and ESM supported.","wrong":"const { parsePo, parseMo } = require('gettext-to-messageformat')","symbol":"parsePo, parseMo","correct":"import { parsePo, parseMo } from 'gettext-to-messageformat'"}],"quickstart":{"code":"const { parsePo } = require('gettext-to-messageformat');\nconst { headers, pluralFunction, translations } = parsePo(`\nmsgid \"\"\nmsgstr \"\"\n\"Language: pl\\n\"\n\"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\\n\"\n\nmsgid \"Time: %1 second\"\nmsgid_plural \"Time: %1 seconds\"\nmsgstr[0] \"Czas: %1 sekunda\"\nmsgstr[1] \"Czas: %1 sekundy\"\nmsgstr[2] \"Czas: %1 sekund\"\n`);\nconst MessageFormat = require('messageformat');\nconst mf = new MessageFormat({ [headers.Language]: pluralFunction });\nconst messages = mf.compile(translations);\nconsole.log(messages['Time: %1 second']([1]));\n// 'Czas: 1 sekunda'","lang":"javascript","description":"Parses a .po file with plural forms and uses messageformat to format a pluralized message."},"warnings":[{"fix":"Use `sort` option instead of `sortByMsgId`.","message":"In v0.4.0, the option `sortByMsgId` was renamed to `sort`.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Access header keys with canonical case (e.g., 'Language' instead of 'language').","message":"In v0.4.0, output headers now use canonical case instead of forced lower-case.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Upgrade Node.js to >=6.0.","message":"Node.js 6.0 is the minimum engine; older versions may break with deps.","severity":"deprecated","affected_versions":">=0.3.0"},{"fix":"Check if pluralFunction is null and provide a fallback if needed.","message":"If no headers are found, pluralFunction may be null; you must handle that.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.4.0':18 'base':78 'bridg':69 'compat':15 'context':88 'convert':5 'deriv':57 'differenti':68 'expect':28 'file':11 'form':62,86,95 'function':39,48,54 'gap':71 'gettext':2,6,32,73,91 'gettext-pars':31 'gettext-to-messageformat':1 'header':45,63 'hood':36 'i18n':96 'internation':79 'javascript':81,89 'json':16 'key':67 'librari':23 'manual':66 'messageformat':4,14,77,90 'messageformat-bas':76 'messageformat-compat':13 'mo':10 'object':51 'parsemo':42 'parsepo':40 'parser':33 'plural':47,53,61,85,94 'plural-form':60,93 'po':7,92 'pot':8 'provid':38,65 'releas':19 'return':44 'stabl':22 'support':83 'tool':74 'translat':50 'updat':27 'use':30 'version':17","created_at":"2026-05-01T13:45:43.770360+00:00","updated_at":"2026-05-01T13:45:43.770360+00:00","problems":[{"fix":"Run `npm install gettext-to-messageformat` and ensure the import path is correct.","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'gettext-to-messageformat'"},{"fix":"Use `const { parsePo } = require('gettext-to-messageformat')` or `import { parsePo } from 'gettext-to-messageformat'`.","cause":"Incorrect import (default vs named).","error":"TypeError: parsePo is not a function"},{"fix":"Ensure the input is a valid .po or .mo file content as a string or Buffer.","cause":"Input string is not valid gettext format.","error":"Invalid or unexpected token"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/eemeli/gettext-to-messageformat","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/gettext-to-messageformat","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-05-01","next_check":"2026-07-30","install_tag":null}}