Modding Tutorials/Plague Gun (old)/Localisation

From RimWorld Wiki
(Redirected from Plague Gun/Localisation)
Jump to navigation Jump to search

This tutorial was originally written by Jecrell. Thread.

Translations[edit]

  1. Now it's time to turn our project's C# strings into text that everyone can translate if they switch to other languages.
    • Remember these lines in our C# project?
                              Messages.Message("TST_PlagueBullet_SuccessMessage".Translate(
                              this.launcher.Label, hitPawn.Label
                          ), MessageSound.Standard);
    and...
    MoteMaker.ThrowText(hitThing.PositionHeld.ToVector3(), hitThing.MapHeld, "TST_PlagueBullet_FailureMote".Translate(Def.AddHediffChance), 12f);
    • Both of these sections use the .Translate string extension method. Each .Translate can take a single argument (.Translate(stringGoesHere)) or multiple arguments (.Translate(stringOne, stringTwo)). In XML, these arguments are then referenced as {0} if singular, or {0} and {1} etc for multiple arguments. I'll show you what I mean below.
  2. Make a Languages folder.


RimWorld>Mods>PlagueGun>Languages

  1. Make an English folder.


RimWorld>Mods>PlagueGun>Languages>English

  1. Make a Keyed folder.


RimWorld>Mods>PlagueGun>Languages>English>Keyed

    • Keyed means that our C# code references a "Key" in our mod's language dictionary.
  1. Make a text file and change it to an XML file named PlagueGun_Keys.xml
  2. Fill out the PlagueGun_Keys.xml with our string keys.
    • First, add in this familiar line.
      <?xml version="1.0" encoding="utf-8" ?>
    • Add in the tag for LanguageData
      <LanguageData>
      </LanguageData>
    • In between LanguageData, add in the keys we used earlier, and define them.
    • Earlier, we used the string keys TST_PlagueBullet_FailureMote and TST_PlagueBullet_SuccessMessage.
    • Filling in the file should look something like this.
      <?xml version="1.0" encoding="utf-8" ?>
      <LanguageData>
        <TST_PlagueBullet_FailureMote></TST_PlagueBullet_FailureMote>
        <TST_PlagueBullet_SuccessMessage></TST_PlagueBullet_SuccessMessage>
      </LanguageData>
    • Let's use our argument notes from earlier. We passed one argument to the failure mote. So we should use {0}, to represent the hit chance. We passed two arguments to the success message, so we should use {0}, to represent the launcher, and {1}, to represent the hit character.
    • Fill out the text for the messages.
      <?xml version="1.0" encoding="utf-8" ?>
      <LanguageData>
        <TST_PlagueBullet_FailureMote>Failure: {0} chance</TST_PlagueBullet_FailureMote>
        <TST_PlagueBullet_SuccessMessage>{0} infected {1} with the plague!</TST_PlagueBullet_SuccessMessage>
      </LanguageData>
  3. Save the file.
  4. Translation complete.
  5. Mod complete.

Congratulations! You've completed the tutorial. If you want to compare your mod to a working example, check out this GitHub repo.

Next up[edit]

We've got a gun now, but it still looks like the plain revolver. You'll probably want to add some textures. Or even sound? You might want to put your mod on Steam (well, not this one of course). Maybe you want to mess with Harmony, or get an overview of the more in-depth information available on the wiki?

See also[edit]

  1. Required Items
  2. XML Stage
  3. Connecting XML and C#
  4. C# Assembly Setup
  5. C# Coding
  6. Localisation <- You are all the way down here, congrats!

More in-depth[edit]