Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@lingui/macro
Advanced tools
@lingui/macro is a package that provides macros for internationalization (i18n) in JavaScript and React applications. It allows developers to mark strings for translation and handle pluralization, among other i18n tasks, in a way that integrates seamlessly with the LinguiJS framework.
Translation
The `t` macro is used to mark strings for translation. This allows the string to be extracted and translated into different languages.
import { t } from '@lingui/macro';
const message = t`Hello, World!`;
Pluralization
The `plural` macro handles pluralization based on a count. It allows you to define different strings for singular and plural forms.
import { plural } from '@lingui/macro';
const message = plural(count, {
one: '# book',
other: '# books'
});
Select
The `select` macro is used for gender-based or other categorical selections. It allows you to define different strings based on the value of a variable.
import { select } from '@lingui/macro';
const message = select(gender, {
male: 'He is a developer.',
female: 'She is a developer.',
other: 'They are a developer.'
});
Date and Time Formatting
The `date` macro formats dates according to the specified options. This is useful for displaying dates in a localized format.
import { date } from '@lingui/macro';
const message = date(new Date(), {
year: 'numeric',
month: 'long',
day: 'numeric'
});
react-intl is a popular library for internationalization in React applications. It provides components and an API to format dates, numbers, and strings, and to handle pluralization and translations. Compared to @lingui/macro, react-intl is more component-based and may require more boilerplate code.
i18next is a full-featured i18n framework for JavaScript. It supports translation, pluralization, and formatting, and can be used with various front-end frameworks including React. i18next is more flexible and can be used in a wider range of environments compared to @lingui/macro, which is more tightly integrated with LinguiJS.
formatjs is a set of libraries for internationalization in JavaScript, including react-intl. It provides low-level APIs for formatting dates, numbers, and strings, and for handling pluralization and translations. formatjs offers more granular control over i18n tasks compared to @lingui/macro.
Babel Macros which transforms tagged template literals and JSX components to ICU MessageFormat.
@lingui/macro
is part of LinguiJS. See the documentation
for all information, tutorials and examples.
npm install --save-dev @lingui/macro
# yarn add --dev @lingui/macro
See the reference documentation.
import { setupI18n } from "@lingui/core"
import { t } from "@lingui/macro"
const i18n = setupI18n()
const message = i18n._(t`Hello, my name is ${name} and today is ${date(now)}`)
// line above is transformed using babel-plugin-macros to this
// const message = i18n._(/*i18n*/{ id: "Hello, my name is {name} and today is {now,date}", values: { name, now }})
4.6.0 (2023-12-01)
FAQs
Macro for generating messages in ICU MessageFormat syntax
The npm package @lingui/macro receives a total of 121,673 weekly downloads. As such, @lingui/macro popularity was classified as popular.
We found that @lingui/macro demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.