Mega Tree API
Translations
How to name your node in the player's language, why both "pt-BR" and "Portuguese" work, 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.
The tree's own labels - the tab names, the hover card, the footer - are written in English and are not translated. This page is about your node, which does not have to wait for that.
So a mod can ship in five languages while the tree around it is in one. That is a bit odd to look at, and it is still better than telling a modder "no" for a reason that is my problem.
How a name is resolved
Every displayed name goes through a key. When you only give a
DisplayName, Mega Tree makes the key for you - it is
<id>.name - and fills it in English:
new UpgradeDefinition
{
Id = "bigboxes.capacity",
DisplayName = "Bigger Boxes", // becomes English: "bigboxes.capacity.name" = "Bigger Boxes"
}Then, for each string, in order:
- the language the game is set to
- English
- your
DisplayNameas written
The game does not speak BCP-47
This is the one place where Megastore differs from Supermarket in a way you can trip over.
Unity's localisation uses codes like pt-BR. Megastore uses the
name of the language: English,
Portuguese, ChineseSimplified.
Both work. AddTranslations accepts either, and
pt-BR, pt and
Portuguese all land in the same bucket. Anything the table below does
not cover is passed through unchanged, so a language this list does not know still works if you
spell its name the way the game does.
Adding translations
var tree = MegaTreeApi.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",
});
// The game's own spelling works just as well.
tree.AddTranslations("German", new Dictionary<string, string>
{
["bigboxes.capacity.name"] = "Groessere Kisten",
});Order does not matter: you can add translations before or after registering.
What you may not write
Keys starting with megatree. or mt. 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 language yourself:
using DFTGames.Localization;
private static bool IsPortuguese()
{
try { return Locale.CurrentLanguage == "Portuguese"; }
catch { return false; }
}
// ...
DescribeLevel = lvl => IsPortuguese()
? $"+{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.
What you can pass as the language
| Code | Game name | Code | Game name |
|---|---|---|---|
en | English | hu | Hungarian |
pt | Portuguese | ro | Romanian |
es | Spanish | uk | Ukrainian |
fr | French | el | Greek |
de | German | he | Hebrew |
it | Italian | ar | Arabic |
ru | Russian | th | Thai |
pl | Polish | vi | Vietnamese |
tr | Turkish | id | Indonesian |
nl | Dutch | ms | Malay |
cs | Czech | ja | Japanese |
sv | Swedish | ko | Korean |
da | Danish | zh / zh-CN | ChineseSimplified |
fi | Finnish | zh-TW | ChineseTraditional |
no | Norwegian |
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 it repaints, so a language change takes effect immediately. Do not cache a translated string in a field at registration time - cache the key.