自動翻譯動態內容

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

標準翻譯工作流程會根據玩家查看字串的頻率檢測您遊戲中的字串,並將其添加到您的本地化表中以供翻譯。它可能會漏掉不常見的字串或在遊玩過程中生成的字串,例如動態生成的文本或玩家創建的文本。您可以使用翻譯文本 API 來實時生成這些字串的翻譯,確保您的遊戲完全本地化。

將文本翻譯為玩家的語言

要將文本翻譯為玩家的語言,請將其 Player.LocaleId 作為目標語言代碼傳遞。下面是一個示例,說明如何在客戶端腳本中獲取玩家的地區 ID,然後將其傳遞到 Script 中的 ServerScriptService 以發出翻譯請求。

  • 翻譯 API 是一個 Open Cloud API,這意味著您需要一個 路徑 來發出請求。在這種情況下,您需要宇宙 ID,可以在 Creator Hub 的遊戲圖塊的溢出菜單中找到。
  • 您還必須在遊戲中包含 Open Cloud 客戶端包;伺服器腳本需要它。
客戶端腳本

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local httpRequestFunction = ReplicatedStorage:WaitForChild("TranslateTextFunction")
-- 要翻譯的文本
local textToTranslate = "這是要翻譯的示例文本"
-- 獲取玩家的地區
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- 獲取本地玩家的地區 ID 或設置為任何支持的地區字符串
local locale = player.LocaleId
local translatedText = httpRequestFunction:InvokeServer(textToTranslate, locale)
print("翻譯後的文本: ", translatedText)
伺服器腳本在 ServerScriptService 中

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local oc = require(ServerScriptService.OpenCloud.V2)
-- 查找位置:https://create.roblox.com/dashboard/creations 在遊戲圖塊的溢出菜單中
local universeID = <your_universe_id>
-- 創建 RemoteFunction
local remoteFunction = Instance.new("RemoteFunction")
remoteFunction.Name = "TranslateTextFunction"
remoteFunction.Parent = ReplicatedStorage
remoteFunction.OnServerInvoke = function(player, text, locale, uni)
print(player.Name .. " 請求翻譯文本: " .. text .. " 到地區: " .. locale)
-- 準備翻譯請求
local request : oc.TranslateTextRequest = {
path = oc:UniversePath(universeID),
text = text,
-- 目標語言代碼支持多地區列表進行翻譯。
-- 這裡我們僅傳遞一種語言:
-- 在本地腳本中檢索的玩家地區
target_language_codes = {locale}
}
local result = oc:TranslateText(request)
if result.Error == nil then
return result.Response.translations[locale] -- 假設 translations[locale] 包含翻譯後的文本
else
return "錯誤: " .. result.Error.message
end
end

測試

實時翻譯 API 當前僅支持 RCC 認證。因此,您必須將代碼部署到測試實例中,以便從 Studio 測試 API。使用 合作測試 部署腳本到測試實例並測試您的變更。

翻譯 API 參考

API 請求參數

參數名稱類型描述
pathstring宇宙的路徑。必填。
textstring要翻譯的文本。必填。
source_language_codestring表示輸入文本語言的 IETF BCP-47 語言代碼。如果未提供,系統將自動檢測源語言。
target_language_codesArray<string>以 IETF BCP-47 格式提供的翻譯目標語言代碼列表。

API 回應字段

字段名稱類型描述
source_language_codestring表示檢測到的或用戶指定的源文本語言的 IETF BCP-47 語言代碼。
translationsDictionary<string, string>包含請求翻譯的映射。鍵是 IETF BCP-47 語言代碼,值是該語言的翻譯文本。該映射將包含所有請求的翻譯。如果源文本被過濾,則該映射將為空。

限制

Roblox 使用以下公式根據您遊戲中的玩家數量來限制該 API 的請求:

每分鐘每個遊戲的最大請求 = 600 + (1.5 * 同時用戶數)

對於所有 Open Cloud API,針對每個遊戲伺服器還有 150 請求的總限制。

支持的語言

實時翻譯 API 當前支持以下語言,這些語言與 自動翻譯的支持語言 略有不同。

語言語言代碼
中文(簡體)zh-cn
中文(繁體)zh-tw
英語en-us
法語fr-fr
德語de-de
印尼語id-id
意大利語it-it
日語ja-jp
韓語ko-kr
波蘭語pl-pl
葡萄牙語pt-br
俄語ru-ru
西班牙語es-es
泰語th-th
土耳其語tr-tr
越南語vi-vn
©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。