From 0a8843399da8f252ca55152d41bd0ba8e0965522 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 13 May 2021 17:06:54 +0200 Subject: [PATCH] Document disabling automatic translation in Internationalizing games (cherry picked from commit 8000d8f317ba6c91a1924822ed0cdf726b206ee3) --- tutorials/i18n/internationalizing_games.rst | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tutorials/i18n/internationalizing_games.rst b/tutorials/i18n/internationalizing_games.rst index af6b13460..823590ee4 100644 --- a/tutorials/i18n/internationalizing_games.rst +++ b/tutorials/i18n/internationalizing_games.rst @@ -56,6 +56,30 @@ 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 +:ref:`Object.set_message_translation` +and send a :ref:`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 :ref:`Object.tr() ` function can be used. This will just look up the text in the translations and convert it if found: