localize: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (added version to return value)
m (Some wiki formatting)
 
(29 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{RV|type=command
{{RV|type=command


| ofp
|game1= ofp
|version1= 1.00


|1.00
|game2= ofpe
|version2= 1.00
 
|game3= arma1
|version3= 1.00
 
|game4= arma2
|version4= 1.00
 
|game5= arma2oa
|version5= 1.50
 
|game6= tkoh
|version6= 1.00
 
|game7= arma3
|version7= 0.50


|gr1= Strings
|gr1= Strings


| Used to internationalize text messages. A string is returned from [[Stringtable.csv]] (or [[Stringtable.xml]]) which corresponds to the ''stringName''.<br>
|gr2= Localization
If the key couldn't be found, for example <tt>"STR_DN_SNAKE"</tt>, string {{Inline code|"Missing string 'STR_DN_SNAKE'"}} is returned and an entry is added to .rpt file, for example <tt>String STR_DN_SNAKE not found</tt>.
 
|descr= Used to internationalise text messages. The provided translation key is looked up in [[Stringtable.xml]] (or [[Stringtable.csv]]).
 
|s1= [[localize]] stringName


{{Informative | Since Arma 3 v2.03.147217, [[localize]] accepts <tt>"$IDS<number>"</tt> and <tt>"$STR<name>"</tt> localization template formats. For example:
|p1= stringName: [[String]] - string which leads to localisation. Casing does not matter. {{GVI|arma3|2.04|size= 0.75}} A string starting with "$" is supported
<code>[[localize]] "$IDS123"; //"Action"</code>
 
<code>[[localize]] "$STR_WEST"; //"BLUFOR"</code>
|r1= [[String]] - text found in corresponding entry in stringtable file. If the key could not be found an empty string {{hl|""}} is returned and an entry is added to .rpt file, for example {{hl|String STR_DN_SNAKE not found}}
}}


| [[localize]] stringName
|x1= <sqf>
hint localize "STR_West"; // returns "BLUFOR"
hint localize "STR_WEST"; // returns "BLUFOR"
hint localize "STR_weSt"; // returns "BLUFOR"
hint localize "STR_NonExistentString"; // returns "" and logs "String STR_NonExistentString not found"
</sqf>


|p1= stringName: [[String]]
|x2= <sqf>hint format ["Go %1", localize "STR_Q_NORTH"]; // returns "Go North"</sqf>


| [[String]]
|x3= <sqf>
* {{Since|arma3|2.03.147217}}: text found in corresponding entry in stringtable file or missing string message (see description)
hint format
* ''before {{arma3}} v2.03.147217'': empty string is returned if key could not be found
[
localize "STR_ACTION_DROP_WEAPON", // "STR_ACTION_DROP_WEAPON" contains "Drop %1"
localize "STR_SN_RIFLE" // "STR_SN_RIFLE" contains "Rifle"
]; // returns "Drop Rifle"
</sqf>


 
|x4= <sqf>localize "$STR_USRACT_ADJUST"; // returns "Adjust" since Arma 3 v2.04</sqf>
|x1= <code>[[hint]] [[localize]] "STR_WEST"; {{codecomment|// -> "BLUFOR" (in Arma2)}}</code>
|x2= <code>[[hint]] [[format]] ["Go %1", [[localize]] "STR_Q_NORTH"]; {{codecomment|// -> "Go North"}}</code>
|x3= <code>{{codecomment|// STR_ACTION_DROP_WEAPON contains "Drop %1"
// STR_SN_RIFLE contains "Rifle"}}
[[hint]] [[format]] [<nowiki/>[[localize]] "STR_ACTION_DROP_WEAPON", [[localize]] "STR_SN_RIFLE"]; {{codecomment|// -> "Drop Rifle"}}</code>


| [[isLocalized]], [[getTextRaw]], [[BIS_fnc_localize]], [[WFSideText]], [[parseText]], [[Stringtable.csv]], [[Stringtable.xml]]
|seealso= [[isLocalized]] [[diag_localized]] [[getTextRaw]] [[BIS_fnc_localize]] [[WFSideText]] [[parseText]] [[Stringtable.csv]] [[Stringtable.xml]]
}}
}}


[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
{{Note
[[Category:Scripting Commands OFP 1.46|{{uc:{{PAGENAME}}}}]]
|user= Killzone_Kid
[[Category:Scripting Commands OFP 1.96|{{uc:{{PAGENAME}}}}]]
|timestamp= 20140912115500
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
|text= The command [[localize]] will strip all HTML tags from your [[Stringtable.xml]] entries, however there is a way to trick it by substituting tags with HTML code instead:
{{GameCategory|arma1|Scripting Commands}}
<syntaxhighlight lang="xml">
{{GameCategory|arma2|Scripting Commands}}
<?xml version="1.0" encoding="utf-8"?>
{{GameCategory|arma3|Scripting Commands}}
{{GameCategory|tkoh|Scripting Commands}}
 
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on September 12, 2014 - 11:55 (UTC)</dd>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
The command [[localize]] will strip all HTML tags from your ''stringtable.xml'' entries, however there is a way to trick it by substituting tags with HTML code instead:
<syntaxhighlight lang="xml"><?xml version="1.0" encoding="utf-8"?>
<Key ID="STR_TEST_KK">
<Key ID="STR_TEST_KK">
<Original><![CDATA[<t color='#ff0000'>This doesn't work</t>]]></Original>
<Original><![CDATA[<t color='#ff0000'>This doesn't work</t>]]></Original>
Line 54: Line 67:
<Key ID="STR_TEST_KK2">
<Key ID="STR_TEST_KK2">
<Original>&lt;t color='#ff0000'&gt;This works&lt;/t&gt;</Original>
<Original>&lt;t color='#ff0000'&gt;This works&lt;/t&gt;</Original>
</Key></syntaxhighlight>
</Key>
<code>[[hint]] [[parseText]] [[localize]] "str_test_kk"; {{codecomment|// no change of colour}}</code>
</syntaxhighlight>
<code>[[hint]] [[parseText]] [[localize]] "str_test_kk2"; {{codecomment|// hint content is in red}}</code>
<sqf>
</dd>
hint parseText localize "str_test_kk"; // no change of colour
</dl>
hint parseText localize "str_test_kk2"; // hint content is in red
<!-- DISCONTINUE Notes -->
</sqf>
}}

Latest revision as of 14:39, 30 April 2023

Hover & click on the images for description

Description

Description:
Used to internationalise text messages. The provided translation key is looked up in Stringtable.xml (or Stringtable.csv).
Groups:
StringsLocalization

Syntax

Syntax:
localize stringName
Parameters:
stringName: String - string which leads to localisation. Casing does not matter. Arma 3 logo black.png2.04 A string starting with "$" is supported
Return Value:
String - text found in corresponding entry in stringtable file. If the key could not be found an empty string "" is returned and an entry is added to .rpt file, for example String STR_DN_SNAKE not found

Examples

Example 1:
hint localize "STR_West"; // returns "BLUFOR" hint localize "STR_WEST"; // returns "BLUFOR" hint localize "STR_weSt"; // returns "BLUFOR" hint localize "STR_NonExistentString"; // returns "" and logs "String STR_NonExistentString not found"
Example 2:
hint format ["Go %1", localize "STR_Q_NORTH"]; // returns "Go North"
Example 3:
hint format [ localize "STR_ACTION_DROP_WEAPON", // "STR_ACTION_DROP_WEAPON" contains "Drop %1" localize "STR_SN_RIFLE" // "STR_SN_RIFLE" contains "Rifle" ]; // returns "Drop Rifle"
Example 4:
localize "$STR_USRACT_ADJUST"; // returns "Adjust" since Arma 3 v2.04

Additional Information

See also:
isLocalized diag_localized getTextRaw BIS_fnc_localize WFSideText parseText Stringtable.csv Stringtable.xml

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Killzone_Kid - c
Posted on Sep 12, 2014 - 11:55 (UTC)
The command localize will strip all HTML tags from your Stringtable.xml entries, however there is a way to trick it by substituting tags with HTML code instead:
<?xml version="1.0" encoding="utf-8"?>
<Key ID="STR_TEST_KK">
	<Original><![CDATA[<t color='#ff0000'>This doesn't work</t>]]></Original>
</Key>
<Key ID="STR_TEST_KK2">
	<Original>&lt;t color='#ff0000'&gt;This works&lt;/t&gt;</Original>
</Key>

hint parseText localize "str_test_kk"; // no change of colour hint parseText localize "str_test_kk2"; // hint content is in red