-
Notifications
You must be signed in to change notification settings - Fork 25
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
Build translations from mdbook #84
base: main
Are you sure you want to change the base?
Conversation
8fd86d8
to
09d960f
Compare
We should bump the version as alpha in |
This basically moves the Later I guess this for-loop-renderer (🙂) will know to pass in i18n-releated information to the book — or maybe not since the other renderer will already be able to grab this from the |
Yes that's the only thing it does. The advantage is that we get a better developer experience for translators. They see all translations at the same time without having to rebuild multiple times with a different command. Live reload is also supported. It's a small win but I think it's worth it. |
This will freeze translation in place: they will keep using the same English Markdown source files as the starting point until a new POT file is merged into the translation. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
This will freeze translation in place: they will keep using the same English Markdown source files as the starting point until a new POT file is merged into the translation. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
This will freeze translation in place: they will keep using the same English Markdown source files as the starting point until a new POT file is merged into the translation. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Before, we always used the latest English source files when publishing. This means that translations become outdated as soon as anything is changed in the source. This PR changes will instead freeze translations in place: they will keep using the same English source files until a new POT file is merged into the translation. We do this by relying on the POT-Creation-Date field in the PO files. We still update all the files around the Markdown files: this allows us to fix things in the theme, for example. Part of google/mdbook-i18n-helpers#16. The logic here should eventually be moved to somewhere in mdbook-i18n-helpers, most likely to the renderer that @sakex is building in google/mdbook-i18n-helpers#84.
Some of the comments has more dashes than necessary — I kept the test cases that tested extra dashes on purpose.
The data is added to PO files automatically by `msgmerge`. This will in turn be used when publishing a translation: it allows us to know which sources goes into a given PO file. Part of google#16.
Refactor repository to use workspaces
Refactor repository to use workspaces
Just a note about Merge branch 'main' into translate-from-mdbook. Please rebase your commits on top of For this reason, I will want to squash merge the PR if it has merge commits. |
We don't care because we run the
Could you instead run the
Okay, thanks for checking! If it isn't documented, then we should not rely on it. If the order is important, could you then open an PR to the upstream repository to define the order in the documentation? |
Yes, I did that because it is more convenient. I only want one commit for this PR anyway, so squashing is expected |
e727d9a
to
f63882e
Compare
Hey @mgeisler . Is it Ok to merge now (with squash) so that I can use this as a base for the other renderer? After the renderer is done, I'll make a test book to test all the features |
I think we need some documentation before we merge this. It's not clear to me what the expectations are for the user. As an example, I believe you said that the
Please add a test here already, otherwise it's hard to know what to expect. Also, update the first PR comment above to explain what this does (hint: reuse that text for your module docstring and for the README and USAGE). |
We still need to answer this essential question: how can we rely on |
No, it's not required anymore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sakex, I tried marking the things we need to figure out or explain before we merge this.
i18n-helpers/src/bin/mdbook-i18n.rs
Outdated
/// Default language code. It will not be translated. | ||
default_language: Option<String>, | ||
|
||
/// Whether to translate all languages or just the selected language, defaults to false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "selected language"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The language set in the env variable MDBOOK_BOOK__LANGUAGE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay... Setting MDBOOK_BOOK__LANGUAGE
is just another way of setting the language
field in book.toml
. So it's not strictly "selected", it's just what the config happens to be when the mdbook-gettext
preprocessor is invoked.
The current system has the elegant approach that you can set language
to what you want and it will then translate the text on the fly to this language — because it's a preprocessor which is independent of the renderer!
The new renderer is a bit different: it takes a list of languages from book.toml
and renders the book for each of them. If the user only want to render a single language, the simplest way would be for the user to remove the other languages from the list in book.toml
!
The users could do this on the command line with a suitable MDBOOK_OUTPUT__I18n__LANGUAGES
setting (I think). This would be better since it uses less infrastructure: all you need to know is that the output.i18n.languages
key controls the list of languages to generate for. If it has 1 item, then you get a single language, if it has
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conversion is documented here: https://rust-lang.github.io/mdBook/format/configuration/environment-variables.html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this variable is that if you do MDBOOK_BOOK__LANGUAGE=fr mdbook build
with translate_all_languages
to false, it will just translate fr
otherwise, it will translate all languages. We can skip that, it's just for convenience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this variable is that if you do
MDBOOK_BOOK__LANGUAGE=fr mdbook build
withtranslate_all_languages
to false, it will just translatefr
otherwise, it will translate all languages. We can skip that, it's just for convenience.
Can we unify this behavior? We stop setting MDBOOK_BOOK__LANGUAGE
and instead drive the behavior of the backend using solely a new output.i18n.languages
field. It should behave like this:
-
The
book.toml
file checked in has all languages for the book. -
To build fewer languages, people can remove the unwanted languages from
book.toml
. Alternativley, they can use the environment variable support and runMDBOOK_OUTPUT__I18N__LANGUAGES='["fr"]' mdbook build
to restrict the languages to just French.
Why have a list in book.toml
instead of just using po/*.po
? Because there could be extra meta data compared to what we find in the PO files. I'm thinking of things like english_name = "French", name = "Français"
and maybe even available_in_language_picker = true
.
Does that sounds like a good idea? So instead of a "all languages or a single language" based on MDBOOK_BOOK__LANGUAGE
(which doesn't make a ton of sense for a multi-language book), we have a more flexible system that people can override on the command line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, it would require refactoring a bit.
In the current state, it works like this:
mdbook build
runs normally on whatever language is set in the environment or manually in the book, then we execute a variable number of backends before reaching this one. From this backend, we loop over the languages defined in book.toml
and do mdbook build
for each language.
What you're suggesting would mean intercepting everything right at the beginning, so it would need to be a preprocessor that would need to run first and then orchestrate the language directives. It works too but would require some refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you're suggesting would mean intercepting everything right at the beginning,
I'm not actually suggesting that — I was only suggesting changing the logic for which subset of the languages to build.
/// For all renderers in this list, we will move individual translations to `book/<renderer>/<language>`. | ||
#[serde(default)] | ||
move_translations_directories: Vec<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're saying here that you'll break the contract defined by mdbook.
I don't want the new renderer to touch files in the output directories of other renderers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very convenient with mdbook serve
to view the output like it will be on the final site. It doesn't need to be enabled otherwise and by default does nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're saying here that you'll break the contract defined by mdbook.
I don't want the new renderer to touch files in the output directories of other renderers.
It's very convenient with
mdbook serve
to view the output like it will be on the final site. It doesn't need to be enabled otherwise and by default does nothing
I don't think you addressed my concern: if the code is writing outside of the output directly, then the code is doing something wrong.
I don't doubt that it is convenient: we should just write everything inside of the designated output directory.
Maybe you're not aware, but I often use mdbook build -d /tmp/foo
and similar to generate output in non-standard directories. So this renderer must respect the output setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, we don't break the contract but if we enable this, we do. That's also what we're already doing in comprehensive rust, so I don't really see a problem as it is opt-in only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also what we're already doing in comprehensive rust, so I don't really see a problem as it is opt-in only.
I hope our mdbook
plugins are not breaking this?
Are you talking about the code in publish.yml
, then that is quite different: the code there relies on the contract of mdbook
which says that it will put things into directory so-and-so. After calling mdbook build
, we are of course free to move things around and mess with the book/
directory — we own it then!
This is the main difference between implementing this functionality as a wrapper script (as suggested in #18!) and writing it as a mdbook
plugin. As a plugin, you are subjected to the rules of the surrounding system.
It might be a subtle difference, but I believe it's an important one. By following the principle carefully on every level of the stack, we will be able to build bigger "stacks" of software which behaves in a predictable manner when seen as a whole.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script does this:
for language in languages:
cmd(f"MDBOOK_BOOK__LANGUAGE={language} mdbook build . -d i18n-helpers/{language}")
for renderer_to_move in move_translations_directories:
cmd(f"mv i18n-helpers/{language}/{renderer_to_move} {renderer_to_move}/{language}")
Note that the move happens after the mdbook build
command ran. Which respects this statement:
After calling mdbook build, we are of course free to move things around and mess with the book/ directory — we own it then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script does this
Sorry, I don't think I know what script you're referring to here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This renderer I mean
Co-authored-by: Martin Geisler <martin@geisler.net>
I sometimes open this PR to look at the current state, and I wanted to let a compliment here for you both. I really like your interactions and styles of giving feedback. May this become a great feature :) Much of love! 👍🏽 |
9293a37
to
d4e0c95
Compare
Fixes #13.
Fixes #18.