1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-18 05:37:52 +02:00

zh-CN: translate cargo (#870)

* zh-CN: translate cargo

Part of #324.

* Apply suggestions from code review

Co-authored-by: Abner Chou <zhcjtht@hotmail.com>

---------

Co-authored-by: Abner Chou <zhcjtht@hotmail.com>
This commit is contained in:
Martin Geisler 2023-06-28 11:01:28 +02:00 committed by GitHub
parent 03b1c0d06b
commit fe40ef54e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1582,7 +1582,7 @@ msgstr ""
#: src/cargo.md:1
msgid "# Using Cargo"
msgstr ""
msgstr "# 使用 Cargo"
#: src/cargo.md:3
msgid ""
@ -1594,14 +1594,19 @@ msgid ""
"ecosystem\n"
"and how it fits into this training."
msgstr ""
"开始了解 Rust 后,你很快就会遇到 [Cargo](https://doc.rust-lang.org/cargo/),"
"这是 Rust 生态系统中\n"
"用于构建和运行 Rust 应用的标准工具。在这里,我们希望\n"
"简要介绍一下什么是 Cargo,它如何融入更广泛的生态系统,\n"
"以及我们如何在本培训中合理利用 Cargo。"
#: src/cargo.md:8
msgid "## Installation"
msgstr ""
msgstr "## 安装"
#: src/cargo.md:10
msgid "### Rustup (Recommended)"
msgstr ""
msgstr "### Rustup(推荐)"
#: src/cargo.md:12
msgid ""
@ -1609,6 +1614,8 @@ msgid ""
"other standard ecosystem tools with the [rustup][3] tool, which is "
"maintained by the Rust Foundation."
msgstr ""
"你可以按照说明,使用由 Rust 基金会维护的 [rustup][3] 工具安装 cargo 和 rust "
"编译器,以及其他标准的生态系统工具。"
#: src/cargo.md:14
msgid ""
@ -1616,20 +1623,24 @@ msgid ""
"utility that you can use to install/switch toolchains, setup cross "
"compilation, etc."
msgstr ""
"Rustup 将与 cargo 和 rustc 一起安装为命令行实用程序,你可以用它来安装/切换工"
"具链、设置交叉编译等。"
#: src/cargo.md:16
msgid "### Package Managers"
msgstr ""
msgstr "### 软件包管理系统"
#: src/cargo.md:18
msgid "#### Debian"
msgstr ""
msgstr "#### Debian"
#: src/cargo.md:20
msgid ""
"On Debian/Ubuntu, you can install Cargo, the Rust source and the [Rust "
"formatter][6] with"
msgstr ""
"在 Debian/Ubuntu 上,你可以通过以下方式安装 Cargo、Rust 源代码和 [Rust 格式设"
"置工具][6]:"
#: src/cargo.md:22
msgid ""
@ -1637,6 +1648,9 @@ msgid ""
"$ sudo apt install cargo rust-src rustfmt\n"
"```"
msgstr ""
"```shell\n"
"$ sudo apt install cargo rust-src rustfmt\n"
"```"
#: src/cargo.md:26
msgid ""
@ -1644,6 +1658,8 @@ msgid ""
"using\n"
"[VS Code][2] to edit the code (but any LSP compatible editor works)."
msgstr ""
"这将允许 [rust-analyzer][1] 跳到定义。我们建议使用\n"
"[VS Code][2] 来编写代码(也可使用任何兼容 LSP 的编辑器)。"
#: src/cargo.md:29
msgid ""
@ -1652,15 +1668,18 @@ msgid ""
"install the [Rust Plugin][5]. Please take note that as of January 2023 "
"debugging only works on the CLion version of the JetBrains IDEA suite."
msgstr ""
"有些人还喜欢使用 [JetBrains][4] IDE 系列自行分析,但会根据自身情况加以权衡。"
"如果你想使用这些工具,可以安装 [Rust 插件][5]。请注意,自 2023 年 1 月起,调"
"试仅适用于 CLion 版本的 JetBrains IDEA 套件。"
#: src/cargo/rust-ecosystem.md:1
msgid "# The Rust Ecosystem"
msgstr ""
msgstr "# Rust 生态系统"
#: src/cargo/rust-ecosystem.md:3
msgid ""
"The Rust ecosystem consists of a number of tools, of which the main ones are:"
msgstr ""
msgstr "Rust 生态系统由许多工具组成,其中的主要工具包括:"
#: src/cargo/rust-ecosystem.md:5
msgid ""
@ -1682,6 +1701,19 @@ msgid ""
"`rustup`\n"
" will let you switch between them as needed."
msgstr ""
"* `rustc`:Rust 编译器,可将 `.rs` 文件转换为二进制文件和其他\n"
"中间格式。\n"
"\n"
"* `cargo`:Rust 依赖项管理器和构建工具。Cargo 知道如何\n"
"下载托管在 <https://crates.io> 上的依赖项,并在构建项目时将它们\n"
"传递给 `rustc`。Cargo 还附带一个内置的\n"
"测试运行程序,用于执行单元测试。\n"
"\n"
"* `rustup`:Rust 工具链安装程序和更新程序。发布新版本 Rust 时,此工具用于\n"
"安装并更新 `rustc` 和 `cargo`。\n"
"此外,`rustup` 还可以下载标准\n"
"库的文档。你可以同时安装多个版本的 Rust,并且 `rustup`\n"
"可让你根据需要在这些版本之间切换。"
#: src/cargo/rust-ecosystem.md:21 src/hello-world.md:25
#: src/hello-world/small-example.md:27 src/why-rust/runtime.md:10
@ -1732,10 +1764,43 @@ msgid ""
"[cargo clippy]).\n"
" * Read more from the [official Cargo Book]"
msgstr ""
"* Rust 有一个快速发布时间表,每六周就会发布一次\n"
"新版本。新版本保持与\n"
"旧版本的向后兼容性,还添加了新功能。\n"
"\n"
"* 共有三个发布阶段:“稳定版”“Beta 版”和“夜间版”。\n"
"\n"
"* 我们会在“夜间版”上测试新功能,每六周将“Beta 版”升级为\n"
"“稳定版”。\n"
"\n"
"* Rust 也有三个[版本]:当前版本是 Rust 2021。之前的\n"
"版本是 Rust 2015 和 Rust 2018。\n"
"\n"
" * 这些版本支持对语言进行向后不兼容的\n"
"更改。\n"
"\n"
" * 为防止破坏代码,你可以自行选择版本:\n"
"通过 `Cargo.toml` 文件为 crate 选择合适的版本。\n"
"\n"
" * 为免分割生态系统,Rust 编译器可以混合使用\n"
"为不同版本编写的代码。\n"
"\n"
" * 提及不通过 `cargo` 而直接使用编译器的情况相当少见(大多数用户从不这样"
"做)。\n"
"\n"
" * 值得注意的是,Cargo 本身就是一个功能强大且全面的工具。它能够实现许多高级"
"功能,包括但不限于:\n"
" * 项目/软件包结构\n"
" * [工作区]\n"
" * 开发依赖项和运行时依赖项管理/缓存\n"
" * [构建脚本]\n"
" * [全局安装] ]\n"
" * 它还可以使用子命令插件(例如 [cargo clippy])进行扩展。\n"
" * 如需了解详情,请参阅[ Cargo 官方图书]"
#: src/cargo/code-samples.md:1
msgid "# Code Samples in This Training"
msgstr ""
msgstr " # 本培训中的代码示例"
#: src/cargo/code-samples.md:3
msgid ""
@ -1745,6 +1810,9 @@ msgid ""
"and\n"
"ensures a consistent experience for everyone."
msgstr ""
"在本培训中,我们将主要通过示例\n"
"探索 Rust 语言,这些示例可通过浏览器执行。这能大大简化设置过程,\n"
"并确保所有人都能获得一致的体验。"
#: src/cargo/code-samples.md:7
msgid ""
@ -1754,10 +1822,13 @@ msgid ""
"to\n"
"work with dependencies and for that you need Cargo."
msgstr ""
"我们仍然建议你安装 Cargo:它有助于你更轻松地完成\n"
"练习。在最后一天,我们要做一个更大的练习,\n"
"向你展示如何使用依赖项,因此你需要安装 Cargo。"
#: src/cargo/code-samples.md:11
msgid "The code blocks in this course are fully interactive:"
msgstr ""
msgstr "本课程中的代码块是完全交互式的:"
#: src/cargo/code-samples.md:13
msgid ""
@ -1767,6 +1838,11 @@ msgid ""
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"fn main() {\n"
" println!(\"Edit me!\");\n"
"}\n"
"```"
#: src/cargo/code-samples.md:19
msgid ""
@ -1774,12 +1850,16 @@ msgid ""
"the\n"
"text box."
msgstr ""
"当文本框为\n"
"焦点时,你可以使用 <kbd>Ctrl + Enter</kbd> 来执行代码。"
#: src/cargo/code-samples.md:24
msgid ""
"Most code samples are editable like shown above. A few code samples\n"
"are not editable for various reasons:"
msgstr ""
"大多数代码示例都可修改(如上图所示)。少数代码示例\n"
"可能会因各种原因而不可修改:"
#: src/cargo/code-samples.md:27
msgid ""
@ -1791,10 +1871,17 @@ msgid ""
" solve the exercises using a local Rust installation or via the\n"
" Playground."
msgstr ""
"* 嵌入式 Playground 无法执行单元测试。将代码复制并粘贴\n"
"到实际 Playground 中,以演示单元测试。\n"
"\n"
"* 嵌入式 Playground 会在你离开页面后立即\n"
"丢失其状态!正因如此,学员应\n"
"使用本地安装的 Rust 或通过\n"
"Playground 解题。"
#: src/cargo/running-locally.md:1
msgid "# Running Code Locally with Cargo"
msgstr ""
msgstr "# 使用 Cargo 在本地运行代码"
#: src/cargo/running-locally.md:3
msgid ""
@ -1805,6 +1892,10 @@ msgid ""
"of\n"
"writing, the latest stable Rust release has these version numbers:"
msgstr ""
"如果你想在自己的系统上对代码进行实验,\n"
"则需要先安装 Rust。为此,请按照 [Rust 图书中的\n"
"说明][1]操作。这应会为你提供一个有效的 `rustc` 和 `cargo`。在撰写\n"
"本文时,最新的 Rust 稳定版具有以下版本号:"
#: src/cargo/running-locally.md:8
msgid ""
@ -1815,12 +1906,20 @@ msgid ""
"cargo 1.69.0 (6e9a83356 2023-04-12)\n"
"```"
msgstr ""
"```shell\n"
"% rustc --version\n"
"rustc 1.69.0 (84c898d65 2023-04-16)\n"
"% cargo --version\n"
"cargo 1.69.0 (6e9a83356 2023-04-12)\n"
"```"
#: src/cargo/running-locally.md:15
msgid ""
"With this in place, follow these steps to build a Rust binary from one\n"
"of the examples in this training:"
msgstr ""
"了解这些信息后,请按照以下步骤从本培训中的\n"
"一个示例中构建 Rust 二进制文件:"
#: src/cargo/running-locally.md:18
msgid ""
@ -1879,6 +1978,54 @@ msgid ""
" run `cargo` commands, it will automatically download and compile missing\n"
" dependencies for you."
msgstr ""
"1. 在你要复制的示例上点击“复制到剪贴板”按钮。\n"
"\n"
"2. 使用 `cargo new exercise` 为你的代码新建一个 `exercise/` 目录:\n"
"\n"
" ```shell\n"
" $ cargo new exercise\n"
" Created binary (application) `exercise` package\n"
" ```\n"
"\n"
"3. 导航至 `exercise/` 并使用 `cargo run` 构建并运行你的二进制文件:\n"
"\n"
" ```shell\n"
" $ cd exercise\n"
" $ cargo run\n"
" Compiling exercise v0.1.0 (/home/mgeisler/tmp/exercise)\n"
" Finished dev [unoptimized + debuginfo] target(s) in 0.75s\n"
" Running `target/debug/exercise`\n"
" Hello, world!\n"
" ```\n"
"\n"
"4. 将 `src/main.rs` 中的样板代码替换为你自己的代码。例如,\n"
"使用上一页中的示例,将 `src/main.rs` 改为:\n"
"\n"
" ```rust\n"
" fn main() {\n"
" println!(\"Edit me!\");\n"
" }\n"
" ```\n"
"\n"
"5. 使用 `cargo run` 构建并运行你更新后的二进制文件:\n"
"\n"
" ```shell\n"
" $ cargo run\n"
" Compiling exercise v0.1.0 (/home/mgeisler/tmp/exercise)\n"
" Finished dev [unoptimized + debuginfo] target(s) in 0.24s\n"
" Running `target/debug/exercise`\n"
" Edit me!\n"
" ```\n"
"\n"
"6. 使用 `cargo check` 快速检查项目是否存在错误;使用 `cargo build`\n"
"只进行编译,而不运行。你可以在 `target/debug/`\n"
"中找到常规调试 build 的输出。使用 `cargo build --release` 在 `target/release/"
"` 中生成经过优化的\n"
"发布 build。\n"
"\n"
"7. 你可以通过修改 `Cargo.toml` 为项目添加依赖项。当你\n"
"运行 `cargo` 命令时,系统会自动为你下载和编译缺失\n"
"的依赖项。"
#: src/cargo/running-locally.md:70
msgid ""
@ -1886,6 +2033,9 @@ msgid ""
"local editor. It will make their life easier since they will have a\n"
"normal development environment."
msgstr ""
"尽量鼓励全班学员安装 Cargo 并使用\n"
"本地编辑器。这能为他们营造常规\n"
"开发环境,让工作变得更加轻松。"
#: src/welcome-day-1.md:1
msgid "# Welcome to Day 1"