Ren'Py Translator ToolKit  Check-in [4d77326162]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support say parameters
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | 1.4
Files: files | file ages | folders
SHA3-256:4d773261622ecb3cb38f3f3594aaa5732a8626f938fbc6eec5b571a45580fca6
User & Date: Beuc 2020-05-24 13:51:42
Context
2020-05-30
10:37
Bump version Leaf check-in: 99eddf960e user: Beuc tags: trunk
2020-05-24
13:51
Support say parameters check-in: 4d77326162 user: Beuc tags: trunk, 1.4
2020-04-25
15:45
Update current Ren'Py version check-in: d83f78dd26 user: Beuc tags: trunk, 1.3
Changes

Changes to rttk/test_tlparser.py.

48
49
50
51
52
53
54
55
56









57
58
59
60
61
62
63

    def test_extract_dqstrings(self):
        testcase = ur'''    _( 'string " character' ) "Tricky single/double '\" multiple strings 2"'''
        self.assertEqual(tlparser.extract_dqstrings(testcase),
            [{'start': 31, 'end': 74, 'text': ur'''Tricky single/double '\" multiple strings 2'''}])
        testcase = ur'''_( "string \" character" ) "Tricky double/double \"' multiple strings"'''
        self.assertEqual(tlparser.extract_dqstrings(testcase),
            [{'start':  4, 'end': 23, 'text': ur'''string \" character'''},
             {'start': 28, 'end': 69, 'text': ur'''Tricky double/double \"' multiple strings'''}])










    def test_extract_base_string(self):
        self.assertEqual(
            tlparser.extract_base_string(u'''    old "menu title"\n'''),
            {'start': 9, 'end': 19, 'text': u'menu title'})

    def test_extract_dialog_string(self):







<
|
>
>
>
>
>
>
>
>
>







48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

    def test_extract_dqstrings(self):
        testcase = ur'''    _( 'string " character' ) "Tricky single/double '\" multiple strings 2"'''
        self.assertEqual(tlparser.extract_dqstrings(testcase),
            [{'start': 31, 'end': 74, 'text': ur'''Tricky single/double '\" multiple strings 2'''}])
        testcase = ur'''_( "string \" character" ) "Tricky double/double \"' multiple strings"'''
        self.assertEqual(tlparser.extract_dqstrings(testcase),

            [{'start': 28, 'end': 69, 'text': ur'''Tricky double/double \"' multiple strings'''}])
        testcase = ur'''    e "Hello" (show_param="value")'''
        self.assertEqual(tlparser.extract_dialog_string(testcase),
            {'start': 7, 'end': 12, 'text': u'''Hello'''})
        testcase = ur'''    _(")") "Hello" (show_param="value")'''
        self.assertEqual(tlparser.extract_dialog_string(testcase),
            {'start': 12, 'end': 17, 'text': u'''Hello'''})
        testcase = ur'''    _(("char")) "Hello" (show_params=("value1","value2"))'''
        self.assertEqual(tlparser.extract_dialog_string(testcase),
            {'start': 17, 'end': 22, 'text': u'''Hello'''})

    def test_extract_base_string(self):
        self.assertEqual(
            tlparser.extract_base_string(u'''    old "menu title"\n'''),
            {'start': 9, 'end': 19, 'text': u'menu title'})

    def test_extract_dialog_string(self):

Changes to rttk/tlparser.py.

46
47
48
49
50
51
52










53
54
55
56
57




