Translation: How to get the text in original language

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
srksrk 68
Regular
Posts: 30
Joined: Fri Jul 19, 2019 8:10 pm
Contact:

Translation: How to get the text in original language

#1 Post by srksrk 68 »

Hi,

I have the issue of getting the original untranslated game's text from a translated text that is passed to the say function. The problem is as follows. I created a hook to the say function like this:

Code: Select all

        my_old_say = renpy.exports.say
        
        def my_say(who, what, *args, **kwargs):
            
            <do something specific with who, what and the arguments>
            return my_old_say(who, what, *args, **kwargs)
    
        renpy.exports.say = my_say
Now the say function is always called with the translated text if a translation is active. My question is if it is possible to somehow get the text in the original language instead, maybe with some other method/hook.

What I am doing is to trigger a lip synchronized talking animation of the character that is currently saying the text that is passed to the say function. This is working almost perfectly, and I do need the translated text for this because lip animation would be different for different languages. So far, so good.

Additionally, I am playing sound files for any text breadcrump enclosed in "*" symboles passed to the say function, i.e. for any text of format "*<some text>*" I play a file "_<some text>.mp3". This works as long as the text inside the "*" symbols is not translated.

Problem is that the translation is covering everything, including those text enclosed inside the "*" symbols. If I have

Code: Select all

old "*knock* *knock* -- Anybody home?"
new "*klopf* *klopf* -- Jemand zuhause?"
the talking animation works fine, but the file _knock.mp3 is not played because instead the translated game is looking for a file _klopf.mp3. I know I can also put the knock file into the tl folder under the translated name, but I would rather have a solution where such noise files would not have to be translated.

This is why I am asking if there is a possibility to get the old text if the new one is passed to the say function. And this should also work for the identifier based translations, not just string translations:

Code: Select all

translate de <label>_<hash>:
  player_name"*klopf* *klopf* -- Jemand zuhause?"
Is there a solution for this, or even a better way?

srksrk 68
Regular
Posts: 30
Joined: Fri Jul 19, 2019 8:10 pm
Contact:

Re: Translation: How to get the text in original language

#2 Post by srksrk 68 »

OK, since nobody came up with suggestions, I investigated more and came up with a solution that suits my needs. For those who might be interested...

I already mentioned I had a hook to the RenPy say function (see initial post). I now also created a hook to the lookup method of the Translate class:

Code: Select all

        my_old_lookup = renpy.ast.Translate.lookup
        
        def my_lookup(self):
            rv = my_old_lookup(self)

            if rv.what.find("*") >= 0:
                try:
                    if config.default_language is not None and renpy.game.preferences.language is not None:
                        default_what = renpy.game.script.translator.default_translates.get(self.identifier).block[0].what
                    else:
                        default_what = rv.what
                    what_sounds = rv.what.split('*')
                    default_sounds = default_what.split('*')
                    for s in what_sounds:
                        rv.what = rv.what.replace("*"+s+"*","{#my_star}"+s+"{#my_star}{#my_play "+default_sounds.pop(0)+"}")
                except Exception:
                    pass
            return rv
            
        renpy.ast.Translate.lookup = my_lookup
What that coding does is to insert a hidden text tag {#my_play <default_sound>} into any text that is sayed and that contains a possible sound "*<translated_sound>*", where <default_sound> is the untranslated original language representation of <translated_sound>. In the hooked say function, I parse the what string to play all those sounds.

Note: Since the lookup function is for some strange rasons called multiple times for the same string, I have to escape the "*" symbols with another hidden tag {#my_star} so that it will not be replaced multiple times.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]