Internationalizing games

Introduction

Sería excelente que el mundo hablara solo un idioma (It would be great if the world spoke only one language). Unfortunately for us developers, that is not the case. While indie or niche games usually do not need localization, games targeting a more massive market often require localization. Godot offers many tools to make this process more straightforward, so this tutorial is more like a collection of tips and tricks. Importing translations tutorial, so this one could be seen more like a follow-up to that one. Note download it from the Asset Library.

Configuring the imported translation

Project → Project Settings → Localization: The above dialog is used to add or remove translations project-wide.

Localizing resources

Remaps tab can be used for this: Select the resource to be remapped, then add some alternatives for each locale.

Converting keys to text

Button and Label, will automatically fetch a translation if their text matches a translation key. For example, if a label’s text is “MAIN_SCREEN_GREETING1” and that key exists in the current translation, then the text will automatically be translated. Object.set_message_translation and send a Object.notification to update the translation:

  1. func _ready(): # This assumes you have a node called "Label" as a child of the node # that has the script attached. var label = get_node("Label") label.set_message_translation(false) label.notification(NOTIFICATION_TRANSLATION_CHANGED)

For more complex UI nodes such as OptionButtons, you may have to use this instead:

  1. func _ready(): var option_button = get_node("OptionButton") option_button.set_message_translation(false) option_button.notification(NOTIFICATION_TRANSLATION_CHANGED) option_button.get_popup().set_message_translation(false) option_button.get_popup().notification(NOTIFICATION_TRANSLATION_CHANGED)

Object.tr() function can be used. This will just look up the text in the translations and convert it if found:

  1. level.set_text(tr("LEVEL_5_NAME"))status.set_text(tr("GAME_STATUS_" + str(status_index)))

Making controls resizable

Size and anchors, as dynamically adjusting control sizes may help. Container can be useful, as well as the text wrapping options available in Label.

TranslationServer

TranslationServer. Translations can be added or removed during run-time; the current language can also be changed at run-time.

Testing translations

You may want to test a project’s translation before releasing it. Godot provides two ways to do this. Input Devices > Locale, there is a Test property. Set this property to the locale code of the language you want to test. Godot will run the project with that locale when the project is run (either from the editor or when exported). Keep in mind that since this is a project setting, it will show up in version control when it is set to a non-empty value. Therefore, it should be set back to an empty value before committing changes to version control. Translations can also be tested when running Godot from the command line. For example, to test a game in French, the following argument can be supplied:

  1. godot --language fr

Translating the project name

application/name in the Project Settings and append the locale identifier to it. For instance, for Spanish, this would be application/name_es: list of locale codes.