Localization: reaching other languages

Translate a Roblox game. Learn the localization table, automatic text capture and translation, parameters for dynamic text, Translator and FormatByKey in code, and how to test a second language in Studio.

Tool lesson, about 70 minutes, 10 steps

By the end you can

  • Read a localization table by its columns and say what Source, Context and Key are for
  • Turn on automatic text capture and automatic translation, and say what they will not translate
  • Rewrite a dynamic string as a key with a parameter and format it through a Translator
  • Test a second language with the Player Emulator, using Locale, Pseudolocalize and Elongate

Before this: Publishing: versions, rollback, store page, UI fundamentals: ScreenGui, UDim2, layouts

1English, written into the code

Open Beacon Yard's HUD in a game running for a French player. It says Go to the beacon and hold E to start the drill. The text is in the script:

	local IDLE_OBJECTIVE = "Go to the beacon and hold E to start the drill"
	local ACTIVE_OBJECTIVE = "Survive and collect coins, swing the wrench at the drone"
 
	local function renderClock()
		local remaining = math.max(0, endsAt - workspace:GetServerTimeNow())
		if phase == "Active" then
			phaseLabel.Text = string.format("Active  %.1fs", remaining)
			objectiveLabel.Text = ACTIVE_OBJECTIVE
		elseif phase == "Cooldown" then
			phaseLabel.Text = "Cooldown"
			objectiveLabel.Text = string.format("Next drill in %ds", math.max(0, math.ceil(remaining)))
		else
			phaseLabel.Text = "Idle"
			objectiveLabel.Text = IDLE_OBJECTIVE
Figure 1.1

Roblox players come from many countries and speak many languages1. Every string above is English for all of them. Some lines are worse than they look: Next drill in %ds is built with string.format, so the finished sentence changes every second. A table of fixed sentences cannot hold it.

Roblox Studio
Beacon Yard's HUD at the top left of the viewport, reading Coins 485, Idle, and an objective sentence telling the player to hold E at the beacon.

Select a numbered pin, or a row below, to read what it marks.

Figure 1.2.

The HUD in Idle. Every piece of readable text here is English, written by the script.

Which pieces of the HUD in the picture are text a translator should handle?

  1. Coins
  2. Idle
  3. Go to the beacon and hold E to start the drill
  4. 485
Answer

Coins; Idle; Go to the beacon and hold E to start the drill. The three phrases are words in English. The 485 is data the game fills in, and it only needs correct number formatting, not translation.

Open this step in lesson mode · Link to this step · This confused me

2The localization table

Roblox's answer is a localization table stored on the cloud for your game2. Each row is one piece of text, with these columns:

ColumnWhat it is
SourceThe text in your source language. Required.
ContextOptional. Names the object the text belongs to, so two uses of the same word can translate differently.
ExampleOptional note for translators.
KeyOptional. A name your code can look up with Translator:FormatByKey.
LocationFilled in for you when a string is captured automatically.

One rule keeps it sane: no two rows may share the same Source and Context, and no two may share a Key. You set one source language (Roblox supports one at a time) and pick the supported languages you want to add1.

Client sideThe localization table is a phrasebook with a key on every line.
In the pictureIn Roblox
A line in the phrasebookOne row of the localization table
The number beside the lineThe Key that code looks up with FormatByKey
The same line in another languageThe column for a supported language

See the whole analogy cast

The table is a phrasebook with a key on every line. The game says "show me line 12 in Spanish" and the book gives back the Spanish sentence.

Think of it as A phrasebook with a key on every line

Match each column to its job.

  1. Source
  2. Context
  3. Key
  4. Location
Answer

Source: The text in your source language, required; Context: Tells two uses of the same word apart; Key: Lets code look an entry up by name; Location: Shows where an automatically captured string was found. Source is the only required field. Context separates identical sources, Key is for code lookups, and Location is written by automatic text capture.

Open this step in lesson mode · Link to this step · This confused me

3Let Roblox collect and translate

You do not have to type the table by hand. Automatic text capture collects text from UI objects as players (or you, in Studio) see it, and adds it to the table. Automatic translation then fills in blank entries for the languages you turned on3.

