Editing Modding Tutorials/Localization

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 120: Line 120:
 
</LanguageData>
 
</LanguageData>
 
</source>
 
</source>
 
==== Using Keyed Strings in C# ====
 
 
Keyed strings can be used from C# by using the Verse.Translator.Translate() extension method like so:
 
 
<source lang="cs">
 
string translatedString = "ClickToJumpToProblem".Translate();
 
</source>
 
 
If the specified key cannot be found, then the key itself will be shown. If Dev Mode is enabled, this will come out as glitched text to make them easier to notice and fix.
 
  
 
==== String Arguments ====
 
==== String Arguments ====
  
String arguments can be used to inject values into key strings. The simplest way of using arguments is by using indexed arguments like so:
+
(Placeholder) String arguments can be used to inject values into key strings. Please check out [[Modding_Tutorials/GrammarResolver|GrammarResolver]] for the time being. (Temporary link until cleanup can happen)
 
 
<source lang="xml">
 
<?xml version="1.0" encoding="utf-8" ?>
 
<LanguageData>
 
  <Example_KeyString>Current Class: Level {0} {1} ({2}%)</Example_KeyString>
 
</LanguageData>
 
</source>
 
 
 
Strings to be injected into those indexed tokens can be added using arguments to the Translate() method:
 
 
 
<source lang="cs">
 
int level = 4;
 
string className = "Rogue";
 
float levelProgress = 96f;
 
string translatedString = "Example_KeyString".Translate(level.ToString("N0"), className, levelProgress.ToString("F1"));
 
</source>
 
 
 
The value of <code>translatedString</code> in this case would be <code>Current Class: Level 4 Rogue (96.0%)</code>
 
 
 
(Placeholder) You can also use named arguments in keyed strings. Please check out [[Modding_Tutorials/GrammarResolver|GrammarResolver]] for the time being. (Temporary link until cleanup can happen)
 
  
 
=== <code>Strings</code> ===
 
=== <code>Strings</code> ===

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: