Ren'Py Translation of text in screen

Evildad

Member
Jan 7, 2019
113
219
Hello, my dears.
I have a problem translating my game.

I have quite a bit of text in my character screen. However, this is not taken into account by renpy when I generate a translation. Can you force it somehow? I've solved it so far with an if query. But that only works to a limited extent.

And because of my bad English, I don't understand the renpy documentation properly.

Code:
screen quest_at_screen () :
    bla
    bla
    bla
   
    vbox:
        style "aufgaben_vbox"
       
        text "That should be translated! renpy doesn't take it into account.":
            style "aufgabe"
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
You need only put _( ) around the text parts of your screen that you want to be included in the translation.

Using your example...

Python:
screen quest_at_screen () :
    bla
    bla
    bla
  
    vbox:
        style "aufgaben_vbox"
      
        text _("That should be translated! renpy doesn't take it into account."):
            style "aufgabe"
 

moskyx

Forum Fanatic
Jun 17, 2019
4,227
13,986
I have one more question. So far it works. With one exception. I have tooltips on my imagebutton. A translation will also be created there. But it will not be adopted...

Code:
hbox:
        style "navi_style"

        xalign 0.5
        yalign 0.87
        $ tooltip = GetTooltip()

        if tooltip:
            text "[tooltip]"   # here also _("") ?
Yeah about the _() thing but that would only extract that text string. But that's called an interpolation. So in order to get it translated, you need to code it like that [tooltip!t] at least in the translation script.

So you can just add this lines to your translation script, manually:

Python:
translate english strings: # not really needed as you already have this function, you can keep writing pairs of old/new lines below haus/house
    old "[tooltip]"
    new "[tooltip!t]"
Or you can edit your original code and leave it like this:
Code:
hbox:
        style "navi_style"

        xalign 0.5
        yalign 0.87
        $ tooltip = GetTooltip()

        if tooltip:
            text _("[tooltip!t]")
That way when you hit generate translations again in the SDK you'll get this:
Python:
translate english strings:
    old "[tooltip!t]"
    new "[tooltip!t]"
And, most importantly, future translators to other languages won't forget to add the !t thing
 

Awa.

Newbie
Jun 7, 2022
50
17
Hello, can you tell me how I can automate the "_( )". I'm trying to translate a game that has a lot of "text" and "notify" to change the hand, I tried to create Regex codes to use in Notepad++, but I couldn't.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
I can't speak for Notepad++, but this works for Atom.

