Skip to content

Commit f3b5eb9

Browse files
Merge branch 'master' into patch-3
2 parents a3bd42b + 32f5fa0 commit f3b5eb9

File tree

12 files changed

+578
-8
lines changed

12 files changed

+578
-8
lines changed

.github/workflows/rbe.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
name: CI
22
on: [push, pull_request]
33

4+
env:
5+
# Update the language picker in index.hbs to link new languages.
6+
LANGUAGES:
7+
48
jobs:
59
test:
610
name: Run tests
711
runs-on: ubuntu-latest
812
steps:
9-
- uses: actions/checkout@master
13+
- uses: actions/checkout@v4
14+
with:
15+
# We need the full history below.
16+
fetch-depth: 0
1017

1118
- name: Update rustup
1219
run: rustup self update
@@ -23,6 +30,10 @@ jobs:
2330
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.15/mdbook-v0.4.15-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
2431
echo "$(pwd)/bin" >> ${GITHUB_PATH}
2532
33+
- name: Install mdbook-i18n-helpers
34+
run: |
35+
cargo install mdbook-i18n-helpers --locked --version 0.3.0
36+
2637
- name: Report versions
2738
run: |
2839
rustup --version
@@ -41,6 +52,28 @@ jobs:
4152
https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
4253
sh linkcheck.sh --all rust-by-example
4354
55+
- name: Build all translations
56+
run: |
57+
for po_lang in ${{ env.LANGUAGES }}; do
58+
POT_CREATION_DATE=$(grep --max-count 1 '^"POT-Creation-Date:' po/$po_lang.po | sed -E 's/".*: (.*)\\n"/\1/')
59+
if [[ $POT_CREATION_DATE == "" ]]; then
60+
POT_CREATION_DATE=now
61+
fi
62+
63+
echo "::group::Building $po_lang translation as of $POT_CREATION_DATE"
64+
rm -r src/
65+
git restore --source "$(git rev-list -n 1 --before "$POT_CREATION_DATE" @)" src/
66+
67+
# Set language and adjust site URL. Clear the redirects
68+
# since they are in sync with the source files, not the
69+
# translation.
70+
MDBOOK_BOOK__LANGUAGE=$po_lang \
71+
MDBOOK_OUTPUT__HTML__SITE_URL=/rust-by-example/$po_lang/ \
72+
MDBOOK_OUTPUT__HTML__REDIRECT='{}' \
73+
mdbook build -d book/$po_lang
74+
echo "::endgroup::"
75+
done
76+
4477
- name: Upload Artifact
4578
uses: actions/upload-artifact@v3
4679
with:

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
book
22

3+
po/messages.pot
4+
35
# Auto-generated files from macOS
4-
.DS_Store
6+
.DS_Store

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,37 @@ mdbook serve
2727
To be able to run the examples, you must be connected to the internet; you can
2828
read all content offline, however!
2929

30+
The following warnings can be ignored safely.
31+
32+
```
33+
[WARN] (mdbook::preprocess::cmd): The command wasn't found, is the "gettext" preprocessor installed?
34+
[WARN] (mdbook::preprocess::cmd): Command: mdbook-gettext
35+
```
36+
37+
### Using translated version
38+
39+
If there is a translated resource in `po/` directory, it can be specified through `MDBOOK_BOOK__LANGUAGE` like below:
40+
41+
```bash
42+
git clone https://github.com/rust-lang/rust-by-example
43+
cd rust-by-example
44+
cargo install mdbook
45+
MDBOOK_BOOK__LANGUAGE=ja mdbook build
46+
MDBOOK_BOOK__LANGUAGE=ja mdbook serve
47+
```
48+
3049
## Contributing
3150

3251
Please see the [CONTRIBUTING.md] file for more details.
3352

3453
[CONTRIBUTING.md]: https://github.com/rust-lang/rust-by-example/blob/master/CONTRIBUTING.md
3554

55+
## Translating
56+
57+
Please see the [TRANSLATING.md] file for more details.
58+
59+
[TRANSLATING.md]: https://github.com/rust-lang/rust-by-example/blob/master/TRANSLATING.md
60+
3661
## Translations to other languages
3762

