npm.io
6.12.0 • Published 5d ago

@lingui/core

Licence
MIT
Version
6.12.0
Deps
2
Size
43 kB
Vulns
0
Weekly
0
Stars
5.9K

License Version Downloads

@lingui/core

The Lingui i18n runtime: loads compiled message catalogs, tracks the active locale and formats ICU MessageFormat messages

@lingui/core is part of Lingui. Lingui is a lightweight, open-source internationalization (i18n) library for JavaScript and TypeScript. It brings compile-time macros and a CLI for message extraction to React, React Native, Vue, SolidJS, Astro, Svelte, and Node.js.

The package is framework-agnostic and behaves the same in the browser, in Node.js and inside any UI framework. @lingui/core exports the i18n instance, which loads catalogs, activates a locale and translates messages. @lingui/core/macro exports the t, plural, select and related macros, which are compiled into ICU messages at build time and need the Babel or SWC plugin.

Usage

import { i18n } from "@lingui/core"
import { t } from "@lingui/core/macro"
import { messages } from "./locales/cs/messages"

i18n.load("cs", messages)
i18n.activate("cs")

function greeting(name) {
  return t`Hello ${name}`
}

greeting("Fred") // "Ahoj Fred"

The messages module is produced by lingui extract and lingui compile from @lingui/cli. Catalogs are compiled ahead of time, so the runtime ships without a MessageFormat parser.

The JavaScript tutorial walks through this setup. React projects use @lingui/react on top of this package. See the core reference and the macro reference for the full API.

License

This package is licensed under the MIT license.

Keywords