Hello,
Thank you for this tuto it's good thing for a newbie.
But there is something I don't understand about the common.rpy and screen.rpy files generated by the ren py translation function.
If you have an explanation it would be nice! See the post
viewtopic.php?f=8&t=56918#p519307
Implementing Translations in Ren'Py [Updated Tutorial]
Forum rules
Do not post questions here!
This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Do not post questions here!
This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Re: Implementing Translations in Ren'Py [Updated Tutorial]
English is not my native language; please excuse typing errors.
- Shocking Alberto
- Regular
- Posts: 35
- Joined: Sun Mar 29, 2020 4:58 am
- Contact:
Re: Implementing Translations in Ren'Py [Updated Tutorial]
I'm actually stuck on how to implement an achievement for switching languages.
I have my game setup where you can toggle the languages from within preferences. So far so good.
screens.rpy
Code: Select all
frame:
label _("Languages")
hbox:
textbutton "日本語" action Language(None)
textbutton "English" action Language("english")
textbutton "简体中文" action Language("simpch")
textbutton "繁体中文" action Language("chinese")
Code: Select all
if persistent.first_boot:
persistent.first_boot = False
renpy.run(SetPreferencesDefault)
_preferences.language = "english"
persistent.last_lang = _preferences.language
grant_achievement("game_start")
if persistent.last_lang != _preferences.language:
grant_achievement("change_language")
persistent.last_lang = _preferences.language
Now that a language toggle is being used, this code does work but it only works after changing the language in game then restarting so I'm wondering what would be a better solution that doesn't require the user to restart the game. I thought maybe I could add an if statement in screens.rpy perhaps?
- Shocking Alberto
- Regular
- Posts: 35
- Joined: Sun Mar 29, 2020 4:58 am
- Contact:
Re: Implementing Translations in Ren'Py [Updated Tutorial]
So I thought this through a bit more and realizing I don't really need too much logic to check for the language being toggled, maybe I could just modify screens.rpy to trigger the achievement.
The achievement is designed to trigger if it's anything but English so I figured maybe this would work? Alas I get the following error:
I feel like I'm very close to the solution... maybe?
Edit: And this is why I never could pass my old college programming classes. I apparently left off an open bracket on the last text button. Put that in and it works like a charm. '-')v
Code: Select all
label _("Languages")
hbox:
textbutton "日本語":
action [ Language(None),
Function(grant_achievement, "change_language")]
# English is the default language so clicking it won't trigger the achievement.
textbutton "English" action Language("english")
textbutton "简体中文":
action [ Language("simpch"),
Function(grant_achievement, "change_language")]
textbutton "繁体中文":
action Language("chinese"),
Function(grant_achievement, "change_language")]
Code: Select all
File "game/screens.rpy", line 616: u'return' is not a keyword argument or valid child for the vbox statement.
return Text("This is English.")
Edit: And this is why I never could pass my old college programming classes. I apparently left off an open bracket on the last text button. Put that in and it works like a charm. '-')v
Who is online
Users browsing this forum: No registered users