Translating string variables depending on other variable? (toggleable localizing names)

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
mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Translating string variables depending on other variable? (toggleable localizing names)

#1 Post by mikolajspy »

Hi!
So I came up with some idea for my game, but I can't figure out how to make it work.
I have persistent variable to toggle True/False from Preferences menu, that should affect certain translation words and phrases in languages other than English.

I figured how to do it with normal dialogues, but I got stuck at strings to translate.
If someone were thinking about something similar, here's code:

Code: Select all

translate language labelname_code:
    if persistent.local_names:
        r "Line with persitent value True"
    else:
        r "Line with persitent value False"
Of course, if player changes variable while on that line, it won't change immediately, but after reading previous line and entering this one, it changes.
And yes, I assume players might want to change it in mid-game. It's a small cosmetic thing, so I don't want them to force restart game.

Basically I change my character names depending on situation, so I tried wrapping them in __( ) *double underscore* and that works, Ren'Py catches them as separate strings for translation. Now comes the hard part, how to translate them based on my persistent variable?

I tried several combinations like:

Code: Select all

    old "Rose"
    if persistent.local_names:
        new "Róża"
    else:
        new "Rose"
or

Code: Select all

    if persistent.local_names:
        old "Rose"
        new "Róża"
    else:
        old "Rose"
        new "Rose"
But I got 'parsing failed', unknown statement pointing at 'if'...

Is it even possible to do it?

Alternatively I'm considering doing another translation set, like 'polish' and 'polish_localized' and swap between them, but that would increase size of the game a tiny bit, doubling most of the lines (not to mention lots of copy-pasting common lines)... But it will also allow to replace dialogue translations immediately, so it's not that bad.

Or maybe there's some option to reference already translated lines and only add few additional?

Any other possible solutions?

Or should I just give up on toggleable localized names and settle either for English names or localized in translation?

Ana
Regular
Posts: 61
Joined: Sun Oct 12, 2014 5:56 pm
Contact:

Re: Translating string variables depending on other variable? (toggleable localizing names)

#2 Post by Ana »

I think if you use something like:

Code: Select all

    if persistent.local_names == true:
        $ rname = "Andrzej"
    else:
        $ rname = "Andrew"
and also:

Code: Select all

define r = DynamicCharacter("rname", color="#fe96a7")
or something along the lines of that, and then use [rname] or [r] in the actual body of the text. I haven't really figured out how to use persistents properly, but I think you may be missing the == true/false part of it.

mikolajspy
Regular
Posts: 169
Joined: Sun Jun 04, 2017 12:05 pm
Completed: Too many, check signature
Deviantart: mikolajspy
Location: Wrocław, Poland
Contact:

Re: Translating string variables depending on other variable? (toggleable localizing names)

#3 Post by mikolajspy »

Ana wrote: Tue Apr 24, 2018 8:33 pm I think if you use something like: (...)
That's how I have the names set up for changes in the game, but I didn't thought about changing language-depending variables in main script!

Good idea, maybe if I put it in a function that will run each time the player toggles button it might work...
But then I will have to also run this function each time the name is going to change, probably like:

Code: Select all

$rname = NameChange()
That will run trough set of if/else checking what language is turned on and if localized names option is also on and will return correct version to use.
But this solution will require me to check if all languages are implemented, I'd like to have some more universal approach that will be accesible in translation files.
Ana wrote: Tue Apr 24, 2018 8:33 pm (...) and then use [rname] or [r] in the actual body of the text
That unfortunately won't work, because in few languages (Polish for example) there are things like "noun variety" which changes writing of name slightly depending on context.
I guess I'll settle for if/else of entire line which has name.

If anyone has other suggestions, let me know!

Ana
Regular
Posts: 61
Joined: Sun Oct 12, 2014 5:56 pm
Contact:

Re: Translating string variables depending on other variable? (toggleable localizing names)

#4 Post by Ana »

mikolajspy wrote: Wed Apr 25, 2018 4:53 am
Ana wrote: Tue Apr 24, 2018 8:33 pm I think if you use something like: (...)
That's how I have the names set up for changes in the game, but I didn't thought about changing language-depending variables in main script!

Good idea, maybe if I put it in a function that will run each time the player toggles button it might work...
But then I will have to also run this function each time the name is going to change, probably like:

Code: Select all

$rname = NameChange()
That will run trough set of if/else checking what language is turned on and if localized names option is also on and will return correct version to use.
But this solution will require me to check if all languages are implemented, I'd like to have some more universal approach that will be accesible in translation files.
Ana wrote: Tue Apr 24, 2018 8:33 pm (...) and then use [rname] or [r] in the actual body of the text
That unfortunately won't work, because in few languages (Polish for example) there are things like "noun variety" which changes writing of name slightly depending on context.
I guess I'll settle for if/else of entire line which has name.

If anyone has other suggestions, let me know!
I'm not too sure of the solution to the first thing you mentioned (I really haven't worked with this type of persistent before, sorry... the button toggle could work though), but for your second part you mentioned (with the [r]), if you're first writing it in English, and if you can predict that it'll be in a certain tense (i.e. with Anna -> z Anią) you can probably set up something similar to what was above, but instead something like: [r1] for tense1 (Ania), [r2] for tense2 (Ani), tense3 (Aniu) etc., but somehow define each tense as a different variable in the Polish version but define each corresponding variable with the same name in the English version. That could solve the noun variety problem, but it may be tedious to go through the script just for this, especially since you'll likely be doing this for multiple characters. I feel like you may have already done something like this, though. Nevertheless, good luck!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]