自动翻译动态内容

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

标准翻译工作流程根据玩家查看字符串的频率检测游戏中的字符串,并将它们添加到本地化表中以进行翻译。它可能会遗漏不常见的字符串和/或在游戏过程中生成的字符串,例如动态生成的文本或玩家创建的文本。您可以使用翻译文本 API 实时生成这些字符串的翻译,确保您的游戏完全本地化。

将文本翻译成玩家的语言

要将文本翻译成玩家的语言,请将他们的 Player.LocaleId 作为目标语言代码传递。以下是如何在客户端脚本中获取玩家的区域 ID,然后将其传递给 ScriptServerScriptService 中进行翻译请求的示例。

  • 翻译 API 是一个 Open Cloud API,这意味着您需要一个 路径 来发起请求。在这种情况下,您需要找到宇宙 ID,可以在 创作者中心 的游戏图块的溢出菜单中找到。
  • 您还必须在游戏中包含 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 是我们在美国及其他国家或地区的注册与未注册商标。