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 submodule for document translation #133562

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@
path = src/gcc
url = https://github.com/rust-lang/gcc.git
shallow = true
[submodule "src/doc/translations"]
path = src/doc/translations
url = https://github.com/dalance/translations
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ impl<P: Step> Step for RustbookSrc<P> {
.arg(&out)
.arg("--rust-root")
.arg(&builder.src)
.arg("-n")
.arg(&name)
.run(builder);

for lang in &self.languages {
Expand All @@ -191,6 +193,10 @@ impl<P: Step> Step for RustbookSrc<P> {
.arg(&src)
.arg("-d")
.arg(&out)
.arg("--rust-root")
.arg(&builder.src)
.arg("-n")
.arg(&name)
.arg("-l")
.arg(lang)
.run(builder);
Expand Down
1 change: 1 addition & 0 deletions src/doc/translations
Submodule translations added at 3afda4
1 change: 1 addition & 0 deletions src/tools/rustbook/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ dependencies = [
"mdbook-spec",
"mdbook-trpl-listing",
"mdbook-trpl-note",
"toml 0.5.11",
]

[[package]]
Expand Down
1 change: 1 addition & 0 deletions src/tools/rustbook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mdbook-trpl-listing = { path = "../../doc/book/packages/mdbook-trpl-listing" }
mdbook-trpl-note = { path = "../../doc/book/packages/mdbook-trpl-note" }
mdbook-i18n-helpers = "0.3.3"
mdbook-spec = { path = "../../doc/reference/mdbook-spec" }
toml = "0.5.11"

[dependencies.mdbook]
version = "0.4.37"
Expand Down
52 changes: 52 additions & 0 deletions src/tools/rustbook/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ fn main() {
.required(false)
.value_parser(clap::value_parser!(String));

let n_arg = arg!(-n --"name" <NAME>
"The book name")
.required(false)
.value_parser(clap::value_parser!(String));

let root_arg = arg!(--"rust-root" <ROOT_DIR>
"Path to the root of the rust source tree")
.required(false)
Expand Down Expand Up @@ -56,6 +61,7 @@ fn main() {
.about("Build the book from the markdown files")
.arg(d_arg)
.arg(l_arg)
.arg(n_arg)
.arg(root_arg)
.arg(&dir_arg),
)
Expand Down Expand Up @@ -121,8 +127,54 @@ pub fn build(args: &ArgMatches) -> Result3<()> {
book.with_preprocessor(Spec::new(rust_root)?);
}

let mut cleanup = Vec::new();
if let Some(rust_root) = args.get_one::<PathBuf>("rust-root") {
if let Some(name) = args.get_one::<String>("name") {
let translation_path = rust_root.join(format!("src/doc/translations/{name}"));
if translation_path.exists() {
let css_file = "theme/language-picker.css";
let js_file = "theme/language-picker.js";

let css_path = translation_path.join(css_file);
let js_path = translation_path.join(js_file);
let po_path = translation_path.join("po");

let theme_dir = book_dir.join("theme");
if !theme_dir.exists() {
std::fs::create_dir(theme_dir)?;
}
let css_target = book_dir.join(css_file);
let js_target = book_dir.join(js_file);
std::fs::copy(css_path, &css_target)?;
std::fs::copy(js_path, &js_target)?;
cleanup.push(css_target);
cleanup.push(js_target);

let css_file: toml::Value = css_file.into();
let js_file: toml::Value = js_file.into();
let po_path: toml::Value = po_path.to_string_lossy().as_ref().into();

if let Some(additional_css) = book.config.get_mut("output.html.additional-css") {
additional_css.as_array_mut().unwrap().push(css_file.into());
} else {
book.config.set("output.html.additional-css", vec![css_file])?;
}
if let Some(additional_js) = book.config.get_mut("output.html.additional-js") {
additional_js.as_array_mut().unwrap().push(js_file.into());
} else {
book.config.set("output.html.additional-js", vec![js_file])?;
}
book.config.set("preprocessor.gettext.po-dir", po_path)?;
}
}
}

book.build()?;

for file in cleanup {
std::fs::remove_file(file)?;
}

Ok(())
}

Expand Down
Loading