-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add support for translation comments #63
Comments
I'm interested in working on this one. |
Questions: I'm assuming we'll be looking at HTML comments? Do you already have some expectations on what the comment structure should look like for this operations?
I'm expecting that we'll want to expand the return type for |
Yes, precisely! They are our universal back-channel 🙂
Yeah, but I would prefix it with <!-- mdbook-xgettext: skip -->
```rust,editable
fn do_not_translate_me() {}
```
This actually matches this SO answer which suggests calling
to extract C comments like this: // TRANSLATORS: A translator comment
printf(_("Hello world")); As you might have guessed, our
The GNU project has documentation here, which also mentions the message context: https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
That sounds like a good idea — I've not really thought about how this will affect the code. It might be time to expand the return type to a bigger type, perhaps our own or perhaps the polib |
Okay, I think I understand. I'm starting to hack to see if I can get a proof of concept going. Here's what I'm thinking of for handling skip, to do it at the place where we're gathering groups for translation: main...dyoo:mdbook-i18n-helpers:skip This is not heavily tested or quite right yet. But I hope it's in a good direction! |
Okay, I did a little bit more work on cleaning up the skip-handling code. #69. I hope this looks good to you! |
Your #69 looks great! I wanted to copy a comment from there to here since I think it can be useful for future PRs. Basically, we can take inspiration from what mdpo does. I think we could use
The An immediate use case of this feature is skipping large code blocks in Comprehensive Rust. A related feature would be skipping code blocks automatically by default. A twist on this would be skipping code blocks that don't contain certain (configurable) patterns: if we don't see |
Overall next plan sketch:
|
The changes in your plan look great to me! However, may I suggest a small detour: could we add a command line option to automatically skip code blocks which don't contain
That sounds very reasonable! There can be normal |
Your wish is my command. Draft: #75 I need to revise it since it's being applied unconditionally here instead of as a command line option. Do you have suggestions on what that command line option should look like? |
I added a bit about that to #75 — we can pass in options via [output.xgettext]
skip-all-codeblocks = true
skip-codeblocks-except-contains = ["\"", "//"] Perhaps the logic should be reversed? We could instead speak about "keeping code blocks" and use settings like [output.xgettext]
keep-codeblocks = true
keep-codeblocks-matching = ["\"", "//"] That way we have fewer double-negations in the mental model 😄 The two options overlap, but I guess people will appreciate the clarity of writing |
Okay, notes to self on implementation strategy here. We want to read from the configuration object. I'm assuming that we want to extract from the It's a little unclear to me how the data flow works here, how we get that value threaded to the message extractor. Reading... okay, the main function of mdbook-xgettext.rs gets the RenderContext value. I'm assuming that the places where we are calling extractMessages are all places where we can pass along a There are two places where we call extractMessages:
So I think I may need a little more guidance here since I'm unfamiliar with the usage of mdbook-i18n-normalize; is it meaningful to have the RenderContext available when using that binary? |
Good question... on one hand, On the other hand, it might be good to do the filtering after |
Yeah, I was also thinking that I'm doing too much at the extract_message level there. Let me see if I can refactor things a bit so that we cleanly separate the filtering as a separate step. |
Apologies for not giving a status report for a few weeks; I caught a nasty bug a few weeks ago that has been sapping a lot of energy from me. I've begun the work on refactoring the directive detection so that we can
Still in progress and being cleaned up, but hopefully I'll get this ready for review shortly. I Just wanted to give you a heads up @mgeisler and to let you know I'm still alive. :) |
#107 is the second part to thread translation comments up to extract_messages. I need to teach |
Yay, good to see you're still here 😄 Thanks for putting up the PRs! |
We should teach
mdbook-xgettext
to react to comments in the Markdown. Comments could be used for:xgettext
extracts them using a special syntax (which we should try to replicate).The text was updated successfully, but these errors were encountered: