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.

Mega Tree's own text is English only

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:

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

Then, for each string, in order:

  1. the language the game is set to
  2. English
  3. your DisplayName as 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

csharp
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:

csharp
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",
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.

What you can pass as the language

CodeGame nameCodeGame name
enEnglish huHungarian
ptPortuguese roRomanian
esSpanish ukUkrainian
frFrench elGreek
deGerman heHebrew
itItalian arArabic
ruRussian thThai
plPolish viVietnamese
trTurkish idIndonesian
nlDutch msMalay
csCzech jaJapanese
svSwedish koKorean
daDanish zh / zh-CNChineseSimplified
fiFinnish zh-TWChineseTraditional
noNorwegian

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 it repaints, so a language change takes effect immediately. Do not cache a translated string in a field at registration time - cache the key.