Messageformat is a JavaScript library that provides a way to format messages with pluralization, gender, and variable substitution. It is useful when dealing with internationalization (i18n) and localization (l10n) of web applications.


Messageformat was first created by James Sewell in 2010 while working on the Firefox OS project at Mozilla. It was originally designed to handle the complex pluralization rules of languages like Arabic, Russian, and Polish. Since then, it has been used in many other projects and has become a popular tool for i18n and l10n.


Messageformat supports a variety of features that make it a powerful tool for i18n and l10n. Some of these features include:

  • Pluralization: Messageformat can handle complex pluralization rules for many languages.
  • Gender: Messageformat can handle gender-specific messages for languages that have them.
  • Variable substitution: Messageformat can substitute variables in messages, making it easy to reuse messages with different values.
  • Message nesting: Messageformat allows messages to be nested, making it easy to reuse common phrases across an application.
  • Custom formats: Messageformat allows developers to define their own custom formats for messages.


To use Messageformat in a JavaScript application, first include the library in your project. Then, create a new instance of the Messageformat class and use its format method to format messages.

Here's an example:


// Include Messageformat

const Messageformat = require('messageformat');

// Create a new instance

const mf = new Messageformat('en');

// Define a message

const message = mf.compile('Hello, {name}!');

// Format the message

const result = message({ name: 'World' });

console.log(result); // "Hello, World!"


In this example, we create a new instance of the Messageformat class and use its compile method to define a message. We then use the message method to format the message with a variable substitution.


Messageformat is a powerful tool for i18n and l10n in JavaScript applications. Its support for pluralization, gender, variable substitution, message nesting, and custom formats make it a versatile and flexible library. By using Messageformat, developers can easily create applications that can be localized for users around the world.