messageformat-convert
raw JSON → 0.4.0 verified Fri May 01 auth: no javascript maintenance
Convert input formats (e.g., Rails i18n YAML) into messageformat-compatible JSON. Version 0.4.0 is the latest stable release. The package is part of the messageformat ecosystem but has seen no recent updates or releases. It supports Node.js >=6.0 and converts Rails-style nested key-value pairs into flat message format strings. Note that this package does not handle MessageFormat 2.0 (MF2) syntax, only the legacy ICU MessageFormat format used by messageformat 2.x and 3.x.
Common errors
error SyntaxError: Unexpected token 'export' ↓
cause Package is ESM-only but project uses CommonJS (require).
fix
Use import instead: import convert from 'messageformat-convert'; or set type: 'module' in package.json.
error TypeError: convert is not a function ↓
cause Wrong import style: using named import { convert } instead of default import.
fix
Use: import convert from 'messageformat-convert';
Warnings
gotcha Package is outdated and may not support modern node versions or MF2 syntax. Use messageformat 4.x with its own converters for MF2. ↓
fix Consider using messageformat's built-in adapters or the @messageformat/icu-messageformat-1 package for legacy ICU support.
deprecated The convert function expects a flat object; nested structures are not handled correctly. It does not perform deep conversion. ↓
fix Flatten your structure manually before passing, or use a library like flat.
gotcha No TypeScript typings included. Using with TypeScript may require manual type definitions. ↓
fix Install @types/messageformat-convert or declare module 'messageformat-convert'.
Install
npm install messageformat-convert yarn add messageformat-convert pnpm add messageformat-convert Imports
- convert wrong
const convert = require('messageformat-convert')correctimport { convert } from 'messageformat-convert' - convert wrong
import { convert } from 'messageformat-convert'correctimport convert from 'messageformat-convert' - convert wrong
const { convert } = require('messageformat-convert')correctimport convert from 'messageformat-convert'
Quickstart
import convert from 'messageformat-convert';
import yaml from 'js-yaml';
import fs from 'fs';
const railsI18n = yaml.load(fs.readFileSync('config/locales/en.yml', 'utf8'));
// railsI18n might be: { en: { greeting: 'Hello', farewell: 'Goodbye' } }
const mfData = convert(railsI18n.en);
console.log(mfData);
// Output: { greeting: 'Hello', farewell: 'Goodbye' }