Internationalizing games

Введение

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.

Localization is usually done by specific studios hired for the job and, despite the huge amount of software and file formats available for this, the most common way to do localization to this day is still with spreadsheets. The process of creating the spreadsheets and importing them is already covered in the Импорт переводов tutorial, so this one could be seen more like a follow-up to that one.

Примечание

We will be using the official demo as an example; you can download it from the Asset Library.

Configuring the imported translation

Translations can get updated and re-imported when they change, but they still have to be added to the project. This is done in Project → Project Settings → Localization:

../../_images/localization_dialog.png

The above dialog is used to add or remove translations project-wide.

Localizing resources

It is also possible to instruct Godot to use alternate versions of assets (resources) depending on the current language. The Remaps tab can be used for this:

../../_images/localization_remaps.png

Select the resource to be remapped, then add some alternatives for each locale.

Converting keys to text

Some controls, such as 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.

This automatic translation behavior may be undesirable in certain cases. For instance, when using a Label to display a player's name, you most likely don't want the player's name to be translated if it matches a translation key. To disable automatic translation on a specific node, use Object.set_message_translation and send a Object.notification to update the translation:

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:

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)

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

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

Making controls resizable

The same text in different languages can vary greatly in length. For this, make sure to read the tutorial on 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

В Godot есть сервер для низкоуровневого управления переводами, который называется TranslationServer. Переводы могут быть добавлены или удалены во время выполнения; текущий язык также может быть изменен во время выполнения.

Командная строка

Язык можно проверить при запуске Godot из командной строки. Например, чтобы проверить игру на французском языке, можно указать следующий аргумент:

godot --language fr

Перевод названия проекта

Имя проекта становится именем приложения при экспорте в различные операционные системы и платформы. Чтобы указать имя проекта на нескольких языках, создайте новый параметр application/name в Project Settings и добавьте к нему идентификатор локали. Например, для испанского языка это будет application/name_es:

../../_images/localized_name.png

Если вы не уверены в том, какой код языка использовать, обратитесь к списку кодов локалей.