The steps:

  1. Creator Hub, your game, Audience, Localization: set the source language and add supported languages.
  2. Under Settings, turn on text capture, and turn on Use Translated Content.
  3. Under Languages, enable automatic translation for each language.

Three things to know. Automatic translation only fills blank entries and never overwrites a human translation. Manual translations are always shown to players, whatever their own setting. And it has quotas, counted per character and per language: translating "hello" into 10 languages counts as 50 characters3.

Capture only sees text objects whose AutoLocalize property is on. Switch it off on anything that must stay as written, such as a player name or a street sign3.

How many characters of automatic-translation quota does it use to translate the string Idle into 3 languages?

Answer

12 characters. Idle has 4 characters. 4 characters × 3 languages = 12.

Open this step in lesson mode · Link to this step · This confused me

4Dynamic text needs a parameter

Capture works on strings it sees. Next drill in 7s and Next drill in 6s are different strings, so a naive table would need a row for every number, forever. The fix is a parameter: one row whose Source has a named slot, written in braces with an optional format specifier4.

KeySourcefr
Hud_NextDrillNext drill in {Seconds:int}sProchain exercice dans {Seconds:int} s

int prints a whole number without separators. Other specifiers include num (two decimals with thousands separators, for example 1,234.50 or 1234,50 depending on the language) and translate, which looks up another string4.

The code asks for the key and passes the values. You can test the idea in plain Luau:

Luau
local function format(template, args)
	return (string.gsub(template, "{(%w+):?(%w*)}", function(name, kind)
		local value = args[name]
		if kind == "int" then
			return string.format("%d", value)
		end
		return tostring(value)
	end))
end
 
print(format("Next drill in {Seconds:int}s", { Seconds = 7 }))
print(format("Prochain exercice dans {Seconds:int} s", { Seconds = 7 }))
Figure 4.1. Expected output: Next drill in 7s Prochain exercice dans 7 s

This is a toy of what FormatByKey does for you, including every specifier. It also shows the real point: the number and the words travel separately, so each language can put them where it wants.

Why use one entry with {Seconds:int} instead of building the sentence in code and translating the pieces?

  1. Languages order words differently, so the translator must control where the number goes
  2. Parameters make the text load faster
  3. Roblox cannot translate numbers
  4. It saves a Luau variable
Answer

Languages order words differently, so the translator must control where the number goes. If code glues translated fragments together, it hard-codes English word order. A whole sentence with a slot lets each language place the number correctly.

Open this step in lesson mode · Link to this step · This confused me

5Where the phrasebook picture breaks

Client sideRemember: The localization table is a phrasebook with a key on every line.

A phrasebook only has sentences someone wrote down. A game builds sentences while it runs.

Where does it break?“A phrasebook with a key on every line” is a good picture of the localization table. Where does it stop being true?

It breaks here. A phrasebook only holds sentences someone wrote in advance, but a game builds sentences while it runs, such as a countdown with a changing number, a player's name or text a player types, none of which are lines in the book.

The true model. The table holds the strings you know ahead of time. Dynamic text uses a parameter slot in one entry so each language can place the value. Text players write or names should not go through the table; a real-time translation API exists for generated text and is in early development.

So a finished string like Next drill in 7s is not in the book, and neither is player-written text or a name. Free text needs a different tool: the real-time translation API, an Open Cloud call that translates a string on demand. The documentation marks it as early in development and subject to change5.

Which of these can a localization table handle well?

  1. The fixed sentence Go to the beacon and hold E to start the drill
  2. A message a player types into a sign
  3. A player's display name
  4. Every possible countdown string such as Next drill in 7s
Answer

The fixed sentence Go to the beacon and hold E to start the drill. Fixed sentences fit. Countdowns need a parameter, and player text and names should not be translated through the table at all.

Open this step in lesson mode · Link to this step · This confused me

6Translate in code

For text a script sets, ask for a Translator. LocalizationService:GetTranslatorForPlayerAsync(player) yields and can fail, so wrap it in pcall and keep an English fallback6:

luau
local LocalizationService = game:GetService("LocalizationService")
local Players = game:GetService("Players")
 
local ok, translator = pcall(function()
	return LocalizationService:GetTranslatorForPlayerAsync(Players.LocalPlayer)
end)
 
local function nextDrillText(seconds: number): string
	local whole = math.max(0, math.ceil(seconds))
	local english = string.format("Next drill in %ds", whole)
	if not ok then
		return english
	end
	local good, text = pcall(function()
		return translator:FormatByKey("Hud_NextDrill", { Seconds = whole })
	end)
	return if good then text else english
end

Two more details. FormatByKey throws when the key is missing, so it needs its own pcall too. And when a player changes language mid-game, a script that cached the translator should listen to the translator's LocaleId change and redraw6.

This HUD code can break the whole HUD for one player. Which line is the risk?

local translator = LocalizationService:GetTranslatorForPlayerAsync(Players.LocalPlayer)
local function label(seconds)
	return translator:FormatByKey("Hud_NextDrill", { Seconds = seconds })
end
objective.Text = label(5)
Answer

Line 1: local translator = LocalizationService:GetTranslatorForPlayerAsync(Players.LocalPlayer). Fixed: local ok, translator = pcall(function() return LocalizationService:GetTranslatorForPlayerAsync(Players.LocalPlayer) end). GetTranslatorForPlayerAsync can fail, and without pcall the error stops the script. FormatByKey also needs a pcall and a fallback, but the first unprotected call is the first thing to break.

Open this step in lesson mode · Link to this step · This confused me

7Test a language without leaving Studio

You do not have to change your Roblox account language to see a translation. Studio's Player Emulator (Test menu, then turn on Enable Test Profile) has three options for this7:

  • Locale emulates a language while you playtest.
  • Pseudolocalize swaps letters for look-alikes, so Bloxy Cola becomes something like ßℓôж¥ Çôℓá. Any text that stays plain English is not going through the translation system.
  • Elongate lengthens strings by a percentage you choose, to show where a longer translation will overflow a button.
Roblox Studio
Studio's Player Emulator window opened from the Test menu with Enable Test Profile on, showing the Locale, Pseudolocalize and Elongate options.

Select a numbered pin, or a row below, to read what it marks.

Figure 7.1.

The Player Emulator with the test profile on.

Build along

m06-drone-wrench

  • src/client/Hud.luau
  • src/client/ShopGui.luau
  1. Open the Player Emulator from the Test menu and turn on Enable Test Profile.

    You should see Output and the HUD look the same as before; Enable Test Profile shows as on.

  2. Turn on Pseudolocalize and press Play.

    You should see The HUD labels and shop buttons now show look-alike letters. Any label still in plain English is not being translated.

  3. Turn Pseudolocalize off, set Elongate to 50 percent, and press Play again.

    You should see Shop buttons such as Speed or Shield, and the objective sentence, get longer. Note which ones clip or wrap badly.

  4. Add one French entry for the Idle phase and choose French (fr-fr) as the emulated Locale. For a published game, add the row under Creator Hub, your game, Audience, Localization; to test locally in Studio without touching the cloud table, insert a LocalizationTable under LocalizationService in Explorer and add a row with Source Idle and French translation En attente.

    You should see With a French translation entered for Idle, picking French (fr-fr) in Locale shows it in the HUD.

Roblox Studio
Beacon Yard in Play with Pseudolocalize on: the Quartermaster shop title and buttons show look-alike letters, while the HUD at the top left still reads plain English Coins, Idle and the objective sentence.

Select a numbered pin, or a row below, to read what it marks.

Figure 7.2.

With Pseudolocalize on, translated labels change. The plain English HUD text is not going through the translation system.

With Pseudolocalize on, the shop title shows look-alike letters, but the Coins label still reads plain Coins. What does that tell you?

  1. The Coins label is not going through the translation system, perhaps because it is set in a way capture misses
  2. The Coins label is already perfect
  3. The shop title is broken
  4. Pseudolocalize only works on titles
Answer

The Coins label is not going through the translation system, perhaps because it is set in a way capture misses. Text that stays plain English is not being localized. Check its AutoLocalize property and how the script sets it.

Open this step in lesson mode · Link to this step · This confused me

