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

feat: adds custom prefix support for gettext po #2004

Merged
merged 11 commits into from
Oct 14, 2024

Conversation

garikkh
Copy link
Contributor

@garikkh garikkh commented Aug 17, 2024

Description

Adds support for custom prefixes in po-gettext formatter generated 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 17, 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 Oct 11, 2024 5:20pm

Copy link

github-actions bot commented Aug 17, 2024

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.68 KB (0%)
./packages/remote-loader/dist/index.mjs 7.26 KB (0%)

@garikkh garikkh marked this pull request as ready for review August 18, 2024 01:41
@garikkh garikkh marked this pull request as draft August 18, 2024 01:41
@garikkh garikkh marked this pull request as ready for review August 18, 2024 03:55
@timofei-iatsenko
Copy link
Collaborator

Could you elaborate a bit on the motivation and rationale of this feature?

@garikkh
Copy link
Contributor Author

garikkh commented Aug 19, 2024

The main reason is for my TMS - there are times the - in the prefix causes issues, either when showing the comments or parsing them into separate lines.

i.e.

#. js-lingui:icu=%7BanotherCount%2C+plural%2C+one+%7BSingular+case%7D+other+%7BCase+number+%7BanotherCount%7D%7D%7D&pluralize_on=anotherCount

will turn into

#. js-
#. lingui:icu=%7BanotherCount%2C+plural%2C+one+%7BSingular+case%7D+other+%7BCase+number+%7BanotherCount%7D%7D%7D&pluralize_on=anotherCount

And parsing breaks because it can't find the comment with prefix.

Alternatively I could try to change this to support multi line comments

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.59%. Comparing base (d6b9698) to head (0d88bc3).
Report is 67 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2004      +/-   ##
==========================================
- Coverage   76.65%   75.59%   -1.06%     
==========================================
  Files          81       88       +7     
  Lines        2090     2172      +82     
  Branches      533      551      +18     
==========================================
+ Hits         1602     1642      +40     
- Misses        375      419      +44     
+ Partials      113      111       -2     

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

@timofei-iatsenko
Copy link
Collaborator

It seems that #. js-lingui-explicit-id should also break your TMS, isn't it?

@vonovak
Copy link
Collaborator

vonovak commented Sep 27, 2024

I wonder (based on the given description) if this is something that rather should be fixed on the TMS side, rather than working around their problem in this lib?
I think we need to know why this should be lingui responsibility.

And if this is to be merged, docs need to be added.

@garikkh
Copy link
Contributor Author

garikkh commented Sep 30, 2024

. js-lingui-explicit-id should also break your TMS, isn't it?

No, because it breaks in my TMS only because of the line length. PO files are recommended to split on 80 characters, so if your comment is less than that theres no problem. URL encoded ICU strings are likely to be split because they are so long.

Changing the comment to NOT include a dash (js-lingui to lingui even) would prevent the line split since there is no character it can split on :/

I don't know the history/support for the 80 character standard, I think it originates from GNU gettext that does the line splitting as well.

-- as I'm writing this, I just tested and confirmed that gettext does split on 80 characters.

I wonder (based on the given description) if this is something that rather should be fixed on the TMS side, rather than working around their problem in this lib?

The above answer is really the only reason why I think it should be supported on lingui - if the standard is 80 character lines, then this isn't a TMS specific issue, it's a PO standard that should be supported (maybe not by doing custom prefix, because that's hacky, but by supporting multi-line icu comments) I might spend some time today looking at supporting multi line icu comments

And if this is to be merged, docs need to be added.

Yeah, will add docs soon, just wanted to check with the lingui team if this is something you want to merge.

@garikkh
Copy link
Contributor Author

garikkh commented Oct 1, 2024

Supporting line split comments is nontrivial as well, for cases like this:

#. some other comment
#. js-
#. lingui:pluralize_on=someCount
#. js-
#. lingui-explicit-id
msgid "message_with_id"
msgid_plural "message_with_id_plural"
msgstr[0] "Singular case"
msgstr[1] "Case number {someCount}"

Copy link

vercel bot commented Oct 1, 2024

@garikkh is attempting to deploy a commit to the lingui Team on Vercel.

A member of the Team first needs to authorize it.

@timofei-iatsenko
Copy link
Collaborator

@garikkh thanks for your investigation. Something new for me. Now, it's more or less clear why your TMS is behaving like that and that is worth to fix.

I think to avoid this it's better in general to change "-" to "_" underscores, but this will cause a big breaking changes for existing users.

@garikkh
Copy link
Contributor Author

garikkh commented Oct 9, 2024

@timofei-iatsenko can I get your review on this? Is there anything else I should add to get this merged?

Copy link
Contributor

@andrii-bodnar andrii-bodnar left a comment

Choose a reason for hiding this comment

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

@garikkh thanks for the contribution!

website/docs/ref/catalog-formats.md Outdated Show resolved Hide resolved
website/docs/ref/catalog-formats.md Outdated Show resolved Hide resolved
Copy link
Contributor

@andrii-bodnar andrii-bodnar left a comment

Choose a reason for hiding this comment

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

@garikkh thank you!

@andrii-bodnar andrii-bodnar merged commit 25b3bc6 into lingui:main Oct 14, 2024
16 checks passed
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.

4 participants