Automatically translate dynamic content

The standard translation workflow detects strings in your experience based on how frequently they're viewed by players and adds them to your localization table for translation. It might miss uncommon strings and/or strings generated during gameplay, such as dynamically generated text or text created by players. You can use the translate text API to generate translations for these strings in real-time, ensuring that your experience is fully localized.

Translate text into a player's language

To translate text into a player's language, pass their Player.LocaleId as the target language code. Below is an example of how you can get the player's locale ID in a client script and then pass it to a Script in ServerScriptService to make the translation request.

  • The translation API is an Open Cloud API, meaning you need a path to make a request. In this case, you need the universe ID, which can be found in the overflow menu of the experience tile on the Creator Hub.
  • You must also include the Open Cloud client package in your experience; the server script requires it.
Client script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local httpRequestFunction = ReplicatedStorage:WaitForChild("TranslateTextFunction")
-- Text to translate
local textToTranslate = "This is the example text to translate"
-- Get the player's locale
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- get the locale ID for the local player's locale or set to any supported locale string
local locale = player.LocaleId
local translatedText = httpRequestFunction:InvokeServer(textToTranslate, locale)
print("Translated text: ", translatedText)
Server script in ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local oc = require(ServerScriptService.OpenCloud.V2)
-- Find at https://create.roblox.com/dashboard/creations in the overflow menu of an experience tile
local universeID = <your_universe_id>
-- Create RemoteFunction
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)
-- Prepare the translation request
local request : oc.TranslateTextRequest = {
path = oc:UniversePath(universeID),
text = text,
-- target language codes supports a list of multiple locales to translate to.
-- Here we are passing just one language:
--The player locale retrieved in the local script
target_language_codes = {locale}
}
local result = oc:TranslateText(request)
if result.Error == nil then
return result.Response.translations[locale] -- Assuming translations[locale] contains the translated text
else
return "Error: " .. result.Error.message
end
end

Testing

The real-time translation API currently only supports RCC authentication. As a result, you must deploy your code to a test instance in order to test the API from Studio. Use Team Test to deploy the script to a test instance and test your changes.

Translation API reference

API request parameters

Parameter NameTypeDescription
pathstringThe path of the universe. Required.
textstringThe text to be translated. Required.
source_language_codestringThe IETF BCP-47 language code representing the language of the input text. If not provided, the system will automatically detect the source language.
target_language_codesArray<string>A list of target language codes in IETF BCP-47 format for translation.

API response fields

Field NameTypeDescription
source_language_codestringThe IETF BCP-47 language code representing the detected or user-specified language of the source text.
translationsDictionary<string, string>A map containing the requested translations. The key is the IETF BCP-47 language code, and the value is the translated text for that language. The map will contain all requested translations. If the source text was filtered, this map will be empty.

Limits

Roblox uses the following formula to throttle requests for this API based on the number of players in your experience:

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

There is also a combined limit of 150 requests per minute, per game server for all Open Cloud APIs.

Supported languages

The real-time translation API currently supports the following languages, which differ slightly from supported languages for automatic translation.

LanguageLanguage Code
Chinese (Simplified)zh-cn
Chinese (Traditional)zh-tw
Englishen-us
Frenchfr-fr
Germande-de
Indonesianid-id
Italianit-it
Japaneseja-jp
Koreanko-kr
Polishpl-pl
Portuguesept-br
Russianru-ru
Spanishes-es
Thaith-th
Turkishtr-tr
Vietnamesevi-vn