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

xgettext: Avoid collisions when splitting .pot files #243

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cip999
Copy link

@cip999 cip999 commented Dec 13, 2024

Hey, I've been looking into #185 and its predecessor #67. While thinking of ways to implement the "reconstruction" of the catalog from smaller pieces, I noticed that the code doesn't handle well books where several part titles and/or chapters have the same name (or, more precisely, are equivalent up to slugging).

For example, consider the following SUMMARY.md:

# Summary

# Part Foo

[Chapter 1](src/chapter-1.md)

# Part Bar

[Chapter 2](src/chapter-2.md)

# Part Foo

[Chapter 3](src/chapter-3.md)

With a depth of 1, the preprocessor generates two POT files foo.pot and bar.pot (beside summary.pot), and the contents of the two Part Foo's (including Chapters 1 and 3) are merged. Since those are unrelated, if not for having the same title, the expected behavior would be to put them in separate files. Note that the titles don't have to be exactly equal, for example the same would happen with Part Foo 1 and Part Foo 2 (since numbers are discarded).

This PR should fix this issue. I hope doc comments are explicative enough, otherwise feel free to request clarifications. :)

Copy link

google-cla bot commented Dec 13, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@cip999
Copy link
Author

cip999 commented Dec 13, 2024

Ah, the PR is somwhat large so let me know if you want me to split it into 2-3 commits.

@codecov-commenter
Copy link

codecov-commenter commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 97.34043% with 5 lines in your changes missing coverage. Please review.

Project coverage is 85.11%. Comparing base (0fdaff1) to head (aa7f82f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
i18n-helpers/src/xgettext.rs 97.34% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #243      +/-   ##
==========================================
+ Coverage   84.89%   85.11%   +0.22%     
==========================================
  Files          15       15              
  Lines        3369     3433      +64     
  Branches     3369     3433      +64     
==========================================
+ Hits         2860     2922      +62     
  Misses        422      422              
- Partials       87       89       +2     

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

PR google#77 added the first half of a functionality requested in google#67, i.e. being
able to split the catalog across a tree of POT files. However, there are
edge cases where the generated files can have identical path relative to
the po/ directory, with the effect of collapsing messages for unrelated
parts or chapters in the same POT fie.

This commit handles deduplication through a "black box" struct
`UniquePathBuilder`, and adds a doctest and a unit test for collision
scenarios. The new version is backward-compatible for cases that
are collision-free in the old version.

Contextually, simplify the recursion logic in `get_subcontent_for_chapter`.
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.

2 participants