Stringtable.xml
Stringtable.xml
String tables are used to make internationalization easier for the game. They are used in addons, missions, and scripts, and are located in the root of the mission or addon folders.
Any strings that are used in the game can be kept separate from the code, and can therefore easily be edited and expanded into different languages. Instead of using strings directly in the code, you are using a variable. This variable will then contain the actual string, read from stringtable.xml, with the language that's being read depending on the game settings.
Example Format:
<?xml version="1.0" encoding="utf-8" ?>
<Project name="Any Name">
<Package name="Mission One">
<Container name="Some Words">
<Key ID="str_myTag_Yes">
<Original>yes</Original>
<English>yes</English>
<Czech>ano</Czech>
<French>oui</French>
<German>ja</German>
<Italian>sì</Italian>
<Polish>tak</Polish>
<Portuguese>sim</Portuguese>
<Russian>да</Russian>
<Spanish>sí</Spanish>
<Korean>네</Korean>
<Japanese>はい</Japanese>
</Key>
<Key ID="str_myTag_No">
<Original>no</Original>
</Key>
</Container>
<Container name="Another Container">
<Key ID="str_myTag_another_key">
<Original></Original>
</Key>
<Key ID="str_myTag_formatted">
<Original>Hello, %1.</Original>
</Key>
<Key ID="str_myTag_structured">
<Original>Some text &lt;t color='%1'&gt;%2&lt;/t&gt;</Original>
</Key>
</Container>
</Package>
</Project>
- Replace myTag in str_myTag_someKey with your OFPEC tag or other means of personal identification so other addon and mission string names won't collide, potentially breaking your mission - this is just good practice
- Package and container names appear to only be for organizational use; use them for your own sanity
Naming Key IDs
If you are planning to use your stringtable.xml with scripts only, there are no rules in regards to naming format of Key IDs. localize and isLocalized will work with any name, as long as it matches Key ID name in stringtable.xml. For example:
// stringtable.xml
<?xml version="1.0" encoding="utf-8" ?>
<Project name="Any Name">
<Package name="Mission One">
<Container name="Some Words">
<Key ID="myCrazyNameTag">
<Original>wuga wuga</Original>
</Key>
</Container>
</Package>
</Project>
// some script
hint str isLocalized "myCrazyNameTag"; // true;
hint str localize "myCrazyNameTag"; // "wuga wuga";
However, if you are also going to use stringtable.xml with configs, you must use special prefix $STR (dollar sign $ followed by uppercase STR) to reference Key ID in config. The Key IDs in stringtable.xml will have to start with "str" or "STR" accordingly, case doesn't matter here. For example:
// stringtable.xml
<?xml version="1.0" encoding="utf-8" ?>
<Project name="Any Name">
<Package name="Mission One">
<Container name="Some Words">
<Key ID="STRblahblah">
<Original>blah</Original>
</Key>
</Container>
</Package>
</Project>
// some config
class Test
{
word = $STRblahblah;
};
hint str getText (configFile >> "Test" >> "word"); // "blah"
By convention, an underscore _ is added to the prefix STR_ ($STR_). It provides clarity and makes stringtable.xml universally compatible with both scripts and configs.
Usage
Scripts
A string from stringtable.xml can be retrieved and used in a script by using the localize command:
hint ( localize "str_myTag_Yes" );
"Marker1" setMarkerTextLocal localize "str_myTag_SiezeTheTown";
hint format [ localize "str_myTag_formatted", "Dave" ]; // "Hello, Dave."
// str_myTag_formatted: <Original>Hello, %1.</Original>
The stringtable can also hold Structured Text xml tags, if the tag characters < > are encoded as < <
and > >
see: HTML Entities
hint parseText format [ localize "str_myTag_structured", "#FF0000", "with Color!" ]; //show 'with Color!' in Red
// str_myTag_structured: <English>Some text <t color='%1'>%2</t></English>
// after format & parseText: Some text <t color='#FF0000'>with Color!</t>
Description.ext
Stringtable values can be used in the Description.ext config by typing the key as such, $STR_myTag_keyName
, and without quotation marks; these will be replaced by the preprocessor:
onLoadName = $STR_myTag_missionName;
onLoadMission = $STR_myTag_loadMissionText;
overviewText = $STR_myTag_overviewText;
overviewPicture = $STR_myTag_overviewImage;
Dialogs
As with Description.ext, the preprocessor will replace the values in configs as long as the key name is formatted correctly (see above) :
class RscText_1012: RscText
{
idc = 1012;
text = $STR_myTag_someLabelText;
tooltip = $STR_myTag_someTip;
...
CfgRadio
Stringtables can also be used for sounds and radio sentences in CfgRadio, also residing in Description.ext:
class CfgRadio
{
sounds[] = {};
class RadioMsg1
{
name = "";
sound[] = {$STR_myTag_sound_RadioMsg1, db-100, 1.0};
title = $STR_myTag_RadioMsg1;
};
};
// str_myTag_sound_RadioMsg1: <English>\sound\radiomsg1_en.ogg</English>
// <Czech>\sound\radiomsg1_cz.ogg</Czech>
// str_myTag_RadioMsg1: <English>I am ready for your orders.</English>
Multiplayer
A string name could be passed to all clients for localized display:
str_myTag_teamKillers: <English><t color='#dd1111'>Team Killing is NOT Tolerated</t></ br> and will result in a Permanent Ban!</English>
// Server
if ( isServer ) then {
["str_myTag_teamKillers","TAG_fnc_localHint"] call BIS_fnc_MP;
};
// Clients
TAG_fnc_localHint = {
if ( ! isDedicated ) then {
hintSilent parseText (localize _this);
};
};
Languages
- Arma 3
- English, Czech, French, Spanish, Italian, Polish, Portuguese, Russian, German, Korean**, Japanese** (**region exclusive)
- Arma 2 OA
- English, Czech, French, Spanish, Italian