Skip to content

Commit a59fdb2

Browse files
docs: Resources section improvements (#2064)
1 parent 716e5f4 commit a59fdb2

File tree

8 files changed

+218
-134
lines changed

8 files changed

+218
-134
lines changed

website/docs/misc/community.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
---
22
title: Community and Contributing
3+
description: Learn how to connect with the Lingui community and contribute to the project
34
---
45

6+
For any open-source project, the community is the backbone of success. It's the community that drives growth, provides valuable feedback, and contributes to the project in countless ways.
7+
58
## Community
69

710
Lingui has a significant number of developers as a part of its community.
811

9-
On this page we've listed some Lingui-related communities that you can be a part of; see the other pages in this section for additional online and in-person learning materials.
10-
11-
Before participating in Lingui's communities, please read our [Code of Conduct](https://github.com/lingui/js-lingui/blob/main/CODE_OF_CONDUCT.md). We expect that all community members adhere to the guidelines within.
12+
On this page, you'll find links to various Lingui-related communities you can join, as well as additional resources for learning and collaboration. Be sure to explore the other pages in this section for more learning opportunities.
1213

13-
### Stack Overflow
14-
15-
Stack Overflow is a popular forum to ask code-level questions or if you're stuck with a specific error. Read through the [existing questions](https://stackoverflow.com/questions/tagged/linguijs) tagged with `linguijs` or [ask your own](https://stackoverflow.com/questions/ask?tags=linguijs)!
14+
Before participating, please take a moment to review our [Code of Conduct](https://github.com/lingui/js-lingui/blob/main/CODE_OF_CONDUCT.md). We expect all members to follow these guidelines to ensure a positive and welcoming environment for everyone.
1615

17-
### Discussion forums
16+
### Discussion Forums
1817

19-
The [Lingui Discord server](https://discord.gg/gFWwAYnMtA) is a place where you can learn, share, and collaborate about anything and everything Lingui.
18+
The [Lingui Discord Server](https://discord.gg/gFWwAYnMtA) is a place where you can learn, share, and collaborate about anything and everything Lingui.
2019

2120
![Join the community on Discord](https://img.shields.io/discord/974702239358783608.svg?label=Discord&logo=Discord&colorB=7289da&style=flat-square)
2221

23-
- Connect with users from the community.
22+
- Connect with users in the community.
2423
- Get your questions answered and learn cool new tips and tricks.
25-
- Watch for notifications of new content from Lingui and the community.
26-
- Share your knowledge and expertise with others.
24+
- Get notifications about new content from Lingui and the community.
25+
- Share your knowledge and experience with others.
26+
27+
### Stack Overflow
28+
29+
Stack Overflow is a popular forum to ask code-level questions or if you're stuck with a specific error. Read through the [existing questions](https://stackoverflow.com/questions/tagged/linguijs) tagged with `linguijs` or [ask your own](https://stackoverflow.com/questions/ask?tags=linguijs)!
2730

2831
### News
2932

30-
For the latest news about Lingui, follow [@LinguiJS](https://twitter.com/LinguiJS) on Twitter.
33+
For the latest news about Lingui, follow [@LinguiJS](https://x.com/LinguiJS) on X.
3134

3235
## Contributing
3336

website/docs/misc/i18next.md

Lines changed: 120 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ description: Comparison of Lingui and i18next internationalization libraries
55

66
# Comparison with i18next
77

8-
[i18next](https://www.i18next.com/) is an internationalization-framework written in and for JavaScript. i18next and Lingui are two popular internationalization (i18n) libraries used for translating and localizing JS-based applications. Both libraries have their strengths and weaknesses, and which one is best for a particular project depends on the project's specific needs.
8+
[i18next](https://www.i18next.com/) is a widely used internationalization framework designed specifically for JavaScript applications. Both i18next and Lingui are popular libraries for translating and localizing JavaScript-based projects, each offering unique strengths and features.
99

10-
## Basic comparison
10+
The choice between them ultimately depends on the specific needs of your project.
1111

12-
Here is a basic example of the i18next usage:
12+
## Basic Comparison
13+
14+
Here's a simple example of how to use i18next:
1315

1416
```js
1517
import i18next from "i18next";
@@ -24,11 +26,15 @@ i18next.init({
2426
},
2527
},
2628
});
27-
// ...
29+
```
30+
31+
```js
32+
import i18next from "i18next";
33+
2834
document.getElementById("output").innerHTML = i18next.t("key");
2935
```
3036

31-
Since the Lingui v4 release, there is a core function [i18n.t(...)](/docs/ref/core.md#i18n.t) that allows doing pretty much the same thing. The following example shows how this works with Lingui:
37+
The equivalent example with Lingui looks like this:
3238

3339
```js title="lingui.config.{js,ts}"
3440
/** @type {import('@lingui/conf').LinguiConfig} */
@@ -45,48 +51,72 @@ module.exports = {
4551
```
4652

4753
```js
48-
import { i18n } from "@lingui/core";
54+
import { t } from "@lingui/core/macro";
4955

50-
document.getElementById("output").innerHTML = i18n.t({ id: "key", message: "Hello world" });
56+
document.getElementById("output").innerHTML = t`Hello world`;
5157
```
5258

53-
:::note
54-
The `message` property can be specified in the case of [Message Extraction](/docs/guides/message-extraction.md) usage flow. You can use the `i18n.t` function only with the `id`, but in this case you'll have to manage your localization catalogs yourself, without advantages of the [message extraction](/docs/guides/message-extraction.md) feature.
59+
:::tip
60+
This example uses a macro for the translation. Macros are a powerful feature of Lingui that allows you to write messages directly in your code. Read more about [Macros](/docs/ref/macro.mdx).
5561
:::
5662

63+
If you prefer to define explicit IDs for your messages, you can follow this approach:
64+
65+
```js
66+
import { t } from "@lingui/core/macro";
67+
68+
document.getElementById("output").innerHTML = t({ id: "msg.greeting", message: `Hello World` });
69+
```
70+
71+
Read more about [Explicit vs Generated Message IDs](/docs/guides/explicit-vs-generated-ids.md).
72+
5773
## Interpolation
5874

59-
Interpolation is one of the most used functionalities in I18N. It allows integrating dynamic values into your translations.
75+
Interpolation is a key internationalization (i18n) feature that allows you to insert dynamic values into your translations. Both Lingui and i18next support interpolation.
6076

6177
i18next sample:
6278

6379
```js
80+
import i18next from "i18next";
81+
82+
i18next.t("My name is {name}", { name: "Tom" });
6483
i18next.t("msg.name", { name: "Tom" });
6584
```
6685

6786
Lingui sample:
6887

6988
```js
70-
i18n._({ id: "msg.name", message: "My name is {name}", values: { name: "Tom" } });
89+
import { t } from "@lingui/core/macro";
90+
91+
const name = "Tom";
92+
93+
t`My name is ${name}`;
94+
t({ id: "msg.name", message: `My name is ${name}` });
7195
```
7296

7397
## Formatting
7498

75-
Both the Lingui and i18next formatting functions are based on the [Intl API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl).
99+
Both Lingui and i18next formatting functions are based on the [Intl API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl).
76100

77101
### Numbers
78102

79103
i18next sample:
80104

81105
```js
106+
import i18next from "i18next";
107+
82108
i18next.t("intlNumber", { val: 1000 });
83109
// --> Some 1,000
110+
84111
i18next.t("intlNumber", { val: 1000.1, minimumFractionDigits: 3 });
85112
// --> Some 1,000.100
113+
86114
i18next.t("intlNumber", { val: 1000.1, formatParams: { val: { minimumFractionDigits: 3 } } });
87115
// --> Some 1,000.100
116+
88117
i18next.t("intlNumberWithOptions", { val: 2000 });
89118
// --> Some 2,000.00
119+
90120
i18next.t("intlNumberWithOptions", { val: 2000, minimumFractionDigits: 3 });
91121
// --> Some 2,000.000
92122
```
@@ -116,8 +146,11 @@ i18n.number(12345.678, { style: "currency", currency: "CZK" });
116146
i18next sample:
117147

118148
```js
149+
import i18next from "i18next";
150+
119151
i18next.t("intlDateTime", { val: new Date(Date.UTC(2012, 11, 20, 3, 0, 0)) });
120152
// --> On the 12/20/2012
153+
121154
i18next.t("intlDateTime", {
122155
val: new Date(Date.UTC(2012, 11, 20, 3, 0, 0)),
123156
formatParams: {
@@ -147,7 +180,7 @@ i18n.date(d, { dateStyle: "medium", timeStyle: "medium" });
147180

148181
## Plurals
149182

150-
Lingui uses the ICU MessageFormat syntax to handle plurals. It provides a simple and translator-friendly approach to plurals localization.
183+
Lingui uses the [ICU MessageFormat](/docs/guides/message-format.md) syntax to handle plurals. It provides a simple and translator-friendly approach to plurals localization.
151184

152185
For example:
153186

@@ -158,7 +191,7 @@ plural(numBooks, {
158191
});
159192
```
160193

161-
Under the hood, plural is replaced with low-level `i18n._`. For production, the above example will become:
194+
Under the hood, the [`plural`](/docs/ref/macro.mdx#plural) macro is replaced with a low-level [`i18n._`](/docs/ref/core.md#i18n._) call. In production, the example will look like this:
162195

163196
```js
164197
i18n._({
@@ -169,7 +202,7 @@ i18n._({
169202
});
170203
```
171204

172-
When we extract messages from source code using Lingui CLI, we get:
205+
When we extract messages from the source code using the [Lingui CLI](/docs/ref/cli.md), we get:
173206

174207
```icu-message-format
175208
{numBooks, plural, one {# book} other {# books}}
@@ -185,37 +218,91 @@ i18next handles plurals differently. It requires a separate key to be defined fo
185218
```
186219

187220
```js
221+
import i18next from "i18next";
222+
188223
i18next.t("key", { count: 0 }); // -> "items"
189224
i18next.t("key", { count: 1 }); // -> "item"
190225
i18next.t("key", { count: 5 }); // -> "items"
191226
```
192227

193228
## Context
194229

195-
By providing a context you can differ translations. Both i18next and Lingui have the context feature to differentiate messages.
230+
By providing context, you can differentiate translations for the same sentences or provide translators with more details. Both i18next and Lingui have the context feature to differentiate messages.
196231

197-
## Summary
232+
i18next sample:
198233

199-
This is a rather short comparison. Both libraries have quite different concepts, but at the same time the core internationalization approaches are similar and use the same background.
234+
```js
235+
import i18next from "i18next";
236+
237+
i18next.t("Right", { context: "direction" });
238+
```
239+
240+
Lingui sample:
241+
242+
```js
243+
import { msg } from "@lingui/core/macro";
244+
245+
msg({
246+
message: "Right",
247+
context: "direction",
248+
});
249+
```
250+
251+
:::tip
252+
Lingui automatically provides additional context by including in the `.po` file the locations where each message is used, and `msgctxt` if the context is specified. This is useful for translators to understand the context of the message:
253+
254+
```gettext title="en.po"
255+
#: src/App.js:5
256+
msgctxt "direction"
257+
msgid "Right"
258+
msgstr "Right"
259+
```
260+
261+
i18next can't do this from its plain JSON files.
262+
:::
200263

201-
On top of that, [Lingui](https://github.com/lingui/js-lingui):
264+
## React Integration
265+
266+
Both libraries provide React components for handling translations in React applications. Lingui provides a set of [React Macros](/docs/ref/macro.mdx#react-macros) that simplify writing messages directly in your code. i18next provides a `Trans` component to handle translations in JSX.
267+
268+
i18next sample:
269+
270+
```jsx
271+
import { Trans } from "react-i18next";
272+
273+
const HelloWorld = () => {
274+
return <Trans i18nKey="welcome">Hello World!</Trans>;
275+
};
276+
```
277+
278+
Lingui sample:
279+
280+
```jsx
281+
import { Trans } from "@lingui/react/macro";
282+
283+
const HelloWorld = () => {
284+
return <Trans>Hello World!</Trans>;
285+
};
286+
```
287+
288+
## Summary
202289

203-
- supports rich-text messages
204-
- provides macros to simplify writing messages using MessageFormat syntax
205-
- provides a CLI for extracting and compiling messages
206-
- supports a number of [Catalog formats](/docs/ref/catalog-formats.md), including [Custom Formatters](/docs/guides/custom-formatter.md)
207-
- is very small (**3kb** gzipped), fast, flexible, and stable
208-
- works for vanilla JS, Next.js, Vue.js, Node.js etc.
209-
- is actively maintained.
290+
This is a rather brief comparison. Both libraries have quite different concepts, but at the same time the core internationalization approaches are similar and use the same background.
210291

211-
On the other hand, [i18next](https://www.i18next.com/):
292+
**On top of that, Lingui:**
212293

213-
- mature. Based on how long i18next already is available open source, there is no real i18n case that could not be solved with i18next
214-
- extensible
215-
- has a big ecosystem.
294+
- Supports rich-text messages.
295+
- Provides macros to simplify writing messages using ICU MessageFormat syntax.
296+
- Provides a CLI tool for extracting and compiling messages.
297+
- Supports a number of [Catalog Formats](/docs/ref/catalog-formats.md), including [Custom Formatters](/docs/guides/custom-formatter.md).
298+
- Is very small, fast, flexible, and stable.
299+
- Works with vanilla JS, React (including RSC), Next.js, Node.js, Vue.js etc.
300+
- Is actively maintained.
216301

217-
Lingui is a great choice for projects that require modern and efficient translation approaches, support for popular frameworks, and tools for managing translations. However, whether Lingui is better than i18next or not depends on the specific needs of the project.
302+
**On the other hand, i18next:**
218303

219-
## Discussion
304+
- Is mature. Based on how long i18next has been open source, there is no real i18n case that cannot be solved with i18next.
305+
- Is extensible, with many plugins and tools developed by other contributors, including extractors, locale identifiers, etc.
306+
- Has a big ecosystem.
220307

221-
Do you have any comments or questions? Please join the discussion at [GitHub](https://github.com/lingui/js-lingui/discussions) or raise an [issue](https://github.com/lingui/js-lingui/issues/new). All feedback is welcome!
308+
In conclusion, Lingui is an excellent option for projects that need modern and efficient translation methods, support for popular frameworks, and effective translation management tools. However, the choice between Lingui and i18next ultimately depends on the specific requirements of your project.

0 commit comments

Comments
 (0)