Skip to content

Include example of handling run-time translation changes in a script #647

@Calinou

Description

@Calinou

Which demo project is affected: Translation Demo

Description:

The Translation demo should include an example of handling translation changes for a custom control in a script.

See https://godotforums.org/discussion/27323/acessing-translations-and-new-scenes where I had to devise some custom code for this, but I don't know if it actually works. Cross-posting it here for posterity:

# Stores the text that is displayed to the user.
var text = "" setget set_text

# Stores the translation key.
var original_text = ""

func set_text(p_text):
    text = tr(p_text)
    original_text = p_text

func _notification(what):
    if what == NOTIFICATION_TRANSLATION_CHANGED:
        self.text = tr(original_text)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions