l10n-tools-compiler-json
raw JSON → 7.0.10 verified Fri May 01 auth: no javascript
A JSON compiler for the l10n-tools i18n pipeline, targeting formats like vue-i18n, node-i18n, and i18next. Current stable version is 7.0.10, updated as part of a monorepo with active releases. It depends on l10n-tools-core ^8.0.0 as a peer dependency and requires Node.js >=22.19.0. Compared to other l10n compilers, it is specifically designed to integrate with the l10n-tools ecosystem, providing a unified workflow for extracting, compiling, and syncing translations.
Common errors
error Error: Cannot find module 'l10n-tools-compiler-json' ↓
cause Package is not installed or Node.js version is below 22.19.0.
fix
Run
npm install l10n-tools-compiler-json and ensure Node.js >=22.19.0. error TypeError: compileJson is not a function ↓
cause Trying to use the default export as a named import, or vice versa.
fix
Use
import compileJson from 'l10n-tools-compiler-json' for default export or import { compileJson } for named export. error Error [ERR_REQUIRE_ESM]: require() of ES Module ↓
cause Using CommonJS require() to import an ESM-only package.
fix
Switch to ESM (use import) or use dynamic import: const { compileJson } = await import('l10n-tools-compiler-json').
Warnings
breaking Package requires Node.js >=22.19.0. Older versions will fail to install or run. ↓
fix Upgrade Node.js to v22.19.0 or later.
gotcha l10n-tools-compiler-json is ESM-only. It cannot be imported via require() in CommonJS modules. ↓
fix Use dynamic import() if needed: const { compileJson } = await import('l10n-tools-compiler-json').
deprecated The `format: 'i18next'` option will be removed in v8. Use `format: 'i18next-v4'` instead. ↓
fix Replace 'i18next' with 'i18next-v4' in the options.
Install
npm install l10n-tools-compiler-json yarn add l10n-tools-compiler-json pnpm add l10n-tools-compiler-json Imports
- default wrong
const compileJson = require('l10n-tools-compiler-json')correctimport compileJson from 'l10n-tools-compiler-json' - compileJson wrong
import compileJson from 'l10n-tools-compiler-json/compile'correctimport { compileJson } from 'l10n-tools-compiler-json' - CompilerOptions
import type { CompilerOptions } from 'l10n-tools-compiler-json'
Quickstart
import { compileJson } from 'l10n-tools-compiler-json';
const source = {
en: { greeting: 'Hello' },
fr: { greeting: 'Bonjour' }
};
const options = {
format: 'vue-i18n',
namespace: 'common'
};
compileJson(source, options)
.then(result => console.log(JSON.stringify(result, null, 2)))
.catch(err => console.error(err));