PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Localization Format Strings

Localization Format Strings

Mar 15 2019, 8:38 PM PST 5 min

If a string needs to update in real-time during gameplay, such as when displaying player names or working with a timer, format strings can be used as placeholders within localized translations.

Displaying an amount of in-game items.
Showing a player's Roblox username in a message.
Displaying a high score using localized separators.

Constructing Format Strings

Format strings consist of a parameter and an optional format specifier for the target value. If no format specifier is included, the value will be displayed exactly as given.

{NumJewels : int}
Parameter
Optional format specifier (integer format)

Parameters can be either named or numbered. All parameters for a single entry must use the same style and can’t be a mix of named and numbered.

${1:fixed} cash and {2:int} jewels
${AmountCash:fixed} cash and {NumJewels:int} jewels
${1:fixed} cash and {NumJewels:int} jewels

Specifier Reference

As stated above, the optional format specifier controls how a value is formatted, such as if it’s a string, a timestamp, or an integer. The following table lists each specifier and its intended purpose.

Specifier Type Description Example Output
int number Integer with optional negative sign; no thousand separators. 1234
fixed number Two decimals with decimal indicator, optional negative sign, and no thousand separators. 1234.50
num number Two decimals with decimal indicator, optional negative sign, and thousand separators. 1,234.50
1 234,50
HEX number Integer converted to hex; negative is converted to 64-bit two's complement. 3FF
hex number Same as HEX, but lowercase. 3ff
datetime number UTC timestamp as a number to universal user-readable format. 2017-10-10 13:38:10
iso8601 number UTC timestamp as a number to ISO-8601 format UTC time. 2017-10-12T22:02:38Z
shorttime number UTC timestamp to local "hour:minute" format. 1:45 PM
13:45
shortdatetime number UTC timestamp to general date+time pattern with short time. 10/10/2017 1:45 PM
shortdate number UTC timestamp to short date pattern. 10/10/2017
2017-10-10
translate string Attempts to translate the argument before concatenating (in the same context). This will only look for a literal Source match — it does not support recursive matching.

Specifier Examples

Source String Example Input English Output
${1} cash $1000 cash $1000 cash
Hello {user}! Hello new_storm! Hello new_storm!
{race_time:fixed} seconds 75.202844 seconds 75.20 seconds
${1:num} cash and {2:int} jewels $2500.5 cash and 99.8 jewels $2,500.50 cash and 100 jewels

Test Implementation

Consider the practical example of displaying a variable amount of jewels across multiple languages. To implement this in a game:

  1. Download the .csv spreadsheet from the localization portal as outlined articles/localization portal additional features#localizing-with-csv-files|here.
  2. Insert a Source string with a named format string, along with translations for supported languages like es (Spanish) and pt (Portuguese).
C D E F G
Source Example es pt
{NumJewels} jewels {NumJewels} joyas {NumJewels} jóias
 
  1. Add a GUI object to your game, for example a TextLabel with a TextLabel/Text|Text property of 100 jewels.
  1. Upload the spreadsheet and playtest the game as outlined articles/localization portal additional features#upload-csv-file|here. The translations should appear on the in-game GUI instance, including the variable 100.
English
Spanish
Portuguese
Tags:
  • localization
  • language
  • translation
  • international
  • format