{"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,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","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,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}