Exemplo n.º 1
0
    def convert_dialog(self, s, loc, toks):
        out = []
        out.append(toks.block_id)
        out.append(" ")
        out.append(toks.block_type)
        if toks.caption:
            out.append(" ")
            out.append(toks.pre_caption)
            out.append("CAPTION ")  # The string caption

            name = rc.generate_dialog_caption_name(toks.block_type,
                                                   toks.block_id[0])
            msgid = toks.caption[1:-1]
            if msgid in self.inputdict:
                if name in self.inputdict[msgid]:
                    out.append('"' + self.inputdict[msgid][name] + '"')
                elif EMPTY_LOCATION in self.inputdict[msgid]:
                    out.append('"' + self.inputdict[msgid][EMPTY_LOCATION] +
                               '"')
            else:
                out.append(toks.caption)

            out.extend(toks.post_caption)  # The rest of the options
            out.append(NL)
        else:
            out.append(" ")
            out.extend(toks.post_caption)  # The rest of the options
            out.append(NL)

        out.append(BLOCK_START)
        out.append(NL)

        for c in toks.controls:

            out.append("    ")
            if len(c[0]) >= 16:
                out.append(c[0])
                # If more than 16 char, put it on a new line to align it.
                out.append("\n" + " " * (16 + 4))
            else:
                out.append(c[0].ljust(16))

            tmp = []

            name = rc.generate_dialog_control_name(toks.block_type,
                                                   toks.block_id[0],
                                                   c.id_control[0],
                                                   c.values_[1])
            msgid = c[1][1:-1]
            if c[1].startswith(("'", '"')) and msgid in self.inputdict:
                if name in self.inputdict[msgid]:
                    tmp.append('"' + self.inputdict[msgid][name] + '"')
                elif EMPTY_LOCATION in self.inputdict[msgid]:
                    tmp.append('"' + self.inputdict[msgid][EMPTY_LOCATION] +
                               '"')
            elif is_iterable_but_not_string(c[1]):
                tmp.append(" | ".join(c[1]))
            else:
                tmp.append(c[1])

            for a in c[2:]:
                if is_iterable_but_not_string(a):
                    tmp.append(" | ".join(a))
                else:
                    tmp.append(a)

            out.append(",".join(tmp))
            out.append(NL)

        out.append(BLOCK_END)

        return out
Exemplo n.º 2
0
    def convert_dialog(self, s, loc, toks):
        yield toks.block_id[0]
        yield " "
        yield toks.block_type
        if toks.caption:
            yield " "
            yield toks.pre_caption
            yield "CAPTION "  # The string caption

            name = rc.generate_dialog_caption_name(toks.block_type, toks.block_id[0])
            msgid = toks.caption[1:-1]
            if msgid in self.inputdict:
                if name in self.inputdict[msgid]:
                    yield '"' + self.inputdict[msgid][name] + '"'
                elif EMPTY_LOCATION in self.inputdict[msgid]:
                    yield '"' + self.inputdict[msgid][EMPTY_LOCATION] + '"'
            else:
                yield toks.caption

            yield from toks.post_caption  # The rest of the options
            yield NL
        else:
            yield " "
            yield from toks.post_caption  # The rest of the options
            yield NL

        yield BLOCK_START
        yield NL
        addnl = False

        for c in toks.controls:

            if isinstance(c, str):
                yield from self.convert_comment(addnl, c)
                addnl = True
                continue
            if addnl:
                yield NL
                addnl = False
            yield "    "
            c0 = c[0]
            if len(c0[0]) >= 16:
                yield c0[0]
                # If more than 16 char, put it on a new line to align it.
                yield NL + " " * (16 + 4)
            else:
                yield c0[0].ljust(16)

            tmp = []

            name = rc.generate_dialog_control_name(
                toks.block_type, toks.block_id[0], c.id_control[0], c.values_[1]
            )
            msgid = c[1][1:-1]
            if c[1].startswith(("'", '"')) and msgid in self.inputdict:
                if name in self.inputdict[msgid]:
                    tmp.append('"' + self.inputdict[msgid][name] + '"')
                elif EMPTY_LOCATION in self.inputdict[msgid]:
                    tmp.append('"' + self.inputdict[msgid][EMPTY_LOCATION] + '"')
            elif is_iterable_but_not_string(c[1]):
                tmp.append(" | ".join(c[1]))
            else:
                tmp.append(c[1])

            for a in c[2:]:
                if is_iterable_but_not_string(a):
                    tmp.append(" | ".join(a))
                else:
                    tmp.append(a)

            yield ",".join(tmp)
            yield NL

        yield BLOCK_END
Exemplo n.º 3
0
    def convert_dialog(self, s, loc, toks):
        yield toks.block_id[0]
        yield " "
        yield toks.block_type
        if toks.caption:
            yield " "
            yield toks.pre_caption
            yield "CAPTION "  # The string caption

            name = rc.generate_dialog_caption_name(toks.block_type,
                                                   toks.block_id[0])
            msgid = toks.caption[1:-1]
            if msgid in self.inputdict:
                if name in self.inputdict[msgid]:
                    yield '"' + self.inputdict[msgid][name] + '"'
                elif EMPTY_LOCATION in self.inputdict[msgid]:
                    yield '"' + self.inputdict[msgid][EMPTY_LOCATION] + '"'
            else:
                yield toks.caption

            yield from toks.post_caption  # The rest of the options
            yield NL
        else:
            yield " "
            yield from toks.post_caption  # The rest of the options
            yield NL

        yield BLOCK_START
        yield NL
        addnl = False

        for c in toks.controls:

            if isinstance(c, str):
                yield from self.convert_comment(addnl, c)
                addnl = True
                continue
            if addnl:
                yield NL
                addnl = False
            yield "    "
            c0 = c[0]
            if len(c0[0]) >= 16:
                yield c0[0]
                # If more than 16 char, put it on a new line to align it.
                yield NL + " " * (16 + 4)
            else:
                yield c0[0].ljust(16)

            tmp = []

            # collect initial quoted items to form msgid
            i = 1
            while isinstance(c[i], str) and c[i].startswith(("'", '"')):
                i = i + 1
            msgid = "".join(cn[1:-1] for cn in c[1:i])

            name = rc.generate_dialog_control_name(toks.block_type,
                                                   toks.block_id[0],
                                                   c.id_control[0], c[i])

            # append translation if available, otherwise use as is
            if msgid in self.inputdict:
                if name in self.inputdict[msgid]:
                    tmp.append('"' + self.inputdict[msgid][name] + '"')
                elif EMPTY_LOCATION in self.inputdict[msgid]:
                    tmp.append('"' + self.inputdict[msgid][EMPTY_LOCATION] +
                               '"')
            else:
                if i > 1:
                    tmp.append(" ".join(c[1:i]))

            # and the remaining items, comma separated
            for a in c[i:]:
                if is_iterable_but_not_string(a):
                    tmp.append(" | ".join(a))
                else:
                    tmp.append(a)

            yield ",".join(tmp)
            yield NL

        yield BLOCK_END