Create an API Key

Check my progress

/ 100

This lab may incorporate AI tools to support your learning.
This content is not yet optimized for mobile devices.
For the best experience, please visit us on a desktop computer using a link sent by email.

GSP049

Google Cloud 自學實驗室

總覽

Cloud Translation API 採用 Google 的神經機器翻譯技術,能將文字即時翻譯成上百種語言。

在本實驗室中,您將使用這個 API 翻譯文字,並偵測該段文字的語言。

課程內容

在本實驗室中,您將使用 Cloud Translation API 執行下列工作:

  • 建立 Cloud Translation API 要求,並使用 curl 呼叫 API
  • 翻譯文字
  • 使用進階版
  • 偵測語言

設定和需求

瞭解以下事項後,再點選「Start Lab」按鈕

請詳閱以下操作說明。實驗室活動會計時,且中途無法暫停。點選「Start Lab」後就會開始計時,顯示可使用 Google Cloud 資源的時間。

您將在真正的雲端環境完成實作實驗室活動,而不是模擬或示範環境。為此,我們會提供新的暫時憑證,供您在實驗室活動期間登入及存取 Google Cloud。

為了順利完成這個實驗室,請先確認:

  • 可以使用標準的網際網路瀏覽器 (Chrome 瀏覽器為佳)。
注意事項:請使用無痕模式 (建議選項) 或私密瀏覽視窗執行此實驗室,這可以防止個人帳戶和學員帳戶之間的衝突,避免個人帳戶產生額外費用。
  • 是時候完成實驗室活動了!別忘了,活動一旦開始將無法暫停。
注意事項:務必使用實驗室專用的學員帳戶。如果使用其他 Google Cloud 帳戶,可能會產生額外費用。

如何開始實驗室及登入 Google Cloud 控制台

  1. 按一下「Start Lab」按鈕。如果實驗室會產生費用,請在開啟的對話方塊中選取付款方式。右側的「Lab setup and access」面板會顯示下列項目:

    • 「Open Google Cloud console」按鈕
    • 此實驗室所需的臨時憑證 (使用者名稱和密碼)
    • 完成此實驗室所需的其他資訊 (如有)

    請注意,實驗室計時器位於頁面頂端附近,會顯示剩餘時間。

  2. 按一下「Open Google Cloud console」。如果使用 Chrome 瀏覽器,也可以按一下滑鼠右鍵,選取「在無痕視窗中開啟連結」。

    接著,實驗室會啟動相關資源,並開啟另一個分頁,顯示「登入」頁面。

    提示:您可以在不同的視窗並排開啟分頁。

    注意:頁面顯示「選擇帳戶」對話方塊時,請點選「使用其他帳戶」。
  3. 如有必要,請將下方的 Username 貼到「登入」對話方塊。

    {{{user_0.username | "Username"}}}

    您也可以在「Lab setup and access」面板找到「Username」。

  4. 點選「下一步」。

  5. 複製下方的 Password,並貼到「歡迎使用」對話方塊。

    {{{user_0.password | "Password"}}}

    您也可以在「Lab setup and access」面板找到「Password」。

  6. 點選「下一步」。

    重要事項:請務必使用實驗室提供的憑證,而非自己的 Google Cloud 帳戶憑證。 注意:如果使用自己的 Google Cloud 帳戶來進行這個實驗室,可能會產生額外費用。
  7. 繼續點按後續頁面:

    • 接受條款及細則。
    • 由於這是臨時帳戶,請勿新增救援選項或雙重驗證機制。
    • 請勿申請免費試用。

Google Cloud 控制台稍後會在這個分頁開啟。

注意:如要使用 Google Cloud 產品和服務,請按一下「導覽選單」,或在「搜尋」欄位輸入服務或產品名稱。「導覽選單」圖示和搜尋欄位

啟動 Cloud Shell

Cloud Shell 是搭載多項開發工具的虛擬機器,提供永久的 5 GB 主目錄,而且在 Google Cloud 中運作。Cloud Shell 提供指令列存取權,方便您使用 Google Cloud 資源。

  1. 點按 Google Cloud 控制台頂端的「啟用 Cloud Shell」圖示 「啟動 Cloud Shell」圖示。

  2. 系統顯示視窗時,請按照下列步驟操作:

    • 繼續操作 Cloud Shell 視窗。
    • 授權 Cloud Shell 使用您的憑證發出 Google Cloud API 呼叫。

連線建立完成即代表已通過驗證,而且專案已設為您的 Project_ID:。輸出內容中有一行文字,宣告本工作階段的 Project_ID:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud 是 Google Cloud 的指令列工具,已預先安裝於 Cloud Shell,並支援 Tab 鍵自動完成功能。

  1. (選用) 您可以執行下列指令來列出使用中的帳戶:
