1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-27 11:08:45 +02:00

zh-TW: translate cargo (#871)

* zh-TW: translate cargo

Part of #684.

* Apply suggestions from code review

Co-authored-by: Jonathan Hao <phao@chromium.org>

* Use 建構 for build instead of 建立

---------

Co-authored-by: Jonathan Hao <phao@chromium.org>
Co-authored-by: Jonathan Hao <phao@google.com>
This commit is contained in:
Martin Geisler
2023-06-28 09:56:13 +02:00
committed by GitHub
parent b14aaf768d
commit 03b1c0d06b

View File

@ -1599,7 +1599,7 @@ msgstr ""
#: src/cargo.md:1 #: src/cargo.md:1
msgid "# Using Cargo" msgid "# Using Cargo"
msgstr "" msgstr "# 使用 Cargo"
#: src/cargo.md:3 #: src/cargo.md:3
msgid "" msgid ""
@ -1611,14 +1611,17 @@ msgid ""
"ecosystem\n" "ecosystem\n"
"and how it fits into this training." "and how it fits into this training."
msgstr "" msgstr ""
"您開始閱讀 Rust 內容後,很快就會認識 [Cargo](https://doc.rust-lang.org/"
"cargo/),這是在 Rust 生態系統中使用的標準工具,用於建構及執行 Rust 應用程式。"
"以下簡要介紹 Cargo,以及如何在更廣大的生態系統和本訓練課程中運用 Cargo。"
#: src/cargo.md:8 #: src/cargo.md:8
msgid "## Installation" msgid "## Installation"
msgstr "" msgstr "## 安裝"
#: src/cargo.md:10 #: src/cargo.md:10
msgid "### Rustup (Recommended)" msgid "### Rustup (Recommended)"
msgstr "" msgstr "### Rustup (建議)"
#: src/cargo.md:12 #: src/cargo.md:12
msgid "" msgid ""
@ -1626,6 +1629,8 @@ msgid ""
"other standard ecosystem tools with the [rustup][3] tool, which is " "other standard ecosystem tools with the [rustup][3] tool, which is "
"maintained by the Rust Foundation." "maintained by the Rust Foundation."
msgstr "" msgstr ""
"您可以按照指示安裝 Cargo 和 Rust 編譯器,並運用 Rust Foundation 維護的 "
"[rustup][3] 工具安裝其他標準生態系統工具。"
#: src/cargo.md:14 #: src/cargo.md:14
msgid "" msgid ""
@ -1633,20 +1638,24 @@ msgid ""
"utility that you can use to install/switch toolchains, setup cross " "utility that you can use to install/switch toolchains, setup cross "
"compilation, etc." "compilation, etc."
msgstr "" msgstr ""
"除了安裝 Cargo 和 rustc 之外,Rustup 還會將自己安裝為指令列公用程式,方便您安"
"裝/切換工具鏈、設定跨平台程式碼編譯等。"
#: src/cargo.md:16 #: src/cargo.md:16
msgid "### Package Managers" msgid "### Package Managers"
msgstr "" msgstr "### 套件管理員"
#: src/cargo.md:18 #: src/cargo.md:18
msgid "#### Debian" msgid "#### Debian"
msgstr "" msgstr "#### Debian"
#: src/cargo.md:20 #: src/cargo.md:20
msgid "" msgid ""
"On Debian/Ubuntu, you can install Cargo, the Rust source and the [Rust " "On Debian/Ubuntu, you can install Cargo, the Rust source and the [Rust "
"formatter][6] with" "formatter][6] with"
msgstr "" msgstr ""
"您可以在 Debian/Ubuntu 上使用下列程式碼,安裝 Cargo、Rust 原始碼和 [Rust 格式設"
"定工具][6]:"
#: src/cargo.md:22 #: src/cargo.md:22
msgid "" msgid ""
@ -1654,6 +1663,9 @@ msgid ""
"$ sudo apt install cargo rust-src rustfmt\n" "$ sudo apt install cargo rust-src rustfmt\n"
"```" "```"
msgstr "" msgstr ""
"```shell\n"
"$ sudo apt install cargo rust-src rustfmt\n"
"```"
#: src/cargo.md:26 #: src/cargo.md:26
msgid "" msgid ""
@ -1661,6 +1673,8 @@ msgid ""
"using\n" "using\n"
"[VS Code][2] to edit the code (but any LSP compatible editor works)." "[VS Code][2] to edit the code (but any LSP compatible editor works)."
msgstr "" msgstr ""
"這樣一來,[rust-analyzer][1] 就能跳至定義。建議您使用 [VS Code][2] 編輯程式"
"碼,不過任何與 LSP 相容的編輯器都能運作。"
#: src/cargo.md:29 #: src/cargo.md:29
msgid "" msgid ""
@ -1669,15 +1683,18 @@ msgid ""
"install the [Rust Plugin][5]. Please take note that as of January 2023 " "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." "debugging only works on the CLion version of the JetBrains IDEA suite."
msgstr "" msgstr ""
"有些人也偏好使用 [JetBrains][4] 系列的 IDE,這些工具會自行分析,但也各有缺"
"點。如果您偏好這些工具,可以安裝 [Rust 外掛程式][5]。請注意,自 2023 年 1 月"
"起,偵錯功能僅適用於 JetBrains IDEA 套件的 CLion 版本。"
#: src/cargo/rust-ecosystem.md:1 #: src/cargo/rust-ecosystem.md:1
msgid "# The Rust Ecosystem" msgid "# The Rust Ecosystem"
msgstr "" msgstr "# Rust 生態系統"
#: src/cargo/rust-ecosystem.md:3 #: src/cargo/rust-ecosystem.md:3
msgid "" msgid ""
"The Rust ecosystem consists of a number of tools, of which the main ones are:" "The Rust ecosystem consists of a number of tools, of which the main ones are:"
msgstr "" msgstr "Rust 生態系統包含多項工具,以下列出主要工具:"
#: src/cargo/rust-ecosystem.md:5 #: src/cargo/rust-ecosystem.md:5
msgid "" msgid ""
@ -1699,6 +1716,15 @@ msgid ""
"`rustup`\n" "`rustup`\n"
" will let you switch between them as needed." " will let you switch between them as needed."
msgstr "" msgstr ""
"* `rustc`:Rust 編譯器,可將 `.rs` 檔案轉換成二進位檔和其他中繼格式。\n"
"\n"
"* `cargo`:Rust 依附元件管理工具和建構工具。Cargo 知道如何下載 <https://"
"crates.io> 上代管的依附元件,且會在建構您的專案時,將這些依附元件傳送至 "
"`rustc`。Cargo 也提供內建測試執行元件,可用於執行單元測試。\n"
"\n"
"* `rustup`:Rust 工具鍊安裝程式和更新程式。新版 Rust 推出時,這項工具可用來安"
"裝及更新 `rustc` 和 `cargo`。此外,`rustup` 也可以下載標準程式庫的說明文件。"
"您可以一次安裝多個 Rust 版本,並視需要使用 `rustup` 切換版本。"
#: src/cargo/rust-ecosystem.md:21 src/hello-world.md:25 #: src/cargo/rust-ecosystem.md:21 src/hello-world.md:25
#: src/hello-world/small-example.md:27 src/why-rust/runtime.md:10 #: src/hello-world/small-example.md:27 src/why-rust/runtime.md:10
@ -1749,10 +1775,39 @@ msgid ""
"[cargo clippy]).\n" "[cargo clippy]).\n"
" * Read more from the [official Cargo Book]" " * Read more from the [official Cargo Book]"
msgstr "" msgstr ""
"* Rust 的發布時程相當緊湊,每六週就會推出新版本。新版本可與舊版本回溯相容,且"
"會啟用新功能。\n"
"\n"
"* 發布版本 (release channel) 分為三種:「穩定版」、「Beta 版」和「Nightly "
"版」。\n"
"\n"
"* 「Nightly 版」會用於測試新功能,「Beta 版」則會每六週成為「穩定版」。\n"
"\n"
"* Rust 還具有[版本] (edition):目前版本為 Rust 2021。先前版本為 Rust 2015 和 "
"Rust 2018。\n"
"\n"
" * 這些版本可針對語言進行回溯不相容的變更。\n"
"\n"
" * 為避免破壞程式碼,版本皆為自行選擇採用:您可以透過 `Cargo.toml` 檔案選擇"
"所需版本。\n"
"\n"
" * 為避免分割生態系統,Rust 編譯器可混合寫給不同版本的程式碼。\n"
"\n"
" * 請說明很少會略過 `cargo` 直接使用編譯器,大部分使用者都不會這麼做。\n"
"\n"
" * 可以考慮暗示 Cargo 本身是極其強大且功能全面的工具,具有許多進階功能,包括"
"但不限於:\n"
" * 專案/套件結構\n"
" * [工作區]\n"
" * 開發人員依附元件和執行階段依附元件管理/快取\n"
" * [建構指令碼]\n"
" * [全域安裝]\n"
" * 此外,還可以擴充使用子指令外掛程式,例如 [cargo clippy]\n"
" * 詳情請參閱[官方的 Cargo 手冊]。"
#: src/cargo/code-samples.md:1 #: src/cargo/code-samples.md:1
msgid "# Code Samples in This Training" msgid "# Code Samples in This Training"
msgstr "" msgstr "# 本訓練課程的程式碼範例"
#: src/cargo/code-samples.md:3 #: src/cargo/code-samples.md:3
msgid "" msgid ""
@ -1762,6 +1817,8 @@ msgid ""
"and\n" "and\n"
"ensures a consistent experience for everyone." "ensures a consistent experience for everyone."
msgstr "" msgstr ""
"在本訓練課程中,我們主要會透過範例瞭解 Rust 語言,這些範例可在瀏覽器中執行。"
"這麼做可讓設定程序更輕鬆,並確保所有人獲得一致的體驗。"
#: src/cargo/code-samples.md:7 #: src/cargo/code-samples.md:7
msgid "" msgid ""
@ -1771,10 +1828,12 @@ msgid ""
"to\n" "to\n"
"work with dependencies and for that you need Cargo." "work with dependencies and for that you need Cargo."
msgstr "" msgstr ""
"我們仍建議安裝 Cargo,方便您更輕鬆做習題。在最後一天,我們會做規模較大的習"
"題,讓您瞭解如何使用依附元件,而這需要使用 Cargo。"
#: src/cargo/code-samples.md:11 #: src/cargo/code-samples.md:11
msgid "The code blocks in this course are fully interactive:" msgid "The code blocks in this course are fully interactive:"
msgstr "" msgstr "本課程的程式碼區塊皆完全為互動式:"
#: src/cargo/code-samples.md:13 #: src/cargo/code-samples.md:13
msgid "" msgid ""
@ -1784,19 +1843,25 @@ msgid ""
"}\n" "}\n"
"```" "```"
msgstr "" msgstr ""
"```rust,editable\n"
"fn main() {\n"
" println!(\"Edit me!\");\n"
"}\n"
"```"
#: src/cargo/code-samples.md:19 #: src/cargo/code-samples.md:19
msgid "" msgid ""
"You can use <kbd>Ctrl + Enter</kbd> to execute the code when focus is in " "You can use <kbd>Ctrl + Enter</kbd> to execute the code when focus is in "
"the\n" "the\n"
"text box." "text box."
msgstr "" msgstr "當焦點位於文字方塊時,按下 <kbd>Ctrl + Enter</kbd> 鍵即可執行程式碼。"
#: src/cargo/code-samples.md:24 #: src/cargo/code-samples.md:24
msgid "" msgid ""
"Most code samples are editable like shown above. A few code samples\n" "Most code samples are editable like shown above. A few code samples\n"
"are not editable for various reasons:" "are not editable for various reasons:"
msgstr "" msgstr ""
"大部分程式碼範例都可供編輯,如上所示。有些程式碼範例無法編輯,原因如下:"
#: src/cargo/code-samples.md:27 #: src/cargo/code-samples.md:27
msgid "" msgid ""
@ -1808,10 +1873,15 @@ msgid ""
" solve the exercises using a local Rust installation or via the\n" " solve the exercises using a local Rust installation or via the\n"
" Playground." " Playground."
msgstr "" msgstr ""
"* 嵌入式遊樂場無法執行單元測試。請複製貼上程式碼,然後在實際的 Playground 中"
"開啟,即可示範單元測試。\n"
"\n"
"* 當您一離開頁面,嵌入式遊樂場就會失去目前狀態!因此,學生應使用本機 Rust 安"
"裝項目或透過 Playground 來做習題。"
#: src/cargo/running-locally.md:1 #: src/cargo/running-locally.md:1
msgid "# Running Code Locally with Cargo" msgid "# Running Code Locally with Cargo"
msgstr "" msgstr "# 使用 Cargo 在本機執行程式碼"
#: src/cargo/running-locally.md:3 #: src/cargo/running-locally.md:3
msgid "" msgid ""
@ -1822,6 +1892,9 @@ msgid ""
"of\n" "of\n"
"writing, the latest stable Rust release has these version numbers:" "writing, the latest stable Rust release has these version numbers:"
msgstr "" msgstr ""
"如果想在自己的系統上進行程式碼實驗,您會需要先安裝 Rust。請按照 [Rust 手冊中"
"的指示][1]操作。您應會獲得正常運作的 `rustc` 和 `cargo`。截至本文撰寫時間,最"
"新的 Rust 穩定版具有下列版本編號:"
#: src/cargo/running-locally.md:8 #: src/cargo/running-locally.md:8
msgid "" msgid ""
@ -1832,12 +1905,20 @@ msgid ""
"cargo 1.69.0 (6e9a83356 2023-04-12)\n" "cargo 1.69.0 (6e9a83356 2023-04-12)\n"
"```" "```"
msgstr "" 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 #: src/cargo/running-locally.md:15
msgid "" msgid ""
"With this in place, follow these steps to build a Rust binary from one\n" "With this in place, follow these steps to build a Rust binary from one\n"
"of the examples in this training:" "of the examples in this training:"
msgstr "" msgstr ""
"完成上述步驟後,請按照下列步驟操作,在本訓練課程的任一範例中建構 Rust 二進位"
"檔:"
#: src/cargo/running-locally.md:18 #: src/cargo/running-locally.md:18
msgid "" msgid ""
@ -1896,6 +1977,52 @@ msgid ""
" run `cargo` commands, it will automatically download and compile missing\n" " run `cargo` commands, it will automatically download and compile missing\n"
" dependencies for you." " dependencies for you."
msgstr "" msgstr ""
"1. 在要複製的範例中,按一下「Copy to clipboard」按鈕。\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` 中的樣板程式碼替換為自己的程式碼。以上一頁的範例為例,替"
"換後的 `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` 在不執行"
"的情況下編譯專案。您會在 `target/debug/` 中看到一般偵錯版本的輸出內容。使用 "
"`cargo build --release`,在 `target/release/` 中產生經過最佳化的發布子版"
"本。\n"
"\n"
"7. 只要編輯 `Cargo.toml`,即可為專案新增依附元件。執行 `cargo` 指令時,系統會"
"自動下載及編譯缺少的依附元件。"
#: src/cargo/running-locally.md:70 #: src/cargo/running-locally.md:70
msgid "" msgid ""
@ -1903,6 +2030,8 @@ msgid ""
"local editor. It will make their life easier since they will have a\n" "local editor. It will make their life easier since they will have a\n"
"normal development environment." "normal development environment."
msgstr "" msgstr ""
"建議您鼓勵課程參與者安裝 Cargo 及使用本機編輯器。這麼做能提供正常的開發環境,"
"降低操作難度。"
#: src/welcome-day-1.md:1 #: src/welcome-day-1.md:1
msgid "# Welcome to Day 1" msgid "# Welcome to Day 1"