Socket
Socket
Sign inDemoInstall

@lingui/macro

Package Overview
Dependencies
39
Maintainers
1
Versions
110
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @lingui/macro

Macro for generating messages in ICU MessageFormat syntax


Version published
Weekly downloads
127K
increased by4.55%
Maintainers
1
Install size
2.10 MB
Created
Weekly downloads
 

Package description

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

Readme

Source

License Version Downloads Babel 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

npm install --save-dev @lingui/macro
# yarn add --dev @lingui/macro

Usage

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 }})

License

MIT

Keywords

FAQs

Last updated on 17 May 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc