Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@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 }})
FAQs
Macro for generating messages in ICU MessageFormat syntax
The npm package @lingui/macro receives a total of 103,158 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.