[SOLVED] Toggling between English/Chinese font for game translation

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
User avatar
hassohappa
Regular
Posts: 33
Joined: Thu Oct 22, 2015 8:51 pm
Tumblr: me-patra
Contact:

[SOLVED] Toggling between English/Chinese font for game translation

#1 Post by hassohappa »

Someone translated my game to Chinese, but I don't know how to change to a Chinese font when you choose it in the menu. So everything shows up as rectangles:
screenshot0131.png
I've added a Chinese font to the game directory with my other fonts, and tried adding the lines of code from this https://www.renpy.org/wiki/renpy/doc/co ... d_Japanese:

init:
$ style.default.font = "chinese.ttf" #this is my chinese font name
$ style.default.language = "eastasian"


But it doesn't have an effect. I feel like it's probably being overridden by me setting the default menu/dialogue fonts elsewhere like gui.rpy?

Do I need to make a class that will change the default font to the Chinese one, and then in my Settings menu do something like this?
textbutton "中文" action Language("traditional_chinese") ToggleField(persistent, "chineseFont")
(I'm not a programmer, sorry if this sounds wonky)

Or is there an obvious method I'm missing? Thanks in advance for any advice!
Last edited by hassohappa on Thu Feb 01, 2018 11:02 pm, edited 1 time in total.

User avatar
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Toggling between English/Chinese font for game translation

#2 Post by ComputerArt.Club »

I'll bump this for you since I am also working on a Chinese game. I'm still working in the art for mine though, I haven't started coding it yet.

First thought that came to mind, are you using Editra? I believe it does not support Chinese characters, you may need to try a different editor if you haven't already.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Toggling between English/Chinese font for game translation

#3 Post by Remix »

The simplest way is probably to use gui.preference for the font and add actions to the language swap buttons.
This Page outlines how it works.

Alternatively the translate style method could work if you can understand what to do (it confuses me as it says 'translate style python:' which makes no sense, lol)
Frameworks & Scriptlets:

User avatar
Donmai
Eileen-Class Veteran
Posts: 1960
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Toggling between English/Chinese font for game translation

#4 Post by Donmai »

If I understood it correctly, add this to any rpy file:

Code: Select all

translate english style default:
    font "fonts/your_english_font_name_here.ttf"
translate chinese style default:
    font "fonts/your_chinese_font_name_here.ttf"
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
hassohappa
Regular
Posts: 33
Joined: Thu Oct 22, 2015 8:51 pm
Tumblr: me-patra
Contact:

Re: Toggling between English/Chinese font for game translation

#5 Post by hassohappa »

Donmai wrote: Thu Feb 01, 2018 2:59 pm If I understood it correctly, add this to any rpy file:

Code: Select all

translate english style default:
    font "fonts/your_english_font_name_here.ttf"
translate chinese style default:
    font "fonts/your_chinese_font_name_here.ttf"
This worked, thank you so much! In English, I used multiple fonts in different places (for example, menus, dialogue), so I have to add that extra line to many styles. Here's a snippet of what it looks like in my rpy files, for anyone else wondering how to do it:

Code: Select all

style main_menu_hbox:
    font "YunusH.ttf"
    spacing 21
    
translate traditional_chinese style main_menu_hbox:
    font "traditional_chinese.ttf"     
    
style main_menu_button_text:
    xanchor 0.5
    xalign 0.5
    text_align 0.5
    font "YunusH.ttf"
    size 45
    color "#c1adff"
    hover_color "#ffcef2"  

translate traditional_chinese style main_menu_button_text:
    font "traditional_chinese.ttf"
    size 20 #you can also change other stuff in the style for different language versions! so handy!
The GUI method also looks helpful! But the translate method makes it easy to pinpoint specific styles, which wouldn't be easy in the GUI method below:

Code: Select all

textbutton _("OpenDyslexic") action gui.TogglePreference("font", "OpenDyslexic-Regular.otf", "DejaVuSans.ttf")
ComputerArt.Club wrote: Thu Feb 01, 2018 8:00 am I'll bump this for you since I am also working on a Chinese game. I'm still working in the art for mine though, I haven't started coding it yet.

First thought that came to mind, are you using Editra? I believe it does not support Chinese characters, you may need to try a different editor if you haven't already.
I am still using Editra, and the Chinese characters are showing up inside the editor and in-game just fine. I'm not sure if my translator typed the characters in a different word processor and then pasted them into Editra, but it looks like once they are there, there's no issue.

User avatar
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Toggling between English/Chinese font for game translation

#6 Post by ComputerArt.Club »

hassohappa wrote: Thu Feb 01, 2018 10:54 pm I am still using Editra, and the Chinese characters are showing up inside the editor and in-game just fine. I'm not sure if my translator typed the characters in a different word processor and then pasted them into Editra, but it looks like once they are there, there's no issue.
Right, I see now that Renpy states that:
Editra currently lacks the IME support required for Chinese, Japanese and Korean text input.
So I guess its more of an issue of inputting it inside the program rather than pasting it from another program. Glad to hear that your problem is solved!

Post Reply

Who is online

Users browsing this forum: 3N16M4