What is @lingui/macro?
@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.
What are @lingui/macro's main functionalities?
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'
});
Other packages similar to @lingui/macro
react-intl
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
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
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.
@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.
Installation & Usage
See the reference documentation.
License
MIT