Stringtable.xml: Difference between revisions
m (side toc) |
Lou Montana (talk | contribs) (Page refresh) |
||
Line 1: | Line 1: | ||
{{SideTOC}} | {{SideTOC}} | ||
{{Informative | [[Stringtable.xml]] was introduced with {{arma}}. For {{ofp}}, see [[Stringtable.csv]].}} | |||
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 is being read depending on the game settings. | |||
== Stringtable Editors == | == Stringtable Editors == | ||
It strongly recommended to use a tool to edit the XML file; a selection of Stringtable [[:Category:Community Tools|Community Tools]] can be found in the [[:Category:Community Tools#Localisation Tools|Community Tools - Localisation Tools]] page section. | |||
== Example == | |||
== | <syntaxhighlight lang="xml"></syntaxhighlight><!-- so the syntaxhighlight works in the spoiler tag --> | ||
<syntaxhighlight lang=" | <spoiler text="Show Stringtable.xml example"> | ||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0" encoding="utf-8" ?> | <?xml version="1.0" encoding="utf-8" ?> | ||
<Project name="Any Name"> | <Project name="Any Name"> | ||
<Package name="Mission One"> | <Package name="Mission One"> | ||
<Container name="Some Words"> | <Container name="Some Words"> | ||
<Key ID=" | <Key ID="str_TAG_Yes"> | ||
<Original>yes</Original> | <Original>yes</Original> | ||
<English>yes</English> | <English>yes</English> | ||
Line 38: | Line 36: | ||
<Chinese>是(繁體)</Chinese> | <Chinese>是(繁體)</Chinese> | ||
</Key> | </Key> | ||
<Key ID=" | <Key ID="str_TAG_No"> | ||
<Original>no</Original> | <Original>no</Original> | ||
</Key> | </Key> | ||
</Container> | </Container> | ||
<Container name="Another Container"> | <Container name="Another Container"> | ||
<Key ID=" | <Key ID="str_TAG_formatted"> | ||
<Original>Hello, %1.</Original> | <Original>Hello, %1.</Original> | ||
</Key> | </Key> | ||
<Key ID=" | <Key ID="str_TAG_structuredText"> | ||
<Original>Some text & | <Original>Some text <t color='%1'>%2</t></Original> | ||
</Key> | </Key> | ||
</Container> | </Container> | ||
Line 80: | Line 51: | ||
</Project> | </Project> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</spoiler> | |||
{{Informative | Package and container names are only for organisational use; use them for your own sanity.}} | |||
{{Important | [[Stringtable.xml]] must be saved with '''UTF-8 Encoding''' for international characters to display and save correctly.}} | |||
[[ | |||
== Supported languages == | == Supported languages == | ||
= | {| class="wikitable" | ||
! {{arma2}} & {{arma2oa}} !! {{arma3}} | |||
|- | |||
| style="vertical-align: top" | | |||
* English | |||
* Czech | |||
* French | |||
* Spanish | |||
* Italian | |||
* Polish | |||
* Russian | |||
* German | |||
| | |||
<div style="column-count: 3"> | |||
* English | * English | ||
* Czech | * Czech | ||
Line 139: | Line 96: | ||
* Finnish | * Finnish | ||
* Dutch | * Dutch | ||
</div> | |||
|} | |||
== Key naming convention == | |||
{{Informative | Same as [[Identifier#Recommendations|global variables]], it is recommended to use a '''{{Color|purple|TAG}}''' to prevent translation collision with mods.}} | |||
If the key is to be used by [[Config]] ([[Description.ext]] and dialogs included), it '''must''' start with <tt>STR</tt> (or <tt>str</tt>, casing does not matter). '''By convention''' however, <tt>STR_</tt> is the norm for all the entries. | |||
== String Formats == | |||
Strings stored in the stringtable can be in the following formats: | |||
* Normal text, such as <tt>Hello there</tt> | |||
* [[format]] text, such as <tt>Hello %1</tt> | |||
* [[Structured Text]], such as <tt><t size='2'>Hello</t> there</tt>, '''but''':<br><!-- | |||
-->{{Important | The HTML tag characters <tt><</tt> and <tt>></tt> must respectively be encoded as <tt>&lt;</tt> and <tt>&gt;</tt>.}}<!-- | |||
--><tt><t size='2'>Hello</t> there</tt> would then become <tt>&lt;t size='2'&gt;Hello&lt;/t&gt; there</tt>. | |||
== Usage == | |||
=== Script === | |||
A translation can be retrieved and used in a script by using the [[localize]] command: | |||
[[hint]] [[localize]] "str_TAG_Yes"; {{cc|returns "Yes" in English, "Oui" in French, etc.}} | |||
[[hint]] [[format]] [<nowiki/>[[localize]] "str_TAG_formatted", [[name]] [[player]]]; | |||
[[hint]] [[localize]] "str_TAG_structuredText"; | |||
=== Config === | |||
Whether it is in [[Description.ext]], [[Campaign Description.ext]], Dialogs etc., the [[Config]] syntax to refer to a Stringtable translation is as follow (here, a [[Description.ext]] example): | |||
==== | <syntaxhighlight lang="cpp"> | ||
onLoadName = $STR_TAG_missionName; | |||
onLoadMission = $STR_TAG_loadMissionText; | |||
overviewText = $STR_TAG_overviewText; | |||
overviewPicture = $STR_TAG_overviewImage; | |||
</syntaxhighlight> | |||
< | The preprocessor will replace <tt>$STR</tt> entries with the Stringtable values. | ||
==== | == Multiplayer == | ||
[[Multiplayer Scripting]] should consider that the translation implementation ''should'' ideally happen client-side; clients and server are likely to be configured in a different language, as a server-side call to [[:Category:Commands with global effects|global effect]] text commands (such as [[setMarkerText]]) would set the text in the server's language to everyone. | |||
Example of client-side translation of a server message: | |||
= | {{cc|Server-side}} | ||
[[if]] ([[isServer]]) [[then]] | |||
{ | |||
[<nowiki/>[[nil]], [[nil]], rHINT, [[localize]] "str_TAG_myMessage"] [[call]] [[RE]]; {{cc|{{arma2}}}} | |||
["str_TAG_myMessage"] [[remoteExecCall]] ["TAG_fnc_localHint"]; {{cc|{{arma3}}}} | |||
}; | |||
{{cc|Client-side executed function}} | |||
TAG_fnc_localHint = { | |||
[[if]] ([[hasInterface]]) [[then]] | |||
{ | |||
[[hintSilent]] [[parseText]] ([[localize]] [[_this]]); {{cc|{{arma2}}}} | |||
[[hintSilent]] [[parseText]] ([[_this]] [[call]] [[BIS_fnc_localize]]); {{cc|{{arma3}}}} | |||
}; | |||
}; | |||
== See also == | |||
* localize | |||
* isLocalized | |||
* [[BIS_fnc_localize]] (since {{arma3}}) | |||
[[Category: | [[Category:BIS File Formats]] | ||
[[Category:Arma 3: Editing]] | [[Category:Arma 3: Editing]] |
Revision as of 21:10, 24 April 2020
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 is being read depending on the game settings.
Stringtable Editors
It strongly recommended to use a tool to edit the XML file; a selection of Stringtable Community Tools can be found in the Community Tools - Localisation Tools page section.
Example
<?xml version="1.0" encoding="utf-8" ?>
<Project name="Any Name">
<Package name="Mission One">
<Container name="Some Words">
<Key ID="str_TAG_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>
<Chinesesimp>是</Chinesesimp>
<Chinese>是(繁體)</Chinese>
</Key>
<Key ID="str_TAG_No">
<Original>no</Original>
</Key>
</Container>
<Container name="Another Container">
<Key ID="str_TAG_formatted">
<Original>Hello, %1.</Original>
</Key>
<Key ID="str_TAG_structuredText">
<Original>Some text <t color='%1'>%2</t></Original>
</Key>
</Container>
</Package>
</Project>
Supported languages
Arma 2 & Arma 2: Operation Arrowhead | Arma 3 |
---|---|
|
|
Key naming convention
If the key is to be used by Config (Description.ext and dialogs included), it must start with STR (or str, casing does not matter). By convention however, STR_ is the norm for all the entries.
String Formats
Strings stored in the stringtable can be in the following formats:
- Normal text, such as Hello there
- format text, such as Hello %1
- Structured Text, such as <t size='2'>Hello</t> there, but:
<t size='2'>Hello</t> there would then become <t size='2'>Hello</t> there.
Usage
Script
A translation can be retrieved and used in a script by using the localize command:
hint localize "str_TAG_Yes"; // returns "Yes" in English, "Oui" in French, etc. hint format [localize "str_TAG_formatted", name player]; hint localize "str_TAG_structuredText";
Config
Whether it is in Description.ext, Campaign Description.ext, Dialogs etc., the Config syntax to refer to a Stringtable translation is as follow (here, a Description.ext example):
onLoadName = $STR_TAG_missionName;
onLoadMission = $STR_TAG_loadMissionText;
overviewText = $STR_TAG_overviewText;
overviewPicture = $STR_TAG_overviewImage;
The preprocessor will replace $STR entries with the Stringtable values.
Multiplayer
Multiplayer Scripting should consider that the translation implementation should ideally happen client-side; clients and server are likely to be configured in a different language, as a server-side call to global effect text commands (such as setMarkerText) would set the text in the server's language to everyone.
Example of client-side translation of a server message:
// Server-side if (isServer) then { [nil, nil, rHINT, localize "str_TAG_myMessage"] call RE; // Arma 2 ["str_TAG_myMessage"] remoteExecCall ["TAG_fnc_localHint"]; // Arma 3 }; // Client-side executed function TAG_fnc_localHint = { if (hasInterface) then { hintSilent parseText (localize _this); // Arma 2 hintSilent parseText (_this call BIS_fnc_localize); // Arma 3 }; };
See also
- localize
- isLocalized
- BIS_fnc_localize (since Arma 3)