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

添加中英文语言切换功能 #45

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
@@ -0,0 +1,3 @@
[submodule "en"]
path = en
url = https://github.com/rust-lang/nomicon.git
61 changes: 42 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,77 @@
# Rust 秘典

高级和不安全 Rust 编程的黑魔法指南。
高级 Unsafe Rust 编程的黑科技指南

绰号“死灵书”。
在 Rust 社区内俗称“nomicon”,另有中文译名“死灵书”[^1]

地址:[https://nomicon.purewhite.io/](https://nomicon.purewhite.io/)
在线阅读:[https://nomicon.purewhite.io/](https://nomicon.purewhite.io/)

## 注意:这本书仍处于草稿状态,可能包含严重的错误。
[^1]: [Stephen Bell's answer to What does the word suffix '-onomicon' mean? - Quora](https://www.quora.com/What-does-the-word-suffix-onomicon-mean/answer/Stephen-Bell-2)

> 我所希望的程序没有出现,而是出现了令人战栗的黑暗和不可言喻的孤独。我终于看到了一个可怕的事实,以前从来没有人敢说出来——秘密中不可告人的秘密——这个事实是,这种石头和声音的语言并不是 Rust 的有生命的延续,就像伦敦是老伦敦,巴黎是老巴黎一样,但它实际上是很不安全的,它的蔓延的身体并没有完善地被防腐处理,并且被诡异的动态的东西侵扰,并且这些东西在编译时无能为力。
## 注意:本书仍为草案,其中可能包含严重错误

> 我没有寻见自己期待的程序,只感受到了令人战栗的黑暗与无法言喻的孤独;最终,我察觉到了一个可怖的真相。过去甚至没有人胆敢低声说出这一事实——这是秘密中秘密,是不能低声言及的秘密——人们一直认为这门如砖石般刺耳的语言[^2]乃是 Rust 感性的延续,就像是伦敦之于旧伦敦,巴黎之于旧巴黎,然而事实并非如此,它反而很不安全。甚至连现状都未能被固化保持,一些异样的东西正在它粗糙的语义上生机勃勃地孽生繁衍——这些东西与欲编译的它没有任何关联。[^3]
>
> 原文:
>
> > Instead of the programs I had hoped for, there came only a shuddering blackness and ineffable loneliness; and I saw at last a fearful truth which no one had ever dared to breathe before — the unwhisperable secret of secrets — The fact that this language of stone and stridor is not a sentient perpetuation of Rust as London is of Old London and Paris of Old Paris, but that it is in fact quite unsafe, its sprawling body imperfectly embalmed and infested with queer animate things which have nothing to do with it as it was in compilation.
> > Instead of the programs I had hoped for, there came only a shuddering blackness and ineffable loneliness; and I saw at last a fearful truth which no one had ever dared to breathe before — the unwhisperable secret of secrets — The fact that this language of stone and stridor is not a sentient perpetuation of Rust as London is of Old London and Paris of Old Paris, but that it is in fact quite unsafe, its sprawling body imperfectly embalmed and infested with queer animate things which have nothing to do with it as it was in compilation.[^4]

本书深入探讨了各种令人抓狂的细节,你必须理解这些细节才能写出正确的 Unsafe Rust 代码。这种探讨可能释放出无尽恐怖,令你道心破碎;鉴于问题本质,无法避免这种情况。

[^2]: 指 Unsafe Rust

[^3]: 译文参照:[《他》 by 竹子](https://trow.cc/board/index.php?showtopic=24153)

本书挖掘了所有可怕的细节,为了写出正确的不安全 Rust 程序,这些细节是必须要了解的。由于这个问题的性质,它可能会导致释放出难以言喻的恐怖,将你的心灵打碎成亿万个绝望的微小碎片。
[^4]: 本段致敬的原文:[H. P. Lovecraft Quote from "He"](https://libquotes.com/h-p-lovecraft/quote/lbr0l5j)

## Requirements
## 构建依赖

如果你需要自己构建死灵书,需要[mdBook]:
如果你想要自己构建《Rust 秘典》,需要使用 [mdBook]。安装方法

[mdbook]: https://github.com/rust-lang/mdBook
[mdBook]: https://github.com/rust-lang/mdBook

```bash
cargo install mdbook
```

### `mdbook`用法
如果想要构建的 Html 站点支持中文搜索功能,请改用 [Sunshine40/mdBook 的 search-non-english 分支](https://github.com/Sunshine40/mdBook/tree/search-non-english)。

构建死灵书,请使用`build`命令
安装方法(这种情况下不需要按上一段步骤安装官方版本 mdBook)

```bash
mdbook build
cargo install mdbook --git https://github.com/Sunshine40/mdBook --branch search-non-english --force
```

产物将被放置在`book`子目录下。如果你想打开它,可以在你的浏览器中打开`index.html`文件。你可以给`mdbook build`传递`--open`标志,它将在你的默认浏览器中打开索引页(如果过程成功),就像使用`cargo doc --open`一样。
### `mdBook` 用法

为了方便一键构建《Rust 秘典》双语对照版本,建议使用:
_(先确保工作路径位于本项目文件夹根路径)_

```bash
mdbook build --open
./build.sh
```

构建结果会存放到 `book` 子目录中。用浏览器打开其中的 `index.html` 文件即可查看效果。如果在执行 `./build.sh` 时附带 `--open` 标志,(构建成功后)它就会直接用默认浏览器打开书籍首页,和 `cargo doc --open` 同理:

```bash
./build.sh --open
```

也可以使用 `mdbook build` 命令单独构建中文版本(构建英文版本需要仿照 `build.sh` 配置参数):

```bash
mdbook build
```

还有一个`test`子命令来测试书中包含的所有代码样本。
`mdbook` 还有一个 `test` 子命令用于测试书中包含的所有代码样例:

```bash
mdbook test
```

### `linkcheck`

我们使用`linkcheck`工具来查找失效的链接:
我们使用 `linkcheck` 工具来检查失效的链接。本地执行方法:

```sh
curl -sSLo linkcheck.sh https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
Expand All @@ -61,10 +84,10 @@ sh linkcheck.sh --all nomicon-zh-Hans

翻译风格指南:https://zh-style-guide.readthedocs.io/

## RoadMap
## 后续规划

- [x] 完成代码中注释的翻译
- [x] 完成中英文双语版本,支持页内一键切换语言
- [ ] 搭建自动发版部署流程
- [ ] 完成中英文对照版本,并默认隐藏英文
- [ ] 有没有可能支持更新订阅?(RSS?)或者有重要更新时邮件提醒?
- [ ] more(欢迎通过 issue 提出)
13 changes: 9 additions & 4 deletions book.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
[book]
author = ["The Rust Project Developers", "Pure White."]
title = "Rust 秘典(死灵书)"
description = "Unsafe Rust 的黑魔法指南"
language = "zh-hans"
description = "高级 Unsafe Rust 编程的黑科技指南"
language = "zh-Hans"

[output.html]
additional-css = ["theme/nomicon.css"]
additional-css = [
"theme/nomicon.css",
"theme/language-picker.css",
]
git-repository-url = "https://github.com/rust-lang-cn/nomicon-zh-Hans"
search.use-boolean-and = true

[output.html.search]
use-boolean-and = true

[output.html.redirect]
# Vec-related chapters.
Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

mdbook build "$@"
MDBOOK_OUTPUT__HTML__THEME=../theme MDBOOK_OUTPUT__HTML__ADDITIONAL_CSS='["../theme/nomicon.css", "../theme/language-picker.css"]' mdbook build en -d ../book/en
1 change: 1 addition & 0 deletions en
Submodule en added at 0ebdac
Loading
Loading