0 votes

Hello !

I set up 2 DynamicFonts ( engfont.tres for English and japfont.tres for Japanese) and I would like to be able to switch my label's font depending on the language option selected.

Basically, this is what I'd like to do :

func _on_japanese_pressed():
   var typo = load("res://fonts/japfont.tres") 
   label.font = typo
   label.text =  "日本語 (japanese)"

# Invalid set index 'font' (on base: 'Label') with value of type 'DynamicFont'

What is the correct way of putting it please ?
thank you !

in Engine by (245 points)
edited by

Try defining one or several fallback fonts in the English DynamicFont resource. This way, you won't have to define create font resources and the font will be swapped automatically when the glyph cannot be found in the original (English) font.

2 Answers

+1 vote
Best answer

That should help you out - Localizing resources. Set different font for different language.

by (378 points)
selected by

thanks, I didn't want to get into this translation option as I already did all the translations myself, but it is super useful actually to be able to switch assets so easily ! :D

+1 vote

I managed to do what I wanted :

   func _on_japanese_pressed():
       var fnt = load("res://fonts/japfont.tres")
       get_node("label").add_font_override("font", fnt)
       label.text =  "日本語 (japanese)"
by (245 points)

I add:

var fnt = load("res://assets/fonts/osans_font.tres")
var name_label = Label.new()
name_label.add_font_override("font",fnt)
name_label.text = data.name
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.