[Solved]Trouble with translating variables

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
User avatar
birctreel
Regular
Posts: 53
Joined: Wed Dec 20, 2017 7:17 am
Projects: Knell of st.Godhrkar
Organization: -Andinomie-
Tumblr: birctreel
Location: Beijing, China
Contact:

[Solved]Trouble with translating variables

#1 Post 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
Last edited by birctreel on Wed Aug 15, 2018 8:17 am, edited 1 time in total.

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: Trouble with translating variables

#2 Post 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

User avatar
birctreel
Regular
Posts: 53
Joined: Wed Dec 20, 2017 7:17 am
Projects: Knell of st.Godhrkar
Organization: -Andinomie-
Tumblr: birctreel
Location: Beijing, China
Contact:

Re: Trouble with translating variables

#3 Post 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!

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]