RegEx to translate RenPy files

Hello,

I'm trying to translate files from a video game created with the Ren'Py Visual Novel Engine (a software game engine with a programming language similar to Python). These files end with a .rpy extension and can be opened in any text editor. I have tried creating a new file type and defining a document structure. It works fine for the RPY files with a simpler structure, but I also have some more complex files and I haven't been able to find RegEx that seem to work. Here is an example:

# game/script/ch1.rpy:34
translate french ch1_308a744b:

# "This is example sentence 1."
"This is example sentence 1."

# game/script/ch1.rpy:38
translate french ch1_baea3297:

# "This is example sentence 2."
"This is example sentence 2."

# game/script/ch1.rpy:160
translate french ch1_7835ba72:

# sato vill cldo opes norm "Some sentences do \"this\" when the author wants to use quotation marks displayed in game."
sato vill cldo opes norm "Some sentences do \"this\" when the author wants to use quotation marks displayed in game."

# game/script/ch1.rpy:161
translate french ch1_fcb8c042:

# taku clot surp weeh "And a last example." with vpunch
taku clot surp weeh "And a last example." with vpunch

Sentences that need to be translated are always between quotation marks. Each sentence is repeated two times, first as a comment (lines starting with #), which must stay in the source language, then as an actual string I need to translate. Sometimes the strings are preceded or followed by a little bit of code (the way the code looks is a bit random).

If I say I only want to translate what's between quotation marks it doesn't work because the sentences in the comments also appears (which means each string appears two times while only one of the two must be translated). It also doesn't work with the \" that are sometimes found within the quotation marks.

I am using Trados Studio 2022 SR1 with the latest update.

emoji
Parents
  • Hello, I recently became interested in Ren'Py, so I created a file format that imports *.rpy into Trados Studio.

    I am using Trados Studio 2022 and the API language is Korean, so the terminology may be different from the English API.

    Here is an explanation of the file format I have created:

    1) Select Project Settings > File Formats > New (N).
    2) Select Regular Expression Delimited Text as the type.
    3) Enter Ren'Py as the File Format Identifier (F) and *.rpy as the File Dialog Wildcard Expression (W). Feel free to enter the rest of the input as you wish.
    4) Ren'Py will then be created as a sub-item of the File Format.
    5) Select File Format Ren'Py > Document Structure in order, then enter the opening and closing patterns and save.

    The Regex's and condition of the pattern I'm currently using are as follows
    Opening pattern: ^(\s*|\s*\b(?!old\b)\w+\s+)"
    Closing pattern: "($|\s+with\s+[a-z]+$)
    Multiple lines: True

    Screenshot of Trados Studio 2022 showing the File Formats configuration window with a new Ren'Py format being added. Fields are populated with regex patterns for opening and closing, and 'Multiple lines' is set to True.

    I made it on the assumption that the abbreviations of the speakers are not separated by spaces. I think you can use it with a little modification.

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 3:10 AM (GMT 1) on 8 Oct 2024]
Reply
  • Hello, I recently became interested in Ren'Py, so I created a file format that imports *.rpy into Trados Studio.

    I am using Trados Studio 2022 and the API language is Korean, so the terminology may be different from the English API.

    Here is an explanation of the file format I have created:

    1) Select Project Settings > File Formats > New (N).
    2) Select Regular Expression Delimited Text as the type.
    3) Enter Ren'Py as the File Format Identifier (F) and *.rpy as the File Dialog Wildcard Expression (W). Feel free to enter the rest of the input as you wish.
    4) Ren'Py will then be created as a sub-item of the File Format.
    5) Select File Format Ren'Py > Document Structure in order, then enter the opening and closing patterns and save.

    The Regex's and condition of the pattern I'm currently using are as follows
    Opening pattern: ^(\s*|\s*\b(?!old\b)\w+\s+)"
    Closing pattern: "($|\s+with\s+[a-z]+$)
    Multiple lines: True

    Screenshot of Trados Studio 2022 showing the File Formats configuration window with a new Ren'Py format being added. Fields are populated with regex patterns for opening and closing, and 'Multiple lines' is set to True.

    I made it on the assumption that the abbreviations of the speakers are not separated by spaces. I think you can use it with a little modification.

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 3:10 AM (GMT 1) on 8 Oct 2024]
Children
No Data