Translating a font for everything

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Karrion
Regular
Posts: 40
Joined: Fri Jan 18, 2019 8:33 pm
Contact:

Translating a font for everything

#1 Post by Karrion » Wed Jul 08, 2020 11:06 am

Hello!

Is there a way for the game to use the same font for everything when selecting another language? I want to have the game in japanese, however when I use the translate_font function, ren'py says it's not defined. Also, I tried putting gui.setpreference("font","nameofthefont.ttf") on the buttons to select language, but that does not work either.

The only thing that works is something like this:

Code: Select all

translate japanese style default:
    font "fonts/dougenzaka16.ttf"
    size 50

translate japanese style say_label:
    font "fonts/dougenzaka16.ttf"
    size 45
but when I tried to translate the "choice_button" style to get the "are you sure?" messages to be translated, that did not work either. Also, it would not change the time format of the saveslots, which I also want to change. Any suggestions?

User avatar
namastaii
Eileen-Class Veteran
Posts: 1348
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Translating a font for everything

#2 Post by namastaii » Wed Jul 08, 2020 11:31 am

Code: Select all

init python:
    translate_font("language", "myfont.ttf")
https://www.renpy.org/doc/html/translat ... ging-fonts

Karrion
Regular
Posts: 40
Joined: Fri Jan 18, 2019 8:33 pm
Contact:

Re: Translating a font for everything

#3 Post by Karrion » Wed Jul 08, 2020 11:34 am

Does not work, ren'py says the function is not defined

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/language.rpy", line 1, in script
    init python:
  File "game/language.rpy", line 2, in <module>
    translate_font("japanese", "fonts/dougenzaka16.ttf")
NameError: name 'translate_font' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/language.rpy", line 1, in script
    init python:
  File "C:\Users\karri\Downloads\renpy-7.3.5-sdk\renpy\ast.py", line 914, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\karri\Downloads\renpy-7.3.5-sdk\renpy\python.py", line 2028, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/language.rpy", line 2, in <module>
    translate_font("japanese", "fonts/dougenzaka16.ttf")
NameError: name 'translate_font' is not defined

Windows-8-6.2.9200
Ren'Py 7.3.5.606
 
Wed Jul 08 17:41:02 2020

User avatar
Jackkel Dragon
Veteran
Posts: 221
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Translating a font for everything

#4 Post by Jackkel Dragon » Wed Jul 08, 2020 12:08 pm

Away from my main computer at the moment so no code samples, but what I did was define several font groups where the gui.rpy usually generates the default font. Then, in the translate block for the other language, I changed the font attribute of the related text styles.

Pseudocode:

Code: Select all

translate japanese python:
    say_label.font = basic_font # instead of default_font
If that doesn't help, I can try to copy my code when I have my files.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

Karrion
Regular
Posts: 40
Joined: Fri Jan 18, 2019 8:33 pm
Contact:

Re: Translating a font for everything

#5 Post by Karrion » Wed Jul 08, 2020 12:26 pm

Is there no option to make the translate_font function to work or a similar alternative? I don't really understand what did you do.

User avatar
MaydohMaydoh
Regular
Posts: 165
Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:

Re: Translating a font for everything

#6 Post by MaydohMaydoh » Wed Jul 08, 2020 12:48 pm

The translate_font function only seems to be for configuring translations in the launcher, not games.
As for the other way, the style for the choice button should be "choice_button_text" I would think.

Karrion
Regular
Posts: 40
Joined: Fri Jan 18, 2019 8:33 pm
Contact:

Re: Translating a font for everything

#7 Post by Karrion » Wed Jul 08, 2020 12:52 pm

Ah yes, I just found about the function right now. Also, tried choice_button_text, did not work.

Edit: I just looked at the style inspector to see if I could find what style I have to modify, and apparently it's "confirm_prompt_text". Now I have to look for the one in the date for the saveslots.

Edit 2: The style is slot_time_text. The problem now is that even if I change the size in the translation, the size does not change in the game.

Edit 3: I was forcing the size in the code instead of changing the size in the style so there was the problem.

User avatar
Jackkel Dragon
Veteran
Posts: 221
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Translating a font for everything

#8 Post by Jackkel Dragon » Thu Jul 09, 2020 3:15 pm

Found the file where I did this, so here's what I've done in my translation experiments so far (or at least the relevant bits):

Code: Select all

translate japanese python:
    style.quick_button.xsize = 140
    ### etc...
    
    ## important part
    ## this is based on the GUI post-7.0 Ren'Py. If you're using the old GUI system, you have to do all related styles in the manner seen above
    gui.text_font = basic_font
    gui.name_text_font = basic_font

Code: Select all

## in the gui.rpy, so assume init -2 for this
## as before, this applies to the 7.0+ default gui files, but some of the ideas can be applied to custom or old GUI

define default_font = FontGroup().add("fonts/ampersand.ttf", 0x0000, 0x02AF).add("fonts/malgun.ttf", 0xAC00, 0xD7A7).add("fonts/meiryo.ttf", 0x0000, 0xffff)

define gui.text_font = default_font ## used for a lot of gui.rpy font definitions
define gui.name_text_font = default_font

define basic_font = FontGroup().add("fonts/malgun.ttf", 0xAC00, 0xD7A7).add("fonts/meiryo.ttf", 0x0000, 0xffff)
So, what's basically happening:
- At init -2, we create a default font group (or normal font, if you don't need special characters like I do).
- We set the gui.rpy default fonts to the font group we made (one line controls all of those individual styles).
- We create a basic/alternate font group.
- At translate time (after init), if we're set to Japanese instead of None or something else, we change the gui's text font attributes.
- When drawing the screen, the game should (ideally) display the relevant font for whatever language is active.

So far, this has worked fine for me. However, I've not yet set all interface text to use the alternate font, so I'm probably missing a font definition somewhere or it gets baked-in during an init phase. I solved this for myself by using font groups, but if you have entirely different fonts for different languages you may want to look into where the interface text is defined.

At any rate, I hope this helps a bit.

Edit: So, the interface text is set by "gui.interface_text_font". I guess I just missed it because I use the "basic" font for it in my game regardless of language settings.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

Post Reply

Who is online

Users browsing this forum: Google [Bot], rayminator