Translating Strings Within a Function?

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
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Translating Strings Within a Function?

#1 Post by Obscura »

My game contains numerous custom choice menus that look like this:

Code: Select all

call special_menu ("Go fast.", "Go slow.")
if pics == 0:
  "You run."
else:
  "You walk."
If it matters, the function itself looks like this:

Code: Select all

label special_menu(*menu_options):
  $picks = None
  $menu_options = list(menu_options)
  $renpy.call_screen("custom_menu", _layer="menus", menu_options=menu_options
  return
  
screen custom_menu:
   ...(misc code for the menu)...
When I generate translation files, is there any way to have Renpy generate translation lines for strings inside the function? (e.g.,"Go fast." and "Go slow.")

Right now it skips over those strings. I placed an underscore in front of the parentheses but it generates error messages.

Thanks!
Coming Out On Top - An Adult Gay Dating Sim
website

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: Translating Strings Within a Function?

#2 Post by Obscura »

Ah, never mind, I found the answer here, in case anyone has the same question:

viewtopic.php?t=49205
Coming Out On Top - An Adult Gay Dating Sim
website

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3784
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Translating Strings Within a Function?

#3 Post by Imperf3kt »

I believe adding !t also works.
Not sure on that though, translation is a feature I haven't looked into yet.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: Translating Strings Within a Function?

#4 Post by Obscura »

Oh, thanks! Do you happen to know where I'd add the !t?

Looking at https://www.renpy.org/doc/html/translat ... stitutions and I'm not sure I know where that would go.
Coming Out On Top - An Adult Gay Dating Sim
website

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3784
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Translating Strings Within a Function?

#5 Post by Imperf3kt »

Unfortunately I only know of it, not much more.
I'm not even sure it can be used for what you want.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: Translating Strings Within a Function?

#6 Post by Obscura »

Ah, gotcha. Thank you for the tip regardless.
Coming Out On Top - An Adult Gay Dating Sim
website

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: Translating Strings Within a Function?

#7 Post by Remix »

!t would be for translating variables in interpolated strings
$ var = _( "English" )
e "[var!t]" # >> translated version

Using just _("String") should be fine in yours and perform the translation as needed.

The other function to note is renpy.substitute( var ) to force the var through translation and tag substitution. (might be renpy.substitutions.substitute() though)
Frameworks & Scriptlets:

nautilus_nc
Newbie
Posts: 17
Joined: Wed Jan 16, 2019 11:59 pm
Contact:

Re: Translating Strings Within a Function?

#8 Post by nautilus_nc »

Hi! Sorry for revival this post but i dont understand you use

call special_menu (__("Go fast.", __"Go slow."))
if pics == 0:
"You run."
else:
"You walk."

And works?

Post Reply

Who is online

Users browsing this forum: Google [Bot]