[Extension] Localization - translate your games a *little* easier!

Hi everyone, coming at you with a slightly smaller extension today after a longer hiatus. Hopefully I will get around to releasing some more interesting stuff in the following weeks but enjoy this treat for now.

Localization (L10N)

Before you ask, no, this extension is NOT a translator. MakeCode is unfortunately far too limited to implement such a system. However, it doesn’t mean that translating your games is impossible in MakeCode. Far from it actually, as I have already demonstrated in my most popular game, Deliverimania!

I used a proprietary system in place to translate the game manually. I managed to make it quite organized and modular which certainly sped up the process of implementing new terms and languages into my game, but not everyone is capable or willing to go to such lengths for a feature most people will never even interact with.

However, translating your game into a few prominent languages can be a nice final touch to an already polished game. So, I decided to take on the task of creating an extension that will streamline that process for everyone else in order to motivate coders to give a second thought to that idea. This extension makes it easy to define phrases that can be localized manually by yourself (if you’re multilingual) or contributors and inserted into your game depending on which language is selected.

Blocks

This extension adds 9 simple blocks for you to work with. Here is a breakdown:

Create language

Pretty self explanatory, this block creates a language block that will store all the phrases for a specific language in your game/project.

You can define a custom code and name for your language, as well as an optional native name, which is what the name of the language would be referred to in that language.

In case the native name isn’t defined, it will default to the standard language name.

Set phrase (key)

This block defines a phrase in a given language for a specific key. In case the key is already defined, it will override its value with a new value.

Set language

This blocks takes in a language object and applies it as the current language project-wide. By default, there is no language set upon game start, meaning it’s set to undefined.

Localize

This is the most important block, because it’s used to actually get the translated string by key from the current language.

Optionally, you can pass in arguments to format the string (we’ll get to this later)

This block returns a string.

Exceptions

  • This block will throw an exception if a language isn’t currently set
    Language locale is undefined
  • This block will throw an exception if the key used isn’t defined in the current language
    Identifier '[key]' not found in locale '[code]'

Localize with

Very similar to the previous block, but this one takes a specific language object to localize with, instead of using the currently applied one.

Just like its counterpart, it can take in arguments for formatting.

Exceptions

  • This block will throw an exception if the key used isn’t defined in the current language
    Identifier '[key]' not found in locale '[code]'

Unset language

If for some reason, you want to set the current language to null (remove it), you can do it with this block.

Get current language

Returns the language object that’s currently set.

Get language attribute

This block is used to retrieve attributes defined for a language object.

Available attributes are

  • Code (eg. en-US)
  • Name
  • Native name

Is language set

Checks if a language is currently set (non-null value)
Useful for preventing exceptions

Formatting

Wondering what the optional arguments in the localize blocks are for? This extension natively supports my String formatting extension! Meaning, you can translate strings that contain dynamic values as well!

The extension is already included and implemented, so all you have to do is use the formatting notation in your phrases and insert the arguments using the provided blocks.

Here’s a simple example on how you can use this extension in your project I made using Richard’s mini menu extension to set the language and then displayed the strings using my own extension!

Thanks for reading! You can get the extension here

11 Likes

So…

If this isn’t a translator, why should we use this?


So it’s open source translator? I see.

3 Likes

if you want to have people translate your game (or you know more than one language yourself) then this makes it easy to swap the text out at runtime.

we use a system very similar to this for makecode itself, and so does basically every bit of software/video game that supports multiple languages

5 Likes

This is neat, and very useful for polishing! :smiley:

1 Like