Page 1 of 1

Problems translating strings with variables

Posted: Wed Oct 19, 2022 6:54 pm
by TioNick
When using Ren'py to generate the translation strings, there is often text that Ren'py cannot scan, and this is where I use the feature.

translate {} strings:

old ""
new ""

But there are strings that have variables outside the text, and because of this, I can't translate them.

Examples:
1
text "Day: {}".format(day)
text "Playtime: {}H {}M {}S".format(hours, minutes, seconds)

2
use text_stat("- ", " times -", phoenix_petted_counter)
use text_stat("- ", " days...", (game.day - phoenix_fed_counter) )

3
text "Unlocked: "+str(len(filter(lambda x: x[1][3] is True, menu_items)))+"/[menu_items_length]" size 12 pos (24, 70)

It seems that the translation script reads the whole line, and because it doesn't understand, I think it ignores the translation attempt.

And what I would like to know is...
Is there a command I can use, so that the translation ignores everything that is not inside the quotation marks and translates the marked text?

Do i have to try to contact the dev, and wait for him to make the necessary modifications in good faith, at the risk of breaking his game?

Re: Problems translating strings with variables

Posted: Wed Oct 19, 2022 7:16 pm
by Ocelot
In short, yes, you have to modify the game to make those string work with translation framework.

Example 1 should look like that, for example:

Code: Select all

text __("Day: {}").format(day)
text __("Playtime: {}H {}M {}S").format(hours, minutes, seconds)
Examples 2 and 3 depends on how it works and what should and should not be translated.

To make game translatable, you should take possibility of translation into account during development. Otherwise you risk doing something that severely complicates translation.

Re: Problems translating strings with variables

Posted: Thu Oct 20, 2022 6:42 pm
by TioNick
It worked, and to think that it was there in the translation documentation, but I didn't understand it for lack of a practical example.

About example 2 and 3 I did it like this

Code: Select all

use text_stat("- ", __(" times -"), phoenix_petted_counter)
use text_stat("- ", __(" days..."), (game.day - phoenix_fed_counter) )

Code: Select all

text  __("Unlocked: ")+str(len(filter(lambda x: x[1][3] is True, menu_items)))+"/[menu_items_length]" size 12 pos (24, 70)
and it worked :D
Thank you very much.

Too bad I couldn't get it to work on this one

Code: Select all

 menu:
                s1 "..."
                "(Buy a bouquet from a street vendor.)" if getbuket and torgovka1:
                    $torgovka1=False
                    jump buketik1
                
                __("(Look for casual earnings.) (shest)") if chasi>=6 and not workblock and not zakat and not policeangry>=2:
                    call workproverka from _call_workproverka
                    jump afterwork
                __("(Watch passersby.) (dva)") if chasi>=2 and not workblock and not zakat and not policeangry>=2: 
                    call workproverka from _call_workproverka_4
                    jump sleju

                "Go away.":
                    stop sound
                    scene black
                    window hide
                    call screen town
gave this error here

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/town.rpy", line 97: expected menuitem
    __("(Look for casual earnings.) (shest)") if chasi>=6 and not workblock and not zakat and not policeangry>=2: 
    ^

Ren'Py Version: Ren'Py 7.4.8.1895
Thu Oct 20 19:09:44 2022
both (shest) and (dva) are targets that do not appear in the game, but call up a clock image to the left of the text.

https://imgur.com/m7NVe01

Re: Problems translating strings with variables

Posted: Thu Oct 20, 2022 7:03 pm
by Ocelot
Menu options are already marked by translation framework. And be careful with immediate translation function, it can break if you are changing languages in-game. Ideally you should only be using it in dynamically buildt strings (amount of which you should try to minimise in favor of interpolation and simply choosing one of prewritten immutable strings). Majority of stuff should be marked with "add to set of translatable strings" ( _() ).

In your case you are probably modifying strings in the choice screen. Modifying string makes it different from the translation framework point of view, so it is not translated when it displayed. Do not modify menu choice strings, this is never nessesary.

Re: Problems translating strings with variables

Posted: Thu Oct 20, 2022 10:57 pm
by TioNick
Thanks, I'll finish the translation, and mark the non-translatable texts to send to the game dev in the future, to see if he can make the necessary changes.

If you want you can mark the topic as solved.