58
59
60
61
62
63
64
65
66
67
68
69
70
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    '''
    def skip_to_delim(pos, delim):
        while pos < len(line) and line[pos] != delim:
            if line[pos] == '\\':
                pos += 1
            pos += 1
        return pos










    pos = 0
    ret = []
    SQ = "'"
    DQ = '"'
    while pos < len(line):




        if line[pos] in (SQ, DQ):
            delim = line[pos]
            pos += 1
            start = pos
            pos = skip_to_delim(pos, delim)
            if pos >= len(line) or line[pos] != delim:
                raise Exception("unterminated string: " + line[start:pos])
            if delim == DQ:
                ret.append({'start':start, 'end':pos, 'text': line[start:pos]})
        pos += 1
    return ret

def extract_dialog_string(dialog_line):
................................................................................
        return res[1]
    return res[0]  # (what)

def extract_base_string(dialog_line):
    res = extract_dqstrings(dialog_line)
    if len(res) == 0:
        return None
    if len(res) > 1:  # (who, what)
        return res[1]
    return res[0]  # (what)

def parse_next_block(lines):
    ret = []
    block_string = {'id':None, 'source':None, 'text':None, 'translation':None}
    while len(lines) > 0:
        line = lines.pop()
        if is_empty(line):







>
>
>
>
>
>
>
>
>
>





>
>
>
>
|




|







 







<
|
<







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
..
89
90
91
92
93
94
95

96

97
98
99
100
101
102
103
    '''
    def skip_to_delim(pos, delim):
        while pos < len(line) and line[pos] != delim:
            if line[pos] == '\\':
                pos += 1
            pos += 1
        return pos
    def skip_paren(pos):
        while pos < len(line) and line[pos] != ')':
            if line[pos] == '(':
                pos = skip_paren(pos+1)
            elif line[pos] in (SQ, DQ):
                delim = line[pos]
                pos += 1
                pos = skip_to_delim(pos, delim)
            pos += 1
        return pos
    pos = 0
    ret = []
    SQ = "'"
    DQ = '"'
    while pos < len(line):
        if line[pos] == '(':
            # Either already _(marked) for translation, either say
            # parameters, so discarded
            pos = skip_paren(pos+1)
        elif line[pos] in (SQ, DQ):
            delim = line[pos]
            pos += 1
            start = pos
            pos = skip_to_delim(pos, delim)
            if pos >= len(line):
                raise Exception("unterminated string: " + line[start:pos])
            if delim == DQ:
                ret.append({'start':start, 'end':pos, 'text': line[start:pos]})
        pos += 1
    return ret

def extract_dialog_string(dialog_line):
................................................................................
        return res[1]
    return res[0]  # (what)

def extract_base_string(dialog_line):
    res = extract_dqstrings(dialog_line)
    if len(res) == 0:
        return None

    return res[0]


def parse_next_block(lines):
    ret = []
    block_string = {'id':None, 'source':None, 'text':None, 'translation':None}
    while len(lines) > 0:
        line = lines.pop()
        if is_empty(line):

Changes to test/input/script.rpy.

89
90
91
92
93
94
95


96
97
98
99
        "dupmenuentry":
            pass

    voice "path/to/file"
    e "voiced text"

    b "「unicode characters♪」"



    call dup

    return







>
>




89
90
91
92
93
94
95
96
97
98
99
100
101
        "dupmenuentry":
            pass

    voice "path/to/file"
    e "voiced text"

    b "「unicode characters♪」"

    e "say parameters with string" (show_param="é")

    call dup

    return

Changes to test/input/testtl-fr_FR.po.

1192
1193
1194
1195
1196
1197
1198




#: game/script.rpy:92
msgid "voiced text"
msgstr "texte vocalisé"

#: game/script.rpy:95
msgid "「unicode characters♪」"
msgstr "「caractères unicode♪」"











>
>
>
>
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
#: game/script.rpy:92
msgid "voiced text"
msgstr "texte vocalisé"

#: game/script.rpy:95
msgid "「unicode characters♪」"
msgstr "「caractères unicode♪」"

#: game/script.rpy:97
msgid "say parameters with string"
msgstr "say avec paramètre chaîne de charactère"

Changes to test/output_expected/script.rpy.

139
140
141
142
143
144
145






146
147
148
149
150
151
152

# game/script.rpy:95
translate french start_7e46d471:

    # b "「unicode characters♪」"
    b "「caractères unicode♪」"







translate french strings:

    # game/script.rpy:7
    old "Eileen"
    new "Hélène personnage dup"

    # game/script.rpy:33







>
>
>
>
>
>







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

# game/script.rpy:95
translate french start_7e46d471:

    # b "「unicode characters♪」"
    b "「caractères unicode♪」"

# game/script.rpy:97
translate french start_d0996e27:

    # e "say parameters with string" (show_param="é")
    e "say avec paramètre chaîne de charactère" (show_param="é")

translate french strings:

    # game/script.rpy:7
    old "Eileen"
    new "Hélène personnage dup"

    # game/script.rpy:33