google / mdbook-i18n-helpers

Translation support for mdbook. The plugins here give you a structured way to maintain a translated book.
Apache License 2.0
127 stars 25 forks source link

Duplicate rows in message.pot #101

Closed Demian101 closed 10 months ago

Demian101 commented 11 months ago

when I run

# gen message.po
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' \
  mdbook build -d po

there are so many duplicate rows, dont know why

image image
mgeisler commented 11 months ago

Hey @Demian101!

You raise a good point: the problem is that if a message (such as "A" in your case) occurs multiple times on the same line, then we record this in the sources multiple times.

This can happen if you have a table in your Markdown:

| A | A | A |
|---|---|---|

will generate the same message "A" three times, all on the same time. So you get a single msgid "A" line, but the source is duplicated.

This is harmless, but silly... if you run the file through msgcat, you will notice that the duplicate source lines are removes. But I would also like to see mdbook-xgettext remove them already.

This is where we accumulate the source lines, so I think this could be the right place to do the de-duplication:

https://github.com/google/mdbook-i18n-helpers/blob/941a188219c5b0492850ad54ea41303dcee49c82/i18n-helpers/src/bin/mdbook-xgettext.rs#L35-L38

mgeisler commented 11 months ago

Alternatively (and probably more efficiently), we could handle this after all messages have been added just before this line:

https://github.com/google/mdbook-i18n-helpers/blob/941a188219c5b0492850ad54ea41303dcee49c82/i18n-helpers/src/bin/mdbook-xgettext.rs#L103

We could then also move the textwrap::refill call to that location.

Demian101 commented 11 months ago

In some cases she may not be harmless lol

image image

So , i try to replace all msgid "" msgstr "" to ""

mgeisler commented 11 months ago

Oh, thanks for pointing that out! You've run into #64...

mgeisler commented 10 months ago

Having duplicate messages (such as "A") should be fine. The problem of adding empty messages ("") was fixed with #111.

I'm about to make a 0.3 release which has the fix above. Please open a new issue if you run into problem with this release.

Demian101 commented 10 months ago

GREAT work! can't wait for the next version ~ 🤣

mgeisler commented 10 months ago

It has been released now! Please cargo install mdbook-i18n-helpers to get it! :smile: