Page 1 of 1

[Solved]Trouble with translating variables

Posted: Thu Aug 09, 2018 9:50 pm
by birctreel
Hello there! I'm trying to translate my game in second language, where I face a bunch of problems >. <
Like, I'm using a lot of variables in screens, such as characters' data or locations' names:

Code: Select all

    fixed:
        area(1275, 250, 320,870)
        vbox:
            xalign 1
            text _("Sex: ")
            text _("Age: ") ypos 10
            text _("Occupation: ") ypos 20
            text ""
    fixed:
        area(1500, 250, 320,870)
        vbox:
            xalign 0
            text "[Mc.sex]" 
            text "[Mc.age]" ypos 10
            text "[Mc.job]" ypos 20

Code: Select all

screen Map(spot):
    zorder 300
    fixed:
        style_group "page"
        area (547,64,1150,943)
        if spot == 1:
            text [locate.L1] xpos 120 ypos 380
        if spot == 2:
            text [locate.L2] xpos 366 ypos 226

And define those variables, then translate them:

Code: Select all

init python in locate:
    L1=_("House A")
    L2=_("House B")
    
    # Location.rpy:450
    old "House A"
    new "房屋 A"
    # Location.rpy:452
    old "House B"
    new "房屋 B"
    
Problems is I found that doesn't work.
Variables cannot be translated when we use it either in scripts or in screens.
So is there any solution can be used to translate variables?

Thank you for taking time to read my stupid problems QAQ

Re: Trouble with translating variables

Posted: Sun Aug 12, 2018 6:03 am
by korova
When you're using string interpolation, you should indicate that you want it translated
(from documentation)
Translating substitutions

String substitutions can be translated using the !t conversion flag. So the following will be translatable using a combination of the dialogue and string translation systems:

Code: Select all

if mood_points > 5:
    $ mood = _("great")
else:
    $ mood = _("awful")

"I'm feeling [mood!t]."
More details about translations subtilities here : https://www.renpy.org/doc/html/translation.html

Re: Trouble with translating variables

Posted: Wed Aug 15, 2018 8:17 am
by birctreel
korova wrote:
Sun Aug 12, 2018 6:03 am
When you're using string interpolation, you should indicate that you want it translated
(from documentation)
Translating substitutions

String substitutions can be translated using the !t conversion flag. So the following will be translatable using a combination of the dialogue and string translation systems:

Code: Select all

if mood_points > 5:
    $ mood = _("great")
else:
    $ mood = _("awful")

"I'm feeling [mood!t]."
More details about translations subtilities here : https://www.renpy.org/doc/html/translation.html
Ah! Thank you very much! I figure out where the problem happens:
I should not use "[variable]" instead of variable simply, which makes the variable static.
So the right code should be:

Code: Select all

init python in locate:
    L1=_("House A")
    L2=_("House B")
    
    # Location.rpy:450
    old "House A"
    new "房屋 A"
    # Location.rpy:452
    old "House B"
    new "房屋 B"
and

Code: Select all

screen Map(spot):
    zorder 300
    fixed:
        style_group "page"
        area (547,64,1150,943)
        if spot == 1:
            text locate.L1 xpos 120 ypos 380
        if spot == 2:
            text locate.L2 xpos 366 ypos 226

Thank you very much for answering my question!