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

Add i18n support #722

Closed
wants to merge 13 commits into from
Closed

Add i18n support #722

wants to merge 13 commits into from

Conversation

trdthg
Copy link

@trdthg trdthg commented Sep 19, 2022

Add gettext and i18n support

This is still a draft now, I want to discuss some questions here.
I have tried to use code from rust-lang/mdBook#1864 and rust-lang/mdBook#1306, and found a bug there. It was fixed quickly. This translation process is feasible, but both of them are not merged yet, so configuring the environment is a little complicated.

@welcome
Copy link

welcome bot commented Sep 19, 2022

Hi! Thanks for opening this pull request! 😄

@fzyzcjy fzyzcjy marked this pull request as draft September 19, 2022 12:07
@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 19, 2022

This is still a draft now

Done

This translation process is feasible, but both of them are not merged yet, so configuring the environment is a little complicated.

Hmm good question. Is it possible that, you firstly configure everything under your fork?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 19, 2022

@all-contributors please add @trdthg for doc

@allcontributors
Copy link
Contributor

@fzyzcjy

I've put up a pull request to add @trdthg! 🎉

@trdthg
Copy link
Author

trdthg commented Sep 19, 2022

Is it possible that, you firstly configure everything under your fork?

Yes, It's not really that complicated, except that you have to clone two other copies of the mdBook.
And then config them here.

# [Add commands for Gettext-based translations i18n #1864](https://github.com/rust-lang/mdBook/pull/1864)
# extract and generate pot/po file
MDBOOK1="path to #1864 mdbook"

# [Add option to localize books in multiple languages #1306](https://github.com/rust-lang/mdBook/pull/1306)
# add multi-language support
MDBOOK2="path to #1306 mdbook"

@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 19, 2022

Great!

Btw is the translatetool written by you? Maybe we can merge it into justfile, which has excellent support for commands, so no need for checkArgNumber etc

@trdthg
Copy link
Author

trdthg commented Sep 19, 2022

Btw is the translatetool written by you?

Yes.

Maybe we can merge it into justfile,

Good idea. You may do some more detailed check.

@trdthg
Copy link
Author

trdthg commented Oct 18, 2022

Here is the current progress.

I moved scripts to justfile and update CI workflow. After the rust 1.64 update, pr 1306 is broken, so I folked and fixed that problem. Now just and CI works.

But I don't really like this solution, and I found rust-lang/mdBook#5 (comment) today, which seems to be better. Should I switch?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Oct 18, 2022

But I don't really like this solution, and I found rust-lang/mdBook#5 (comment) today, which seems to be better. Should I switch?

Depend on you. When doing https://github.com/fzyzcjy/flutter_smooth, I tried http://cjycode.com/flutter_smooth/, which uses https://docusaurus.io/. That one seems to have excellent multi-lang support.

So you can even switch the whole book to docusaurus as well :)

@trdthg
Copy link
Author

trdthg commented Oct 18, 2022

Looks good, I'll give it a try.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Oct 18, 2022

Btw @Desdaemon what do you think about the doc site? (Since you have written several chapters)

@Desdaemon
Copy link
Contributor

Btw @Desdaemon what do you think about the doc site? (Since you have written several chapters)

It looks great! I might contribute some translations myself if it works out well.

@stale
Copy link

stale bot commented Dec 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Dec 17, 2022
@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 17, 2022

👀

@stale stale bot removed the wontfix This will not be worked on label Dec 17, 2022
@trdthg
Copy link
Author

trdthg commented Dec 17, 2022

eyes

Busy with other things, but maybe next week will be free to continue 😵

trdthg added 2 commits May 2, 2023 21:27
Signed-off-by: trdthg <trdthg47@gmail.com>
Signed-off-by: trdthg <trdthg47@gmail.com>
@trdthg trdthg temporarily deployed to github-pages May 2, 2023 13:50 — with GitHub Actions Inactive
@fzyzcjy
Copy link
Owner

fzyzcjy commented May 2, 2023

Btw, it seems the zh homepage is somehow broken:

image

Copy link
Owner

@fzyzcjy fzyzcjy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! I am going to merge it, maybe after the fix of broken homepage if it is easy to fix

@trdthg trdthg temporarily deployed to github-pages May 3, 2023 06:15 — with GitHub Actions Inactive
@trdthg trdthg temporarily deployed to github-pages May 3, 2023 07:38 — with GitHub Actions Inactive
@trdthg trdthg temporarily deployed to github-pages May 3, 2023 07:50 — with GitHub Actions Inactive
@trdthg trdthg temporarily deployed to github-pages May 3, 2023 08:05 — with GitHub Actions Inactive
@trdthg trdthg temporarily deployed to github-pages May 3, 2023 08:07 — with GitHub Actions Inactive
@trdthg trdthg temporarily deployed to github-pages May 3, 2023 08:16 — with GitHub Actions Inactive
@trdthg
Copy link
Author

