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.
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:
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:
$ 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?
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") ) ) )
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.