-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 option to localize books in multiple languages #1306
base: master
Are you sure you want to change the base?
Conversation
5362438
to
0db30b9
Compare
I don't know if this has been already discussed, but instead of having In this case this constraint goes away by design:
|
@MarcoIeni Yes actually, I updated the code to use I'm not sure about order because |
Oh, ok. |
c8101cb
to
a06aafd
Compare
I'm trying to test a real-world example by adding the Japanese and French translations of The Rust Programming Language into the base repository. https://github.com/Ruin0x11/book/tree/translated A few things I'm noticing immediately:
It could be more helpful to have the missing chapters automatically added regardless of whether or not they're in the summary with a notice about the missing translation, like this page: https://docs.microsoft.com/vi-vn/azure/guides/developer/azure-developer-guide. And for everything else, just grey out the language in the dropdown. But this would also have to handle the translations diverging, to prevent two copies of the same page with different names from showing up in the TOC - one for the default language which was moved, and one for the translation that hasn't been updated yet. Maybe what we need to do is use a unique identifier of some kind in each summary item in addition to the human-readable text, and then each translation's summary would reference the same identifier to indicate what item it corresponds to. We could reuse the filename for this unique identifier. The default language's summary would define the order of each item. If a translation-local page is found, it would appear immediately after the summary item before it. Anything that is missing in the order defined in the default language's summary would get copied into the translation's summary and file structure. |
910c342
to
d06249b
Compare
What needs to be done for this PR to be included into upstream? Can I help anyhow? |
Hi damirka, I just looked at the code out of curiosity and added a comment. Then GitHub added me as a reviewer, but I am not one of the maintainers of this library (I haven't done a single commit 😅). I hope this PR will receive some love from the maintainers soon anyway :) |
@damirka Mostly usability issues. There should be a way to define a "base" language structure that is shared between all languages. Then if you switch to another language, you should be able to easily tell which pages in the translation are not available, maybe copying the structure of the base language's outline and greying out the sections that are missing, showing a message, and possibly redirecting or replacing the page with the base language. (See the Microsoft docs example in my previous post.) Currently the outline is not shared between languages, so you can't tell what is missing and get a 404 instead if you switch anyway. Also this has to account for pages that are not in the base language but are in the translation, I think they can just be hidden if you're not viewing the translation. I think that as far as the requirement to switch languages goes it's usable, but since it requires breaking changes to the structure of the books it might be helpful to get it (mostly) right the first time. That might mean having to change the meaning of See my previous post for other gotchas, like needing to handle translations diverging. |
Currently, mdbook creates an empty page with a title if you've created link to this page in SUMMARY. Why can't translations do the same? Create title-only structure same as the non-translated version of the engine does? Another question comes to mind - how to translate summary? Should it follow the original structure? So duplicating link blocks is the only way? |
@Ruin0x11 can you resolve the conflicts? we can move this forward from there |
@Dylan-DPC Yes, when I can get some cycles I will look at it. |
Hi, @Ruin0x11 what is the update about this feature.. |
Thanks for this work @Ruin0x11! For your information, we are already using this in production at join.lemmy.ml/docs (rebased on a later mdbook version). Hopefully this can be completed and merged soon. For some feedback, I think it would be good if the select language button was more prominent, right now it seems very easy to miss. |
It would be nice if this can make it into upstream, this is one feature that I am eagerly awaiting 😄 . |
Maybe it's good to put it to the most right, next to the printing button? This way it declutters the available options of icons on the left side (even the theming button feels off there, given how often it will be used in comparison with the hamburger and the search magnifier), and gets one of the most prominent positions on the screen: People are already conditioned to check the top-right for a login button, why a 🌐 there might as well be recognised. @Nutomic Do you maintain a public repository of your fork, which can be used as guidance for the rebase which is left to happen here? The README in your lemmy-docs repository suggest you are effectively using this feature branch, and did not maintain a separate fork, which leaves me a little confused.
|
d06249b
to
92ec3dd
Compare
Done. |
Seems this branch will introduce a race: i did crosscheck, that rendering on stock 0.4.12 is working out fine, including the mermaid preprocessor.
ReasonI have tried to figure out, why mdbook::utils complains about a missing field. Describe the bugWhen including mdbook-mermaid v0.8.3 (or latestest git version) as a valid preprocessor in the render chain controlled with mdbook v0.4.12 the process returns with ERROR. To ReproduceSteps to reproduce the behavior:
$ git clone https://github.com/badboy/mdbook-mermaid.git
$ cd ./mdbook-mermaid
$ cargo update; cargo install --path `pwd`
$ cd $ORBTK_BOOK_ROOT
$ mdbook-mermaid install inside $ORBTK_BOOK_ROOT/
$ cd $ORBTK_BOOK_ROOT
$ RUST_LOG=info mdbook build --dest-dir=$XDG_RUNTIME_DIR/book --language en
$ 2021-09-20 11:49:40 [ERROR] (mdbook::utils): Error: Unable to parse the preprocessed book from "mermaid" processor
$ 2021-09-20 11:49:40 [ERROR] (mdbook::utils): Caused By: missing field `chapter_titles` at line 1 column 83887``` Expected behaviorThe application should render the book with the mermaid source. Bug solvedRace condition is solved with latest commits (0.4.15) |
* Generate config docs from lemmy code * fix mkdir error in build.sh, update lemmy submodule * fix drone config * init git submodule * install git * apt update * -y * dont do submodule init * x * w * update gitignore * xz * remove submodule * readd submodule * step * update rust * deps * use defaults.hjson from lemmy without building, also include apub examples * use updated mdbook from upstream pr rust-lang/mdBook#1306 (comment) * Download embeds over http instead of using git submodule * install curl * apt update * typo * -y
# Conflicts: # .gitignore # guide/src/en/cli/completions.md # guide/src/en/format/images/rust-logo-blk.svg # guide/src/en/format/markdown.md # guide/src/en/misc/introduction.md # src/renderer/html_handlebars/hbs_renderer.rs # src/utils/mod.rs
The mentioned issue should be fixed, although the book in question needed some fixes for compatibility with the feature. I also merged the latest master. @ehuss Could this perhaps see some more traction soon? |
Are we going to collect guide translations? Where to submit the PR's? |
Hi @Ruin0x11, (I'm just a random person with some experience with translating software.) I wrote a lengthy comments on #5 about why I think it would be better to support translations with dedicated tooling. Basically, while it seems useful at first to use parallel directories, I don't think it's practical for the poor people who will have to maintain the translations. Translating software has been a solved problem for 20+ years (GNU Gettext was apparently released in 1995). I would advice building on top of the tooling which has already been developed in this field. Now, the PR adds a lot of great stuff, which would still be needed if mdBook starts using Gettext: the language selector is important, as is the per-language configuration in |
mdBook is really good, and this branch makes it complete for us. Thanks! |
Some new features got added to mdbook making this branch somewhat behind. Are you able to update the branch or do you need any help? |
@jkelleyrtp I did update the branch a few months ago, but it didn't get merged at the time. It seems like the feature may need a redesign according to @mdinger. Is there something else that would prevent this from being merged if I were to go back and update the branch again? |
i could also really use this feature, is there any progress? |
Hi, can't build on rustc 1.64. I have tested it using rust-toolchain to specify an older rustc(1.63, 1.32 ...), and all of them are successful. // src/renderer/html_handlebars/helpers/navigation.rs
// Before
_h.template()
.ok_or_else(|| RenderError::new("Error with the handlebars template"))
.and_then(|t| {
let local_ctx = Context::wraps(&context)?;
let mut local_rc = rc.clone();
t.render(r, &local_ctx, &mut local_rc, out)
})?;
Ok(())
// After
let t = _h
.template()
.ok_or_else(|| RenderError::new("Error with the handlebars template"))?;
let local_ctx = Context::wraps(&context)?;
let mut local_rc = rc.clone();
t.render(r, &local_ctx, &mut local_rc, out) Would you like to fix this bug? |
commit 8664faea083017b1ec7c9d811be28427b8408bef Author: Kara <[email protected]> Date: Thu Sep 28 10:47:37 2023 -0500 Update for new mdbook version commit 1b45e7a7a6521b4df6d441788a7fff105eba9240 Merge: e74fdb1 79edc75 Author: Kara <[email protected]> Date: Thu Sep 28 10:03:55 2023 -0500 Merge branch 'master' into localization # Conflicts: # Cargo.lock # Cargo.toml # src/book/book.rs # src/book/init.rs # src/book/mod.rs # src/cmd/build.rs # src/cmd/clean.rs # src/cmd/serve.rs # src/cmd/test.rs # src/cmd/watch.rs # src/config.rs # src/preprocess/links.rs # src/renderer/html_handlebars/hbs_renderer.rs # src/renderer/markdown_renderer.rs # src/utils/mod.rs # tests/init.rs commit e74fdb1 Author: Ruin0x11 <[email protected]> Date: Fri Feb 25 14:30:38 2022 -0800 Make `chapter_titles` optional in Book commit 7305e8c Merge: 9d8147c 5921f59 Author: Ruin0x11 <[email protected]> Date: Fri Feb 25 14:13:22 2022 -0800 Merge remote-tracking branch 'upstream/master' into localization # Conflicts: # .gitignore # guide/src/en/cli/completions.md # guide/src/en/format/images/rust-logo-blk.svg # guide/src/en/format/markdown.md # guide/src/en/misc/introduction.md # src/renderer/html_handlebars/hbs_renderer.rs # src/utils/mod.rs commit 9d8147c Author: Ruin0x11 <[email protected]> Date: Wed Sep 15 21:49:58 2021 -0700 Remove extra `localization.md` commit 56e72a2 Author: Ruin0x11 <[email protected]> Date: Wed Sep 15 15:33:28 2021 -0700 [localization] rustfmt commit 92ec3dd Author: Ruin0x11 <[email protected]> Date: Wed Sep 15 15:25:31 2021 -0700 [localization] Fixes for latest master commit d6c27ab Author: Ruin0x11 <[email protected]> Date: Sat Aug 29 16:11:47 2020 -0700 Implement translation fallback of files included with preprocessing commit 5fed5e8 Author: Ruin0x11 <[email protected]> Date: Wed Sep 15 14:29:30 2021 -0700 Update mdBook manual to have information about translations commit 09a8b66 Author: Ruin0x11 <[email protected]> Date: Sat Aug 29 14:41:08 2020 -0700 Improve robustness of link rewriting commit 8d1c086 Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 16:33:02 2020 -0700 Fix {{#include}} directives for default language commit 98c3a04 Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 16:11:21 2020 -0700 Move example book to multilingual structure commit c72ce18 Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 14:50:04 2020 -0700 Rewrite links in Markdown to point to fallback if missing in translation It will follow relative links to other pages and embedded images. commit ee740ac Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 12:26:08 2020 -0700 Remove 'default' property on languages, use book.language instead commit a042cfc Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 11:35:42 2020 -0700 Make `mdbook init` output multilingual structure commit 5e223e0 Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 03:17:26 2020 -0700 Support localizing book title/description commit e17ce64 Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 02:29:07 2020 -0700 Fix test using create_missing commit 282fdaa Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 02:05:21 2020 -0700 Redirect to a 404 page when serving translated We can't redirect in warp based on the URL, so redirect to the default language's 404 page instead. See: seanmonstar/warp#171 commit 85ab4d3 Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 01:36:22 2020 -0700 Redirect to translation index page in serve command commit 8869c2c Author: Ruin0x11 <[email protected]> Date: Fri Aug 28 00:24:33 2020 -0700 Build multiple books from localizations at once Changes how the `book` module loads books. Now it is possible to load all of the translations of a book and put them into a single output folder. If a book is generated this way, a menu will be created in the handlebars renderer for switching between languages. commit 96d9271 Author: Ruin0x11 <[email protected]> Date: Thu Aug 27 19:44:24 2020 -0700 Specify language for book in command line args - Add a [language] table to book.toml. Each key in the table defines a new language with `name` and `default` properties. - Changes the directory structure of localized books. If the [language] table exists, mdBook will now assume the src/ directory contains subdirectories named after the keys in [language]. The behavior is backwards-compatible if you don't specify [language]. - Specify which language of book to build using the -l/--language argument to `mdbook build` and similar, or omit to use the default language. - Specify the default language by setting the `default` property to `true` in an entry in [language]. Exactly one language must have `default` set to `true` if the [language] table is defined. - Each language has its own SUMMARY.md. It can include links to files not in other translations. If a link in SUMMARY.md refers to a nonexistent file that is specified in the default language, the renderer will gracefully degrade the link to the default language's page. If it still doesn't exist, the config's `create_missing` option will be respected instead. commit 3049d9f Author: Ruin0x11 <[email protected]> Date: Thu Aug 27 16:35:00 2020 -0700 Actually, don't change source root The book paths have to gracefully degrade to the default language if they aren't available. commit 24e6d6b Author: Ruin0x11 <[email protected]> Date: Thu Aug 27 16:26:07 2020 -0700 Change book source root depending on language commit e4b443c Author: Ruin0x11 <[email protected]> Date: Thu Aug 27 13:27:47 2020 -0700 Add language config section Referencing rust-lang#5 (comment).
Referencing the ideas at #5 (comment), I took a shot at implementing the localization of books.
[language]
table to book.toml. Each key in the table defines a new language with various properties for localizing the metadata of the book.[language]
table exists, mdBook will now assume thesrc/
directory contains subdirectories named after the keys in[language]
. The behavior is backwards-compatible if you don't specify[language]
.-l/--language
argument tomdbook build
and similar, or omit to build all translations at once and add a menu in the output pages for switching between them.book.language
. This language gets used for page fallbacks.SUMMARY.md
. It can include links to files not in other translations. If a link inSUMMARY.md
refers to a nonexistent file that exists in the default language's file structure, the book loader will gracefully degrade the link to the default language's file. If it still doesn't exist, the config'sbuild.create-missing
option will be respected instead.--language
is passed, since there will be no default page in the generated output to redirect to.)Closes #5.
TODO
multilingual
property in[book]
config sectionmdbook init
generate books with the new localized directory structuremdbook serve
aware of multiple language root directories{{#include ...}}
files?