Tech Tree API

Translations

The 22 locale codes Tech Tree ships with, how the fallback chain works, and which keys you are allowed to write.

You can skip this page

Translations are optional. Set DisplayName and your node is called that in every language. Nothing breaks, nothing warns. Come back here when you want more.

How a name is resolved

Every displayed string goes through a key. When you only give a DisplayName, Tech Tree makes the key for you - it is <id>.name - and fills it in English:

csharp
new UpgradeDefinition
{
    Id          = "bigboxes.capacity",
    DisplayName = "Bigger Boxes",   // becomes en: "bigboxes.capacity.name" = "Bigger Boxes"
}

Then, for each string, in order:

  1. the player's exact locale, for example pt-BR
  2. the base language, pt
  3. en
  4. the raw key itself - which is why a missing translation shows bigboxes.capacity.name on screen instead of an empty node

Adding translations

csharp
var tree = TechTreeApi.ForPlugin("BigBoxes", "Big Boxes");

tree.Register(new UpgradeDefinition
{
    Id          = "bigboxes.capacity",
    NameKey     = "bigboxes.capacity.name",   // explicit is clearer once you translate
    DisplayName = "Bigger Boxes",             // still the English fallback
    // ...
});

tree.AddTranslations("pt-BR", new Dictionary<string, string>
{
    ["bigboxes.capacity.name"] = "Caixas Maiores",
    ["Big Boxes"]              = "Caixas Grandes",   // your sub-tab label
});

tree.AddTranslations("de", new Dictionary<string, string>
{
    ["bigboxes.capacity.name"] = "Groessere Kisten",
});

Order does not matter: you can add translations before or after registering.

Translating your sub-tab

The sub-tab label doubles as its own translation key. Add an entry whose key is the exact label you passed to ForPlugin and the tab follows the game's language; leave it out and the label shows as written.

What you may not write

Two kinds of key are refused, silently skipped and counted in one warning line:

Otherwise one mod could rewrite the whole tree's UI text. Prefix your keys with your id or your guid and you will never hit this.

The effect text

DescribeLevel returns a string directly - it does not go through a key. To translate it, look up the locale yourself:

csharp
using UnityEngine.Localization.Settings;

private static string Loc()
{
    try { return LocalizationSettings.SelectedLocale?.Identifier.Code ?? "en"; }
    catch { return "en"; }
}

// ...
DescribeLevel = lvl => Loc().StartsWith("pt")
    ? $"+{lvl * 2} itens por caixa"
    : $"+{lvl * 2} items per box",
Numbers first

Effect lines are read at a glance. "+6 items per box" survives a bad translation; "Increases the carrying capacity of each delivered box" does not survive the card width. Lead with the number.

Locale codes Tech Tree ships with

CodeLanguageCodeLanguage
enEnglish zhChinese (Traditional)
pt-BRPortuguese (Brazil) zh-HansChinese (Simplified)
pt-PTPortuguese (Portugal) jaJapanese
ptPortuguese koKorean
esSpanish csCzech
frFrench daDanish
deGerman fiFinnish
itItalian huHungarian
nlDutch ltLithuanian
trTurkish plPolish
ruRussian roRomanian

You do not have to cover all of them. Add the ones you can do properly; English carries the rest.

The player can change language mid-game

The tree re-reads every string each time the window opens, so a language change takes effect immediately. Do not cache a translated string in a field at registration time - cache the key.