@lingui/core 6.6.0 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -6
- package/dist/index.mjs +12 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -4,23 +4,46 @@
|
|
|
4
4
|
|
|
5
5
|
# @lingui/core
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> The Lingui i18n runtime: loads compiled message catalogs, tracks the active locale and formats ICU MessageFormat messages
|
|
8
8
|
|
|
9
|
-
`@lingui/core` is part of [
|
|
9
|
+
`@lingui/core` is part of [Lingui][documentation]. 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.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
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][babel-plugin] or [SWC][swc-plugin] plugin.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { i18n } from "@lingui/core"
|
|
17
|
+
import { t } from "@lingui/core/macro"
|
|
18
|
+
import { messages } from "./locales/cs/messages"
|
|
19
|
+
|
|
20
|
+
i18n.load("cs", messages)
|
|
21
|
+
i18n.activate("cs")
|
|
22
|
+
|
|
23
|
+
function greeting(name) {
|
|
24
|
+
return t`Hello ${name}`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
greeting("Fred") // "Ahoj Fred"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The `messages` module is produced by `lingui extract` and `lingui compile` from [`@lingui/cli`][cli]. Catalogs are compiled ahead of time, so the runtime ships without a MessageFormat parser.
|
|
31
|
+
|
|
32
|
+
The [JavaScript tutorial][tutorial] walks through this setup. React projects use [`@lingui/react`][react] on top of this package. See the [core reference][reference] and the [macro reference][macro] for the full API.
|
|
14
33
|
|
|
15
34
|
## License
|
|
16
35
|
|
|
17
|
-
This package is licensed under [MIT][license] license.
|
|
36
|
+
This package is licensed under the [MIT][license] license.
|
|
18
37
|
|
|
19
38
|
[license]: https://github.com/lingui/js-lingui/blob/main/LICENSE
|
|
20
|
-
[linguijs]: https://github.com/lingui/js-lingui
|
|
21
39
|
[documentation]: https://lingui.dev
|
|
22
40
|
[tutorial]: https://lingui.dev/tutorials/javascript
|
|
23
41
|
[reference]: https://lingui.dev/ref/core
|
|
42
|
+
[macro]: https://lingui.dev/ref/macro
|
|
43
|
+
[cli]: https://www.npmjs.com/package/@lingui/cli
|
|
44
|
+
[react]: https://www.npmjs.com/package/@lingui/react
|
|
45
|
+
[babel-plugin]: https://lingui.dev/installation#choosing-a-transpiler
|
|
46
|
+
[swc-plugin]: https://lingui.dev/ref/swc-plugin
|
|
24
47
|
[package]: https://www.npmjs.com/package/@lingui/core
|
|
25
48
|
[badge-downloads]: https://img.shields.io/npm/dw/@lingui/core.svg
|
|
26
49
|
[badge-version]: https://img.shields.io/npm/v/@lingui/core.svg
|
package/dist/index.mjs
CHANGED
|
@@ -156,7 +156,12 @@ const getDefaultFormats = (locale, passedLocales, formats = {}) => {
|
|
|
156
156
|
time: (value, format) => time(locales, value, style(format) || format)
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
|
-
const selectFormatter = (value, rules) =>
|
|
159
|
+
const selectFormatter = (value, rules) => (
|
|
160
|
+
// Own-property check so a runtime value like "constructor" or "toString"
|
|
161
|
+
// falls back to the `other` branch instead of resolving to a member
|
|
162
|
+
// inherited from Object.prototype.
|
|
163
|
+
(Object.prototype.hasOwnProperty.call(rules, value) ? rules[value] : void 0) ?? rules.other
|
|
164
|
+
);
|
|
160
165
|
function interpolate(translation, locale, locales) {
|
|
161
166
|
return (values = {}, formats) => {
|
|
162
167
|
const formatters = getDefaultFormats(locale, locales, formats);
|
|
@@ -274,7 +279,10 @@ class I18n extends EventEmitter {
|
|
|
274
279
|
return this;
|
|
275
280
|
}
|
|
276
281
|
_load(locale, messages) {
|
|
277
|
-
const maybeMessages =
|
|
282
|
+
const maybeMessages = Object.prototype.hasOwnProperty.call(
|
|
283
|
+
this._messages,
|
|
284
|
+
locale
|
|
285
|
+
) ? this._messages[locale] : void 0;
|
|
278
286
|
if (!maybeMessages) {
|
|
279
287
|
this._messages[locale] = messages;
|
|
280
288
|
} else {
|
|
@@ -325,7 +333,8 @@ class I18n extends EventEmitter {
|
|
|
325
333
|
message = id.message;
|
|
326
334
|
id = id.id;
|
|
327
335
|
}
|
|
328
|
-
const
|
|
336
|
+
const messages = this.messages;
|
|
337
|
+
const messageForId = Object.prototype.hasOwnProperty.call(messages, id) ? messages[id] : void 0;
|
|
329
338
|
const messageMissing = messageForId === void 0;
|
|
330
339
|
const missing = this._missing;
|
|
331
340
|
if (missing && messageMissing) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/core",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "The Lingui i18n runtime: loads compiled message catalogs, tracks the active locale and formats ICU MessageFormat messages",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Tomáš Ehrlich",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"macro/index.mjs"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@lingui/babel-plugin-lingui-macro": "6.
|
|
59
|
-
"@lingui/message-utils": "6.
|
|
58
|
+
"@lingui/babel-plugin-lingui-macro": "6.7.0",
|
|
59
|
+
"@lingui/message-utils": "6.7.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@lingui/test-utils": "3.0.3",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"unbuild": {
|
|
76
76
|
"declaration": "node16"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "a2d4b6d42e052fed1d432050b20cc56cfdacfe98"
|
|
79
79
|
}
|