Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@messageformat/runtime
Advanced tools
@messageformat/runtime is a runtime library for handling message formatting in JavaScript. It allows for the creation of localized messages using ICU MessageFormat syntax, which supports pluralization, gender, and other complex message formatting needs.
Basic Message Formatting
This feature allows you to create and compile basic messages with placeholders that can be replaced with dynamic values.
const { MessageFormat } = require('@messageformat/runtime');
const mf = new MessageFormat('en');
const msg = mf.compile('Hello, {name}!');
console.log(msg({ name: 'Alice' })); // Output: Hello, Alice!
Pluralization
This feature supports pluralization, allowing you to format messages differently based on the quantity of items.
const { MessageFormat } = require('@messageformat/runtime');
const mf = new MessageFormat('en');
const msg = mf.compile('{count, plural, one {# item} other {# items}}');
console.log(msg({ count: 1 })); // Output: 1 item
console.log(msg({ count: 5 })); // Output: 5 items
Gender Formatting
This feature allows for gender-based message formatting, enabling different messages based on the gender of the subject.
const { MessageFormat } = require('@messageformat/runtime');
const mf = new MessageFormat('en');
const msg = mf.compile('{gender, select, male {He} female {She} other {They}} will respond soon.');
console.log(msg({ gender: 'male' })); // Output: He will respond soon.
console.log(msg({ gender: 'female' })); // Output: She will respond soon.
intl-messageformat is a library for formatting ICU MessageFormat strings. It provides similar functionality to @messageformat/runtime, including support for pluralization and gender formatting. However, it is part of the larger FormatJS suite, which offers additional tools for internationalization.
i18next is a comprehensive internationalization framework for JavaScript. It supports message formatting, including pluralization and gender, but also offers features like language detection, interpolation, and more. It is more feature-rich compared to @messageformat/runtime, but may be overkill for simple message formatting needs.
react-intl is a library specifically designed for internationalizing React applications. It provides components and APIs for formatting dates, numbers, and messages, including support for ICU MessageFormat. It is more specialized for React, whereas @messageformat/runtime is a more general-purpose solution.
A collection of messageformat runtime utility functions.
npm install @messageformat/runtime
This package should be marked as a dependency for any package that publishes the output of compileModule(), as the compiled ES source output may include references to it.
For applications that bundle their output using e.g. Webpack this is not necessary.
The Messages
accessor class is a completely optional addition.
See also @messageformat/react for a React-specific solution.
This package was previously named messageformat-runtime.
Messageformat is an OpenJS Foundation project, and we follow its Code of Conduct.
FAQs
Runtime components of messageformat
The npm package @messageformat/runtime receives a total of 305,665 weekly downloads. As such, @messageformat/runtime popularity was classified as popular.
We found that @messageformat/runtime demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.