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.
-
lorum
- Newbie
- Posts: 1
- Joined: Tue Apr 19, 2022 2:22 pm
-
Contact:
#1
Post
by lorum » Tue Apr 19, 2022 2:33 pm
Hi, for some time I've been looking for how to translate some texts that are outside the normal translations, this is "text" tags or variables of the type: $ var = "hello world", used in some games, I've tried with _( ) and com __() but they don't always work, so I made this little script to help me:
Code: Select all
init python:
def replace_text(t):
if _preferences.language == "spanish":
t = t.replace("You've created a {i}new{/i} \n Ren'Py game.", "Otro texto 1")
t = t.replace("other text 2 ", "otro texto 2 ")
return t
config.say_menu_text_filter = replace_text
And it works until I come across variables of this type:
Code: Select all
$ f += "the {i}bee{/i}\n"
$ f += "is very big\n"
e "hi [f]"
Due to the use of {} and to the fact that the variable "f" is concatenated with other texts, the script does not recognize them, my question is is there any way to see the content of a variable in the script to be able to replace it?
-
Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
-
Contact:
#2
Post
by Imperf3kt » Tue Apr 19, 2022 5:07 pm
Does it work for you, using .format?
Code: Select all
$ f += "the {i}bee{/i}\n"
$ f += "is very big\n"
e "hi {}".format(f)
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project:
GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
-
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:
#3
Post
by Remix » Fri Apr 22, 2022 7:29 pm
You should be registering the strings for translation ...
$ f += _("the {i}bee{/i}\n")
(the _() registers it)
If the translation still does not occur, either use the !t modifier in interpolation ( "[var!t]" ) or renpy.substitute() as s string wrapper ( e( renpy.substitute( _("Translate this") ) ) )
-
Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#4
Post
by Ocelot » Sat Apr 23, 2022 2:56 am
Remix wrote: ↑Fri Apr 22, 2022 7:29 pm
You should be registering the strings for translation ...
$ f += _("the {i}bee{/i}\n")
(the _() registers it)
If the translation still does not occur, either use the !t modifier in interpolation ( "[var!t]" ) or renpy.substitute() as s string wrapper ( e( renpy.substitute( _("Translate this") ) ) )
You should use double underscore for immideate translation if you are building strings:
__("the {i}bee{/i}\n"). Translation framework translates strings when they are displayed, just before substitutions happen. And it will do that only if exact match is found. So you want to translate parts of the strings before they are glued together. Or use translated interpolation, as you suggested.
< < insert Rick Cook quote here > >
Users browsing this forum: No registered users