Search : ^(\s*)(text\s)(\"|\')(.*)(\"|\')
Replace: $1$2_($3$4$5)

Where () in the search specifies captures groups, in this case
  • --- Beginning of the line ^. (not captured)
  • (1) An unknown number of spaces \s*.
  • (2) The word "text" followed by a space text\s.
  • (3) A double quote or single quote. \" <or |> \'.
  • (4) Any number of characters .*.
  • (5) A double quote or single quote. \" <or |> \'.

Then the replacement includes each of the capture groups as $1, $2, $3, $4 and $5. Then inserts the characters _( and ) before capture group #3 and after capture group #5.

I'm not a regex person. I'm sure there are alternate and probably better ways to do this. All I can say, is it works in Atom.

It does have a flaw though. I'm checking for double quotes or single quotes. If there were a string like text "Don't do this! - it would convert badly, as the single quote within the word "don't" would cause issues. Again... I'm not a regex person.

The reason I check for text\s\" (text followed by space followed by quotes) is hopefully to avoid converting lines which already are marked for translation.

Keep in mind text is not the only screen statement that could be translated. You mentioned notify as at least one example, I'm sure you'll come across others.
 
Last edited:
  • Like
Reactions: osanaiko

Awa.

Newbie
Jun 7, 2022
50
17
I can't speak for Notepad++, but this works for Atom.

Search : ^(\s*)(text\s)(\"|\')(.*)(\"|\')
Replace: $1$2_($3$4$5)

Where () in the search specifies captures groups, in this case
  • --- Beginning of the line ^. (not captured)
  • (1) An unknown number of spaces \s*.
  • (2) The word "text" followed by a space text\s.
  • (3) A double quote or single quote. \" or | \'.
  • (4) Any number of characters .*.
  • (5) A double quote or single quote. \" or | \'.

Then the replacement includes each of the capture groups as $1, $2, $3, $4 and $5. Then inserts the characters _( and ) before capture group #3 and after capture group #5.

I'm not a regex person. I'm sure there are alternate and probably better ways to do this. All I can say, is it works in Atom.

It does have a flaw though. I'm checking for double quotes or single quotes. If there were a string like text "Don't do this! - it would convert badly, as the single quote within the word "don't" would cause issues. Again... I'm not a regex person.

The reason I check for text\s\" (text followed by space followed by quotes) is hopefully to avoid converting lines which already are marked for translation.

Keep in mind text is not the only screen statement that could be translated. You mentioned notify as at least one example, I'm sure you'll come across others.
Thanks, I'll test it in notepad++, then I'll see if I'm comfortable making regex codes.
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,553
4,639
It does have a flaw though. I'm checking for double quotes or single quotes. If there were a string like text "Don't do this! - it would convert badly, as the single quote within the word "don't" would cause issues. Again... I'm not a regex person.
Awa.

Ideally the developer would be consistent, and only use " for all the relevant strings... but dev's are also (arguably) human so it would be be good to do a cleanup step first, and then do _("xxx") translation wrapper code insertion second.

That is:

1. Use a text editor global search to find and manually fix any instances of text ' (with an apostrophe) to use double quotes like it should

2. Use a regex like 79flavors suggested, but modified as it only needs to handle text "string to be translated that includ'th apostrophes too" patterns:
Search: ^(\s*)text \"(.*)\"
Replace: $1text _("$2")

You should be able to adapt the search/replace to use other keywords as well. i.e. replace the "text" with "textbutton" etc

3. do some manual checks/searches to see if you can find any patterns that the regex does not catch
 
Last edited:

guest1492

Member
Apr 28, 2018
350
288
Awa.

Notepad++ didn't behave like I expected when searching for ^(\s*)(text\s)(\"|\')(.*)(\"|\')

temp.gif

Anyway, I would try this instead:
Search: ^(\s*)(text)\s*(["'])(.*?)(\3)
Replace: $1$2 _\($3$4$5\)

You can google for sites to "test regular expressions online" if you want to experiment.
 
Last edited:
  • Like
Reactions: osanaiko

moskyx

Forum Fanatic
Jun 17, 2019
4,227
13,986
Awa.

Notepad++ didn't behave like I expected when searching for ^(\s*)(text\s)(\"|\')(.*)(\"|\')

View attachment 3435429

Anyway, I would try this instead:
Search: ^(\s*)(text\s*)(["'])(.*?)(\3)
Replace: $1$2_\($3$4$5\)

You can google for sites to "test regular expressions online" if you want to experiment.
In Search Mode, you should check the box "Extended" instead of "Regular expression"
 

Awa.

Newbie
Jun 7, 2022
50
17
Awa.

Ideally the developer would be consistent, and only use " for all the relevant strings... but dev's are also (arguably) human so it would be be good to do a cleanup step first, and then do _("xxx") translation wrapper code insertion second.

That is:

1. Use a text editor global search to find and manually fix any instances of text ' (with an apostrophe) to use double quotes like it should

2. Use a regex like 79flavors suggested, but modified as it only needs to handle text "string to be translated that includ'th apostrophes too" patterns:
Search: ^(\s*)text \"(.*)\"
Replace: $1text _("$2")

You should be able to adapt the search/replace to use other keywords as well. i.e. replace the "text" with "textbutton" etc

3. do some manual checks/searches to see if you can find any patterns that the regex does not catch
I'm going to try this one now, thanks for your help ;-;
 

Awa.

Newbie
Jun 7, 2022
50
17
Awa.

Ideally the developer would be consistent, and only use " for all the relevant strings... but dev's are also (arguably) human so it would be be good to do a cleanup step first, and then do _("xxx") translation wrapper code insertion second.

That is:

1. Use a text editor global search to find and manually fix any instances of text ' (with an apostrophe) to use double quotes like it should

2. Use a regex like 79flavors suggested, but modified as it only needs to handle text "string to be translated that includ'th apostrophes too" patterns:
Search: ^(\s*)text \"(.*)\"
Replace: $1text _("$2")

You should be able to adapt the search/replace to use other keywords as well. i.e. replace the "text" with "textbutton" etc

3. do some manual checks/searches to see if you can find any patterns that the regex does not catch
the search method worked fine, but I don't know if I did something wrong, or if it's a notepad thing, but the replace code adds the _ but not the ().

1710707382363.png 1710707394883.png
 

Awa.

Newbie
Jun 7, 2022
50
17
Awa.

Notepad++ didn't behave like I expected when searching for ^(\s*)(text\s)(\"|\')(.*)(\"|\')

View attachment 3435429

Anyway, I would try this instead:
Search: ^(\s*)(text)\s*(["'])(.*?)(\3)
Replace: $1$2 _\($3$4$5\)

You can google for sites to "test regular expressions online" if you want to experiment.
it looks like the code worked, thanks, I'll try searching this way to see if I can find code for notify and other parts that renpy doesn't extract.

1710707667264.png