{"id":25848,"library":"l10n-tools-compiler-gettext","title":"l10n-tools-compiler-gettext","description":"A compiler plugin for the l10n-tools ecosystem that handles PO/MO file formats for internationalization workflows. Current stable version is 7.0.10, requiring Node >=22.19.0 and npm >=10.9.0. It is part of the l10n-tools monorepo and depends on l10n-tools-core ^8.0.0, which dropped PHP gettext support in v8.0.0 (a breaking change). This package is TypeScript-native, ESM-only, and designed for CLI-based translation compilation. Unlike standalone gettext parsers, it integrates tightly with l10n-tools's pipeline and is intended for use with l10n-tools-cli or programmatically via the core API. Release cadence follows the monorepo's weekly/biweekly schedule.","status":"active","version":"7.0.10","language":"javascript","source_language":"en","source_url":"https://github.com/tpcint/l10n-tools","tags":["javascript","typescript"],"install":[{"cmd":"npm install l10n-tools-compiler-gettext","lang":"bash","label":"npm"},{"cmd":"yarn add l10n-tools-compiler-gettext","lang":"bash","label":"yarn"},{"cmd":"pnpm add l10n-tools-compiler-gettext","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for core types and compiler interfaces","package":"l10n-tools-core","optional":false}],"imports":[{"note":"Package is ESM-only and does not export a CommonJS version. TypeScript types are bundled.","wrong":"const GettextCompiler = require('l10n-tools-compiler-gettext')","symbol":"GettextCompiler","correct":"import { GettextCompiler } from 'l10n-tools-compiler-gettext'"},{"note":"compileGettext is a named export, not a default export.","wrong":"import compileGettext from 'l10n-tools-compiler-gettext'","symbol":"compileGettext","correct":"import { compileGettext } from 'l10n-tools-compiler-gettext'"},{"note":"Available since v7.0.0. For parsing .po files without compilation.","wrong":null,"symbol":"parsePo","correct":"import { parsePo } from 'l10n-tools-compiler-gettext'"}],"quickstart":{"code":"import { compileGettext } from 'l10n-tools-compiler-gettext';\nimport { readFileSync, writeFileSync } from 'node:fs';\n\nconst poContent = readFileSync('messages.po', 'utf-8');\nconst compiled = compileGettext(poContent, {\n  sourceLocale: 'en',\n  targetLocale: 'fr',\n  domain: 'messages',\n});\nwriteFileSync('messages.mo', compiled);\nconsole.log('Compiled .mo file written.');","lang":"typescript","description":"Show reading a .po file, compiling it with compileGettext, and writing the .mo output. Minimal setup with TypeScript."},"warnings":[{"fix":"Update l10n-tools-core to ^8.0.0 and ensure your code does not rely on the removed PHP gettext support.","message":"l10n-tools-core bumped from ^7.x to ^8.0.0 requiring peer dependency update","severity":"breaking","affected_versions":">=7.0.10 <7.5.3"},{"fix":"Use a compat shim or preprocess files to remove PHP-specific metadata.","message":"Deprecation of PHP gettext support may affect users processing PHP-generated .po files","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Use import syntax or dynamic import(). Ensure parent package is also ESM or uses a bundler that supports ESM.","message":"Package is ESM-only; require() will throw ERR_REQUIRE_ESM","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"Ensure you pass a string. Use parsePo() first if you need to inspect or modify the parsed structure.","message":"compileGettext expects raw PO string, not parsed object","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"Update to latest version and pass options as flat object instead of nested structure.","message":"The compileGettext function signature changed in v7.5.0: options parameter flattened","severity":"deprecated","affected_versions":"<7.5.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import syntax or dynamic import(). Alternatively, set { type: 'module' } in package.json.","cause":"Package is ESM-only and cannot be required via CommonJS.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /.../node_modules/l10n-tools-compiler-gettext/index.js from /.../app.js not supported."},{"fix":"Change to: import { compileGettext } from 'l10n-tools-compiler-gettext'","cause":"Default import used instead of named import.","error":"TypeError: compileGettext is not a function"},{"fix":"Install l10n-tools-core: npm install l10n-tools-core@^8.0.0","cause":"Missing peer dependency l10n-tools-core.","error":"Error: Cannot find module 'l10n-tools-core'"},{"fix":"Rename file to .mjs or add 'type': 'module' to package.json.","cause":"Trying to run ESM code in a CommonJS context without type:module or .mjs extension.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}