Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra details about i18next + better lingui examples #2013

Closed
wants to merge 1 commit into from

Conversation

igorsantos07
Copy link

Description

As a user of i18next for around 3 years, I noticed some parts of the comparison were lacking. I got specially baffled by the verbosity of interpolations, but I'm glad I checked the API docs before giving up :)

BTW, do i18n.t() really need different examples from i18n._()? I would say that only causes more confusion; at first glance it looks like that it works differently, even though it's an alias.

An important fact to distinguish as well is that you need a lot of extra config in i18n to use natLang keys, which honestly is quite troublesome for people coming from gettext. This happens because i18next relies solely on JSON files, so they need some... workarounds... to shove different details in the same JSON key.

I also replaced the t() references with _(), as that's the main function (and not the alias).

Lastly, I'm not entirely sure about the syntax to include translation context in Lingui. I stumbled upon comment in some other example and in the API docs, but again, that's not exactly clear. I would advise add a description for all options that can be used in _(), as well as examples for context/comments.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

Copy link

vercel bot commented Aug 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 24, 2024 7:34pm

Copy link

size-limit report 📦

Path Size
./packages/core/dist/index.mjs 2.88 KB (0%)
./packages/detect-locale/dist/index.mjs 723 B (0%)
./packages/react/dist/index.mjs 1.67 KB (0%)
./packages/remote-loader/dist/index.mjs 7.26 KB (0%)

@igorsantos07
Copy link
Author

igorsantos07 commented Aug 24, 2024

By the way, lazy translation is something that i18next does NOT support, and caused a lot of subtle bugs on our application until I realized what was going on. I'm not sure how to better write about this in the comparison page, though :|

Comment on lines +213 to +215
```js
i18n._("Hello!", { comment: "This goes in the header" });
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that will not work. Most lingui features build around macros, pieces of code which executed during build step not a runtime. This helps reduce size footprint of the translation catalogs as well as library itself.

In this case to specify a context for a message you MUST use a macro like this

import {t} from "@lingui/macro";

t({message: `From: `, context: "direction"})

With plain runtime modules (i18n._) the only way is custom id.

@andrii-bodnar
Copy link
Contributor

@igorsantos07 @timofei-iatsenko is there anything we can do to help move this PR forward?

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.00%. Comparing base (d6b9698) to head (d959a0c).
Report is 71 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2013      +/-   ##
==========================================
+ Coverage   76.65%   80.00%   +3.35%     
==========================================
  Files          81       85       +4     
  Lines        2090     2146      +56     
  Branches      533      547      +14     
==========================================
+ Hits         1602     1717     +115     
- Misses        375      413      +38     
+ Partials      113       16      -97     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@timofei-iatsenko
Copy link
Collaborator

This article should be proofread and lingui examples replaced to theirs macro alternatives.

@andrii-bodnar
Copy link
Contributor

Close in favor of #2064

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants