Skip to content

Localization

Use loc to put the texts of a screen into a String Table. The game can then change language without a second set of documents.

The Localization sample has a panel whose texts come from a String Table and change language in place. Two buttons ("English", "Polski") switch the culture. The title, the sentences, the labels and the "Add a coin" button change at once, and the plain line never does. "Add a coin" counts up, and the count picks its plural form for the current language: "1 coin", "2 coins" in English, "1 moneta", "2 monety", "5 monet" in Polish. Run it by choosing Localization in the samples list in the map L_ArcRmlSamples (Samples).

The Localization sample in English: welcome text, the plain line, a purse of 1 coin with Add a coin, the culture en and English and Polski buttons

loc

loc="Key" on an element that holds plain text makes the text the entry Key of the document's String Table. The text written in the .rml is the source (English) text. A key is made of A-Z, a-z, 0-9, _, . and -.

Localization.rml
<h1 class="lc-title" loc="Title">Localization</h1>
<p class="lc-text" loc="Welcome">Welcome, traveler!</p>
<p class="lc-plain">Plain text without loc stays as written.</p>
<button id="lc-add" class="lc-button" loc="AddCoin" on:click="call('loc', 'AddCoin')">Add a coin</button>
  • The table is one per .rml file: <folder>/Loc/ST_<Name> beside the file, here Loc/ST_Localization. Only UStringTable assets named ST_* in a Loc folder under a content root are loaded.
  • A text without loc is shown as written in every culture.
  • On a component, put loc-<prop> on its dc-import instead of loc, which is an error there (Components). <dc-import name="/Game/UI/Rml/Components/Card" loc-title="CardTitle"/> takes the text of the prop title from the entry CardTitle in the table of the importing file. A loc inside the component uses the component's own table.
  • A key with no entry shows the key and warns once; the validator reports it as missing-loc-key.

Plurals

{{ n | arcplural('Key') }} takes the entry Key of the same table, which holds the forms. The entry is String Table text, not RML:

Localization.rml
<span id="lc-coins" class="lc-value">{{ loc.Coins | arcplural('Coins') }}</span>
String Table entry Coins
{0}|plural(one={0} coin,other={0} coins)

The forms are zero, one, two, few, many and other; other is required, and the form the current language picks must exist. {0} is the number. The Polish entry adds few and many. You edit the entry in the String Table itself; Sync Strings only checks it.

The culture switch

Localization/ArcRmlSamplesLocalization.cpp
void UArcRmlSamplesLocalizationViewModel::SwitchCulture(const FString& Name)
{
    if (!FInternationalization::Get().SetCurrentCulture(Name))
    {
        UE_LOGF(LogArcRmlSamples, Warning, "ArcRmlSamples: culture '%ls' does not exist in this build", *Name);
    }
}

call('loc', 'SwitchCulture', 'pl') calls it. ArcRmlUI translates every open document again in place; no document is reopened, so focus, scroll and the count stay. The engine console command culture=pl does the same. The sample's view model also listens to FInternationalization::Get().OnCultureChanged(), so the {{ Culture }} readout follows a change from anywhere.

Edit the texts

  1. Change the text in Localization.rml, then right-click the file (or its folder) in the Content Browser and choose Sync Strings. It adds new keys to ST_Localization and updates changed texts; a folder syncs every .rml under it. Nothing is ever removed from a table. From editor Python the same function is unreal.ArcRmlStringSyncLibrary.sync_strings([...]), which takes the package path of each document and returns the errors as <path>(<line>): <message>.
  2. Gather, translate and compile with the project's Game localization target. The String Table is a content asset, so the target can gather it. Open Tools > Localization Dashboard, select the Game target and, in its settings, enable Gather from Packages and add an include path that covers your documents (the default Game target gathers no packages). Click Gather Text, translate the texts (the edit-translations button in the culture's row, or the exported .po file), then click Compile Text.

The dashboard lists only the Game and Engine targets, not a plugin's LocalizationTargets. For the samples' plugin target, run this from the project folder instead (where UnrealEditor-Cmd.exe is):

UnrealEditor-Cmd.exe "<Project>.uproject" -run=GatherText -config=Plugins/ArcRmlUISamples/Config/Localization/ArcRmlUISamples.ini

It exports Content/Localization/ArcRmlUISamples/<culture>/ArcRmlUISamples.po. Write the translations as the msgstr lines of pl/ArcRmlUISamples.po and run the same command again: it imports the .po and compiles Content/Localization/ArcRmlUISamples/<culture>/ArcRmlUISamples.locres.

Packaging

A packaged game ships only the cultures listed in the project's packaging settings. In Config/DefaultGame.ini:

[/Script/UnrealEd.ProjectPackagingSettings]
+CulturesToStage=pl

Limits

  • Only the whole text of an element is localized: a loc element holds no child element and no {{ }}, or the compile fails. A text in an attribute (a tooltip, a placeholder) cannot be localized; it stays as written.
  • Sync Strings never writes an arcplural entry; a missing or bad one is an error in its report.