自動翻译動態內容

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

標準翻譯工作流程會根據玩家查看的頻率偵測您體驗中的字串,並將它們添加到本地化表中以供翻譯。它可能會錯過在遊戲期間生成的罕見字串和/或在遊戲期間創建的文字,例如動態生成的文字或玩家創建的文字。您可以使用翻譯文字 API 在實時生成這些字串的翻譯,確保您的體驗完全本地化

將文字翻譯成玩家語言

若要將文字翻譯為玩家的語言,請將 Player.LocaleId 傳送為目標語言代碼。以下是客戶端腳本如何獲得玩家的本地 ID 的例子,然後將其傳給 ScriptServerScriptService 中進行翻譯請求。

客戶端脚本

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local httpRequestFunction = ReplicatedStorage:WaitForChild("TranslateTextFunction")
-- 待翻譯的文字
local textToTranslate = "This is the example text to translate"
-- 取得播放器的本地
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- 獲取本地玩家的本地ID或設為任何支持的本地字串
local locale = player.LocaleId
local translatedText = httpRequestFunction:InvokeServer(textToTranslate, locale)
print("Translated text: ", 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>
-- 創建遠端函數
local remoteFunction = Instance.new("RemoteFunction")
remoteFunction.Name = "TranslateTextFunction"
remoteFunction.Parent = ReplicatedStorage
remoteFunction.OnServerInvoke = function(player, text, locale, uni)
print(player.Name .. " requested translation for text: " .. text .. " to locale: " .. 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] -- 假設翻譯[locale]包含翻譯的文字
else
return "Error: " .. result.Error.message
end
end

測試中

目前實時翻譯 API 只支持 RCC 認證。因此,您必須將代碼部署到測試實例才能從 Studio 測試 API。使用 團隊測試 將腳本部署到測試實例並測試您的更改。

翻譯API參考

API 請求參數

參數名稱類型說明
路径字串宇宙的路徑。必須。
文本字串要翻譯的文字。必須。
來源語言代碼字串IETF BCP-47 語言代碼代表輸入文本的語言。如果未提供,系統將自動偵測來源語言。
目標語言代碼Array<string>轉譯時使用 IETF BCP-47 格式的目標語言代碼列表。

API 回應字段

字段名稱類型說明
來源語言代碼字串IETF BCP-47 語言代碼代表來源文本的偵測或使用者指定語言。
翻譯Dictionary<string, string>包含要求的翻譯的地圖。關鍵是 IETF BCP-47 語言代碼,值是該語言的翻譯文本。地圖會包含所有要求的翻譯。如果來源文字被過濾,此地圖將為空。

限額

Roblox 使用以下公式來根據體驗中的玩家數量限制此 API 的請求:

max requests per minute per experience = 600 + (1.5 * number_of_concurrent_users)

還有每分鐘結合的限制為 150 個請求、每個遊戲伺服器對所有開放雲端 API 的請求。

支持語言

實時翻譯 API 目前支持以下語言,與自動翻譯支持的語言略有不同 .

语言語言代碼
中文(簡體)zh-cn
中文(傳統)zh-tw
英文en-us
法語fr-fr
德語de-de
印尼語id-id
意大利語它-它
日文ja-jp
韓語ko-kr
波蘭語pl-pl
葡萄牙語pt-br
俄語ru-ru
西班牙語es-es
泰語zh-tw
土耳其語tr-tr
越南语vi-vn