3863
* [Bulgarian](https://github.com/kberov/rust-by-example-bg)

TRANSLATING.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Rust by Example translation guidelines
2+
3+
Please see the [CONTRIBUTING.md] file for general contribution guidelines.
4+
This file describes about the translation workflow.
5+
6+
[CONTRIBUTING.md]: https://github.com/rust-lang/rust-by-example/blob/master/CONTRIBUTING.md
7+
8+
## Translation workflow
9+
10+
### Preparation
11+
12+
RBE uses [mdbook-i18n-helpers](https://github.com/google/mdbook-i18n-helpers) as a translation framework.
13+
The following tools are required.
14+
15+
* GNU gettext utilities ( `msgmerge` and `msgcat` )
16+
* mdbook-i18n-helpers ( `cargo install mdbook-i18n-helpers` )
17+
18+
### Creating and Updating Translations
19+
20+
Please see the [mdbook-i18n-helpers USAGE](https://github.com/google/mdbook-i18n-helpers/blob/main/i18n-helpers/USAGE.md) file for the detailed usage of mdbook-i18n-helpers.
21+
The summarized command list is below:
22+
23+
#### Generating a message template
24+
25+
The generated message templete `po/messages.pot` is required to create or update translations.
26+
27+
```bash
28+
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' \
29+
mdbook build -d po
30+
```
31+
32+
#### Creating a new translation resource
33+
34+
`xx` is [ISO 639](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code.
35+
36+
```bash
37+
msginit -i po/messages.pot -l xx -o po/xx.po
38+
```
39+
40+
#### Updating the exising translation resource
41+
42+
```bash
43+
msgmerge --update po/xx.po po/messages.pot
44+
```
45+
46+
### Editing translation resources
47+
48+
After generating a translation resource `po/xx.po`, you can write translation messages in `msgstr` entry of `po/xx.po`.
49+
To build a translated book, the following command can be used.
50+
51+
```bash
52+
MDBOOK_BOOK__LANGUAGE=xx mdbook build
53+
MDBOOK_BOOK__LANGUAGE=xx mdbook serve
54+
```
55+
56+
### Add a language entry
57+
58+
Please add a language entry in `.github/workflows/rbe.yml` and `theme/index.hbs` like below:
59+
60+
* `rbe.yml`
61+
62+
```yml
63+
env:
64+
# Update the language picker in index.hbs to link new languages.
65+
LANGUAGES: xx yy zz
66+
```
67+
68+
* `index.hbs`
69+
70+
```html
71+
<ul id="language-list" class="theme-popup" aria-label="Languages" role="menu">
72+
<li role="none"><button role="menuitem" class="theme">
73+
<a id="en">English</a>
74+
</button></li>
75+
<li role="none"><button role="menuitem" class="theme">
76+
<a id="xx">XX language</a>
77+
</button></li>
78+
<li role="none"><button role="menuitem" class="theme">
79+
<a id="yy">YY language</a>
80+
</button></li>
81+
<li role="none"><button role="menuitem" class="theme">
82+
<a id="zz">ZZ language</a>
83+
</button></li>
84+
</ul>
85+
```

book.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ enable = true
1313

1414
[output.html]
1515
git-repository-url = "https://github.com/rust-lang/rust-by-example"
16+
additional-css = [
17+
"theme/css/language-picker.css",
18+
]
1619

1720
[rust]
1821
edition = "2021"
22+
23+
[build]
24+
extra-watch-dirs = ["po"]
25+
26+
[preprocessor.gettext]
27+
after = ["links"]

src/meta/doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Used to inline docs, instead of linking out to separate page.
8080
pub use bar::Bar;
8181
8282
/// bar docs
83-
mod bar {
83+
pub mod bar {
8484
/// the docs for Bar
8585
pub struct Bar;
8686
}

src/meta/playground.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,22 @@ button that says "Run", which opens the code sample up in a new tab in Rust
3939
Playground. This feature is enabled if you use the `#[doc]` attribute called
4040
[`html_playground_url`][html-playground-url].
4141

42+
```
43+
#![doc(html_playground_url = "https://play.rust-lang.org/")]
44+
//! ```
45+
//! println!("Hello Wolrd");
46+
//! ```
47+
```
48+
4249
### See also:
4350

4451
- [The Rust Playground][rust-playground]
45-
- [rust-playground][rust-playground]
52+
- [The Rust Playground On Github][rust-playground-github]
4653
- [The rustdoc Book][rustdoc-book]
4754

4855
[rust-playground]: https://play.rust-lang.org/
49-
[rust-playground]: https://github.com/integer32llc/rust-playground/
56+
[rust-playground-github]: https://github.com/integer32llc/rust-playground/
5057
[mdbook]: https://github.com/rust-lang/mdBook
5158
[official-rust-docs]: https://doc.rust-lang.org/core/
5259
[rustdoc-book]: https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html
53-
[html-playground-url]: https://doc.rust-lang.org/rustdoc/the-doc-attribute.html#html_playground_url
60+
[html-playground-url]: https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html#html_playground_url

src/std_misc/ffi.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ attribute containing the name of the foreign library.
88
use std::fmt;
99
1010
// this extern block links to the libm library
11+
#[cfg(target_family = "windows")]
12+
#[link(name = "msvcrt")]
13+
extern {
14+
// this is a foreign function
15+
// that computes the square root of a single precision complex number
16+
fn csqrtf(z: Complex) -> Complex;
17+
18+
fn ccosf(z: Complex) -> Complex;
19+
}
20+
#[cfg(target_family = "unix")]
1121
#[link(name = "m")]
1222
extern {
1323
// this is a foreign function

src/std_misc/process/pipe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ process via pipes.
66

77
```rust,ignore
88
use std::io::prelude::*;
9-
use std::process::{Command, Stdio};
9+
use std::process::Stdio;
1010
1111
static PANGRAM: &'static str =
1212
"the quick brown fox jumped over the lazy dog\n";

src/testing/unit_testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
199199
Tests can be marked with the `#[ignore]` attribute to exclude some tests. Or to run
200200
them with command `cargo test -- --ignored`
201201

202-
```rust
202+
```rust,ignore
203203
pub fn add(a: i32, b: i32) -> i32 {
204204
a + b
205205
}

0 commit comments

Comments
 (0)