Hey Creators!
We’re excited to announce the launch of our real-time translation API! This will enable you to generate automatic translations for text in your experience without using the standard translation workflow.
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 to be translated. This means it may miss uncommon strings and/or strings generated during gameplay, such as dynamically-generated text or text created by players. This new real-time translation API can generate translations for these strings in real-time, ensuring that your experience is fully localized.
How to Use the Translation API
You can view the Translation API reference documentation here (link may be temporarily broken as we are working to get the page up - all relevant info should be in the post below!).
Translating Content Into the Player’s Language
You can translate text into a player’s language by passing their Player.LocaleId in as the target language code. Below is an example of how you can get the player’s locale ID in a LocalScript, and then pass it to a Script in ServerScriptService to make the translation request.
- Note that the translation API is an Open Cloud API, meaning you’ll need a path when making a request. The only path parameter you’ll need here is your experience’s Universe ID, which can be found in the overflow menu of the experience tile on the Creator Hub Creations page. Also make sure that you have included the Open Cloud client package (the linked page is for another API, but the instructions are the exact same).
- Additionally, all input text will be passed through the text filter before translation. If it does not pass, the text will not be translated and the API will return a content moderated error.
LocalScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local httpRequestFunction = ReplicatedStorage:WaitForChild("TranslateTextFunction")
-- Text to translate
local textToTranslate = "This is the example text"
-- 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:
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 = <UniverseID>
-- 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
Translation API Limits
Roblox throttles requests for this API based on the number of players in your experience. The formula for the rate limit is as follows:
max requests per minute per experience = 600 + 1.5 * # concurrent users
There is also a default Open Cloud API request limit of 150 requests per minute per game server.
Testing the Translation API
The real-time translation API currently only supports RCC authentication. As a result, you will need to 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.
Feedback
Note that the API is still in beta, so some of the settings and limits we’ve established may be subject to change. Please let us know if you run into any issues while using the API, and as always, please let us know if you have any questions, concerns, or suggestions!