gcloud auth list
  1. 點按「授權」。

輸出內容:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (選用) 您可以使用下列指令來列出專案 ID:
gcloud config list project

輸出內容:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} 注意:如需 gcloud 的完整說明,請前往 Google Cloud 參閱 gcloud CLI 總覽指南。

設定專案區域

請執行下列指令來設定專案區域:

export REGION={{{project_0.default_region | REGION}}} gcloud config set compute/region $REGION

工作 1:建立 API 金鑰

本實驗室稍後會使用 curl 傳送要求至 Translation API,因此您必須產生 API 金鑰,並將該金鑰帶入要求網址中。

  1. 建立 API 金鑰的第一步,是依序點選「導覽選單」圖示 「導覽選單」圖示 >「API 和服務」>「憑證」。

  2. 點選「+ 建立憑證」,然後選取「API 金鑰」。

  3. 「建立 API 金鑰」側邊面板會隨即顯示,請在「可透過這個金鑰存取的 API」部分,點選「選取 API 限制」下拉式選單。

  4. 搜尋或捲動畫面並找到「Cloud Translation API」,然後勾選核取方塊。

  5. 點選「確定」。

  6. 點選「建立」。

  7. 複製系統產生的 API 金鑰,然後點選「關閉」。

接著,將 API 金鑰儲存為環境變數,就不必在每項要求插入金鑰值。

  1. 在 Cloud Shell 執行下列指令,其中 [YOUR_API_KEY] 必須替換成您剛才複製的金鑰:
export API_KEY=[YOUR_API_KEY]

點選「Check my progress」,確認目標已達成。 建立 API 金鑰

工作 2:翻譯文字

在本例中,您要將字串「My name is Steve」翻譯成西班牙文。

  • 使用下列 curl 指令,將要翻譯的文字連同 API 金鑰環境變數,一併傳送至 Translation API:
TEXT="My%20name%20is%20Steve" curl "https://translation.googleapis.com/language/translate/v2?target=es&key=${API_KEY}&q=${TEXT}"

回應內容應如下所示:

{ "data": { "translations": [ { "translatedText": "Mi nombre es Steve", "detectedSourceLanguage": "en" } ] } }

在回應中,您可以看到翻譯後的文字和 API 偵測到的來源語言。

注意:進階模式

Google Cloud Translation API 大多使用標準版模型來執行翻譯工作。Google 強化了翻譯服務,改用更強大的神經機器翻譯系統。如要進一步瞭解如何使用這個進階模型,請參閱 Cloud Translation 說明文件。

工作 3:偵測語言

除了翻譯文字,Translation API 還能偵測文字的語言。在本例中,您將偵測兩個字串的語言。

  • 使用下列 curl 指令,將要偵測的文字連同 API 金鑰環境變數,一併傳送至 Translation API:
TEXT_ONE="Meu%20nome%20é%20Steven" TEXT_TWO="日本のグーグルのオフィスは、東京の六本木ヒルズにあります" curl -X POST "https://translation.googleapis.com/language/translate/v2/detect?key=${API_KEY}" -d "q=${TEXT_ONE}" -d "q=${TEXT_TWO}"

回應內容應如下所示:

{ "data": { "detections": [ [ { "isReliable": false, "language": "pt", "confidence": 1 } ], [ { "language": "ja", "isReliable": false, "confidence": 1 } ] ] } }

本例傳回的語言是「pt」和「ja」,分別代表葡萄牙文和日文的 ISO-639-1 識別碼。如要查看所有可能傳回的語言代碼,請參考這份 Translation API 支援的語言清單。

恭喜!

您已學會使用 Cloud Translation API 翻譯文字!

挑戰下一個實驗室

後續步驟/瞭解詳情

Google Cloud 教育訓練與認證

協助您瞭解如何充分運用 Google Cloud 的技術。我們的課程會介紹專業技能和最佳做法,讓您可以快速掌握要領並持續進修。我們提供從基本到進階等級的訓練課程,並有隨選、線上和虛擬課程等選項,方便您抽空參加。認證可協助您驗證及證明自己在 Google Cloud 技術方面的技能和專業知識。

使用手冊上次更新日期:2026 年 4 月 8 日

實驗室上次測試日期:2026 年 4 月 8 日

Copyright 2026 Google LLC 保留所有權利。Google 和 Google 標誌是 Google LLC 的商標,其他公司和產品名稱則有可能是其關聯公司的商標。

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We can notify you via email when it becomes available

Great!

We can contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Using an Incognito or private browser window is the best way to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.