8How studios localize

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
Automatic text capture and translationRoblox collects strings and machine-translates blank entries.Early on, small teams, and long-tail languages.Quality varies, monthly quotas apply, and it misses dynamic and player text.
Manual translations in the tableYou or translators add entries in the Translator Portal or by CSV upload.Your top languages and anything with tone, jokes or brand terms.Slower and costs money or time; always shown to players.
Work with translatorsInvite native speakers as collaborators on the localization table.Languages that matter to your audience.Needs briefs, context notes and review.
Real-time translation APIAn Open Cloud call that translates a string on demand.Player-written or generated text, if you accept the preview status.Early in development and subject to change; needs a server round trip.

Order the localization work for a new game.

  1. Replace machine translations in your top languages with human ones
  2. Turn on automatic capture and translation for a few languages
  3. Check the layout with Pseudolocalize and Elongate
  4. Move HUD strings into keys, with parameters for numbers
Answer

1. Move HUD strings into keys, with parameters for numbers 2. Check the layout with Pseudolocalize and Elongate 3. Turn on automatic capture and translation for a few languages 4. Replace machine translations in your top languages with human ones. Fix the strings first, test the layout cheaply, let automation provide a first draft, then spend human effort where players are.

Open this step in lesson mode · Link to this step · This confused me

9Challenges

Level 1, Apprentice

Challenge

List what a translator would have to handle in the HUD and the shop.

Start from
The game at milestone m06 (download)

Done means

  • A list of every English string the HUD and shop create
  • Each marked as a fixed sentence, a parameter string, or data only

Hints

  1. Search Hud.luau and ShopGui.luau for quotation marks and string.format.
  2. Names and numbers are data.

Level 2, Builder

Challenge

Run both emulator tests on the shop and write up what broke.

Start from
The game at milestone m06 (download)

Done means

  • A screenshot or note for each of Pseudolocalize and Elongate at 50 percent
  • A list of every label that stayed English or clipped

Hints

  1. Use the BuildAlong above.
  2. Check the shop buttons: they combine a name and a price.

Why test with Elongate before you have a single translation?

  1. Translations are often longer than English, so you find clipped buttons early
  2. Elongate translates the text for you
  3. It lowers the translation quota
  4. It makes the HUD load faster
Answer

Translations are often longer than English, so you find clipped buttons early. Elongate stretches strings to imitate longer translations, so layout problems show up before translators are involved.

Level 3, Professional

Challenge

Start from the m14-ship tag in the game repo, then make the countdown translatable in challenges/localization_work.luau. The test uses a fake translator, so no published table is needed.

Press Play and run this in the server command bar:

luau
game.ServerScriptService.RunGameTests:Invoke("localization")
Start from
The game at milestone m14 (download)
Grade it
In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("localization") in the server command bar. Copy the pass code from Output.

Done means

  • nextDrillText asks the translator for Hud_NextDrill with a Seconds parameter rounded up
  • It falls back to the English line with no translator, and when FormatByKey throws
  • A late tick shows 0, never a negative number
  • challenges/localization.luau prints TEST PASS for all seven cases

Hints

  1. Round up with math.ceil before you pass the value.
  2. Wrap the FormatByKey call in pcall and return the English line on failure.

Open this step in lesson mode · Link to this step · This confused me

10Recap

Retiring the analogy

You no longer need “a phrasebook with a key on every line”. The table holds the strings you know ahead of time. Dynamic text uses a parameter slot in one entry so each language can place the value. Text players write or names should not go through the table; a real-time translation API exists for generated text and is in early development.

Recap

  1. The localization table has a row per string: Source, optional Context and Key, and Location from capture.
  2. Automatic capture and translation give a quick first draft; human translations always win, quotas apply per character and language.
  3. Use parameters for dynamic text, pcall every translator call, and test with Locale, Pseudolocalize and Elongate.

The localization table is a phrasebook with a key on every line, until a phrasebook only holds sentences someone wrote in advance, but a game builds sentences while it runs, such as a countdown with a changing number, a player's name or text a player types, none of which are lines in the book.

Next LiveOps: updates, events, feature flags, migrations

Open this step in lesson mode · Link to this step · This confused me