translation_demo.gd 628 B

1234567891011121314151617181920212223242526272829303132
  1. extends Control
  2. func _ready() -> void:
  3. _set_text_in_label()
  4. func _on_english_pressed():
  5. TranslationServer.set_locale("en")
  6. func _on_spanish_pressed():
  7. TranslationServer.set_locale("es")
  8. func _on_japanese_pressed():
  9. TranslationServer.set_locale("ja")
  10. func _on_play_pressed():
  11. $Audio.play()
  12. func _set_text_in_label():
  13. # Use tr(translation_key) to get the desired string in the correct language.
  14. var message := "This text is being translated through script: \n"
  15. message += tr("KEY_TEXT")
  16. $TextLabel.text = message
  17. func _notification(what):
  18. if what == NOTIFICATION_TRANSLATION_CHANGED:
  19. _set_text_in_label()