本指南說明如何使用偏好的 Cloud Translation API 版本列出支援的語言。
事前準備
如要開始使用 Cloud Translation API,必須先準備一個已啟用 Cloud Translation API 的專案,並取得適當的憑證。您也可以安裝常用程式設計語言的用戶端程式庫,協助您呼叫 API。詳情請參閱「設定」頁面。
選擇偏好的 API 版本:
列出支援的語言
REST
如要取得支援語言的清單,請向 https://translation.googleapis.com/v3/projects/project-number-or-id/locations/location/supportedLanguages 網址發出 GET 要求。以下顯示使用 curl 和 PowerShell 的 GET 要求範例。其中使用的存取權杖,屬於透過 Google Cloud Google Cloud CLI 建立的專案服務帳戶。如需安裝 Google Cloud CLI、使用服務帳戶建立專案,以及取得存取權杖的操作說明,請參閱「設定」頁面。
使用任何要求資料之前,請先替換以下項目:
- PROJECT_NUMBER_OR_ID: Google Cloud 專案的數值或英數字元 ID
HTTP 方法和網址:
GET https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/global/supportedLanguages
請展開以下其中一個選項,以傳送要求:
您應該會收到如下的 JSON 回覆:
{
"languages": [
"languageCode": "af",
"supportSource": true,
"supportTarget": true
},
{
"languageCode": "am",
"supportSource": true,
"supportTarget": true
},
{
"languageCode": "ar",
"supportSource": true,
"supportTarget": true
},
....
{
"languageCode": "zu",
"supportSource": true,
"supportTarget": true
}
]
}
清單會依語言代碼的字母順序排序。這項查詢會傳回支援語言的 ISO-639 語言代碼。部分語言也會包含國家/地區代碼,例如 zh-CN 或 zh-TW。例如:
{
"languageCode": "zh-TW",
"supportSource": true,
"supportTarget": true
},Go
在試用這個範例之前,請先按照「使用用戶端程式庫的 Cloud Translation 快速入門導覽課程」中的 Go 設定操作說明進行操作。詳情請參閱「Cloud Translation Go API 參考文件」。
如要向 Cloud Translation 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Java
在試用這個範例之前,請先按照「使用用戶端程式庫的 Cloud Translation 快速入門導覽課程」中的 Java 設定操作說明進行操作。詳情請參閱「Cloud Translation Java API 參考文件」。
如要向 Cloud Translation 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。