Blog Post 16 Jun 20 – Localization

A hello to new readers, and a welcome back to old ones!

Today’s post is about localization, on how I’m achieving it for TinyAttack more specifically.

Everything started some days ago, as I was working on the UI for multiplayer, I remembered that eventually the game could be localized into different languages, and a desire to prevent doing the same work multiple times arose.

Doing stuff? Doing the same stuff multiple times? Oh no…

The first step was researching, I wanted to decide on what format the localization files would have. I wanted something be user friendly, since I wanted the files to be open to users and they could change it as they wanted.

From all possibilities I decided json was good enough, it wasn’t as confusing to look as xml, and not as loosely as csv.

Decided the format, next step was actually doing it.

The biggest problem was getting plurals to work, my first approach was not only flawed but also wasted me almost two days of work.

In all my intelligence, I had decided to just use an array in the value and get the result depending on the number passed as an argument in code:

Me, pretending to be smart: Behold, a json!

The syntax {x} was decided because that’s how String.Format works, and I wanted to be able to offer some of the cool stuff that method does.

Woa that ended up being a bad idea, not only did I decide to make a whole tool to create localization files, I decided to do it in html, and then I put that array bullshit that made me lose hours and hours of sanity.

The absolutely madgirl…

The first problem was doing the tool, but only later on I found the biggest one.

How would I select which value to use? Sure I thought to use a number given as a parameter, but what if there are multiple parameters? For each one the complexity of the array increases exponentially!

Filled with madness, I took some time off, later I decided to look into how Slay the Spire did it, and then I remember about keywords, and was quickly to implement them into my own project!


Next big step was deciding on how I would implement the formatting for it, I ended up deciding on something like:

To implement it I actually copy+pasted most of the method from StringBuilder.AppendFormat and changed it, so it would use the keyword version based on the arguments given when you as for a localized key!

Like so:

And to finish, a gif showing the system in real time:

This system also includes a new type of class that mimics the behaviour of strings and custom UI classes, which I will cover in a private patron-only post.

Thanks for all your support! – Saishy

Liked it? Take a second to support TinyBird Games on Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.