trdthg commented May 3, 2023

Btw, it seems the zh homepage is somehow broken:

@fzyzcjy seems the reason comes from mdbook-i18n-helper, after I install it from source, then build and serve locally. it's fixed
image

@mgeisler I saw that compensive-rust also has this little problem, maybe you need to release a new version?

@trdthg trdthg temporarily deployed to github-pages May 3, 2023 09:06 — with GitHub Actions Inactive
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing this thread: @trdthg - what about adding this information at the top of each zh page, saying something like:

This page is translated by [@trdthg](https://github.com/trdthg)

Comment on lines +31 to +59
- name: Checkout
uses: actions/checkout@v3

# ref https://github.com/peaceiris/actions-mdbook
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: 'latest'

- name: Setup `mdbook-mermaid`
run: cargo install mdbook-mermaid
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2

- name: Install mdbook
run: cargo install mdbook --locked --version 0.4.28

- name: Install mdbook-mermaid
run: cargo install mdbook-mermaid --locked --version 0.12.6

- name: Install mdbook-i18n-helpers
run: cargo install mdbook-i18n-helpers --locked --version 0.1.0

- name: Build book in English
working-directory: ./book
run: mdbook build -d book

- run: mdbook build ./book
- name: Build all translations
working-directory: ./book
run: |
for po_lang in ${{ env.LANGUAGES }}; do
echo "::group::Building $po_lang translation"
MDBOOK_BOOK__LANGUAGE=$po_lang \
MDBOOK_OUTPUT__HTML__SITE_URL=/flutter-rust-bridge/$po_lang/ \
mdbook build -d book/$po_lang
echo "::endgroup::"
done
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it seems good to move them to justfile. Then, everyone who wants to play with it locally (including you and me ;) ) can execute a one-line command like just whatever-command-name instead of copy-and-paste these long code

Copy link
Author

@trdthg trdthg May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding this information at the top of each zh page

Not bad, what about the people who contribute to the same page afterward?
But in any case, with the current translation process, it seems not so easy to add additional information to the translated page

Blank lines are filtered, same sentences from different pages will also be merged:

#: src/SUMMARY.md:34 src/SUMMARY.md:112
msgid "Async in Rust"
msgstr ""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems good to move them to justfile

agree, one thing to note is that if you want to serve all languages, you will have to first build and then use a separate http server to serve them, such as https://github.com/TheWaWaR/simple-http-server

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad, what about the people who contribute to the same page afterward?

Good question. Maybe just list all and add a link pointing to a separate page showing everyone's detailed contribution?

But in any case, with the current translation process, it seems not so easy to add additional information to the translated page

Just a wild guess, Is it possible to modify the HTML?

agree, one thing to note is that if you want to serve all languages, you will have to first build and then use a separate http server to serve them, such as TheWaWaR/simple-http-server

I see. Then it would be great to have a bit of doc, telling users how to build and serve the doc locally

@trdthg trdthg temporarily deployed to github-pages May 6, 2023 06:53 — with GitHub Actions Inactive
Signed-off-by: trdthg <trdthg47@gmail.com>
@trdthg trdthg temporarily deployed to github-pages May 6, 2023 06:58 — with GitHub Actions Inactive
@stale
Copy link

stale bot commented Jul 9, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jul 9, 2023
@stale stale bot closed this Jul 16, 2023
@mgeisler
Copy link

Btw, it seems the zh homepage is somehow broken:

@fzyzcjy seems the reason comes from mdbook-i18n-helper, after I install it from source, then build and serve locally. it's fixed image

@mgeisler I saw that compensive-rust also has this little problem, maybe you need to release a new version?

Hey @fzyzcjy! Yes, I need to release a new version to get this fixed. Thanks for the ping!

I didn't do this yet since I have been working on a way to improve the text extraction. The current main branch has this new system: it will turn # Some heading in the Markdown file into just "Some heading" in the PO file. Similarly, tables are now extracted on a cell-by-cell basis. This removes most of the Markdown syntax and makes the job easier for translators.

For this to work smoothly with existing translations, I've written a conversion tool: google/mdbook-i18n-helpers#46. When that is merged, I will make a new release, upgrade our own PO files, and also update the publishing pipeline to use the new version.

@mgeisler
Copy link

Hi @fzyzcjy, I've finally released a version 0.2 of mdbook-i18n-helpers — which improves the way text is extracted and which fixed the rendering of the badges on the translated pages: https://google.github.io/comprehensive-rust/pt-BR.

I know this PR is closed, but if you ever end up using the plugins, please add a link to your project in the mdbook-i18n-helpers README.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 23, 2023

@mgeisler Sure! I am happy to see i18n support, this PR is closed by stale bot.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 23, 2023

@trdthg Feel free to ping me when everything is done and I am happy to reopen/merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants