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:
new UpgradeDefinition
{
Id = "bigboxes.capacity",
DisplayName = "Bigger Boxes", // becomes en: "bigboxes.capacity.name" = "Bigger Boxes"
}Then, for each string, in order:
- the player's exact locale, for example
pt-BR - the base language,
pt en- the raw key itself - which is why a missing translation shows
bigboxes.capacity.nameon screen instead of an empty node
Adding translations
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:
- anything starting with
techtree.ortt. - any key Tech Tree already uses itself -
cat_staff,tree_lmb,n_cashierand so on
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:
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",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
| Code | Language | Code | Language |
|---|---|---|---|
en | English | zh | Chinese (Traditional) |
pt-BR | Portuguese (Brazil) | zh-Hans | Chinese (Simplified) |
pt-PT | Portuguese (Portugal) | ja | Japanese |
pt | Portuguese | ko | Korean |
es | Spanish | cs | Czech |
fr | French | da | Danish |
de | German | fi | Finnish |
it | Italian | hu | Hungarian |
nl | Dutch | lt | Lithuanian |
tr | Turkish | pl | Polish |
ru | Russian | ro | Romanian |
You do not have to cover all of them. Add the ones you can do properly; English carries the rest.
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.