Translation 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
Dreamtale
Newbie
Posts: 24
Joined: Tue Jan 11, 2011 8:15 pm
Contact:

Translation function

#1 Post by Dreamtale » Fri Oct 31, 2014 12:19 pm

Ok, so I have a translation in my game, and now I want some function that takes phrase on one language and return it's translation. Something like this:

Code: Select all

def translate(str):
    return renpy.translation.translate_string(str) # this exact function doesn't do what I want
For example, I have something like this in my translation file:

Code: Select all

# game/scenario.rpy:2315
translate english day2_main1_641d577e:

    # "А теперь марш умываться!"
    "Now go wash yourself!"
And I want to call translate("А теперь марш умываться!") and receive "Now go wash yourself!" or vice versa call translate("Now go wash yourself!") and receive "А теперь марш умываться!"

Is there any way to do so?

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Translation function

#2 Post by PyTom » Fri Oct 31, 2014 6:03 pm

You want the __ (two underscores) function. It doesn't work with the code block translations, only with the translate strings blocks.

Code: Select all

translate english strings:
    old "А теперь марш умываться!"
    new "Now go wash yourself!"

$ s = __("А теперь марш умываться!")
Offhand, why? It'll usually possible to keep a string in the original language until Text translates it.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Dreamtale
Newbie
Posts: 24
Joined: Tue Jan 11, 2011 8:15 pm
Contact:

Re: Translation function

#3 Post by Dreamtale » Sat Nov 01, 2014 5:11 am

PyTom, thanks, but it's not exactly what I wanted. To put it simple, I have text history from here: http://www.renpy.org/wiki/renpy/doc/coo ... xt_History in my project, and when I switch languages during the game and then open text log, phrases displayed in previously selected language. So, I thought that, maybe, I can 'convert' those phrases using some function.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Translation function

#4 Post by PyTom » Sat Nov 01, 2014 10:10 am

The problem with that would be the opposite switch - when you switch from English to Russian, transitions will not occur, since there isn't an English -> Russian translation table.

How common is it to switch languages during the game, anyway?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Google [Bot]