示例#1
0
def convertrc(input_file,
              output_file,
              template_file,
              pot=False,
              duplicatestyle="msgctxt",
              charset=None,
              lang=None,
              sublang=None):
    """reads in input_file using rc, converts using rc2po, writes to output_file"""
    input_store = rc.rcfile(input_file, lang, sublang, encoding=charset)
    convertor = rc2po()
    if template_file is None:
        output_store = convertor.convert_store(input_store,
                                               duplicatestyle=duplicatestyle)
    else:
        template_store = rc.rcfile(template_file,
                                   lang,
                                   sublang,
                                   encoding=charset)
        output_store = convertor.merge_store(template_store,
                                             input_store,
                                             blankmsgstr=pot,
                                             duplicatestyle=duplicatestyle)
    if output_store.isempty():
        return 0
    output_store.serialize(output_file)
    return 1
示例#2
0
def convertrc(input_file, output_file, template_file, pot=False, duplicatestyle="msgctxt", charset=None, lang=None, sublang=None):
    """reads in input_file using rc, converts using rc2po, writes to output_file"""
    input_store = rc.rcfile(input_file, lang, sublang, encoding=charset)
    convertor = rc2po()
    if template_file is None:
        output_store = convertor.convert_store(input_store, duplicatestyle=duplicatestyle)
    else:
        template_store = rc.rcfile(template_file, lang, sublang, encoding=charset)
        output_store = convertor.merge_store(template_store, input_store, blankmsgstr=pot, duplicatestyle=duplicatestyle)
    if output_store.isempty():
        return 0
    output_file.write(output_store.serialize())
    return 1
示例#3
0
 def __init__(self, templatefile, charset="utf-8", lang=None, sublang=None):
     self.templatefile = templatefile
     self.templatestore = rc.rcfile(templatefile, encoding=charset)
     self.inputdict = {}
     self.charset = charset
     self.lang = lang
     self.sublang = sublang
示例#4
0
    def convertfile(storefile):

        input_store = rcfile(storefile)
        convertor = rc2po()
        store = convertor.convert_store(input_store)
        store.rcfile = input_store
        return store
示例#5
0
    def test_convert_double_string(self):
        self.create_testfile(
            "simple.rc",
            """
STRINGTABLE
BEGIN
    IDS_COPIED              "Copied"
    IDS_XCOPIED             "Copied"
END
""",
        )
        self.create_testfile(
            "simple.po",
            """
#: STRINGTABLE.IDS_COPIED
msgid "Copied"
msgstr "Zkopirovano"
""",
        )
        self.run_command(template="simple.rc",
                         i="simple.po",
                         o="output.rc",
                         l="LANG_CZECH")
        with self.open_testfile("output.rc") as handle:
            rc_result = rcfile(handle)
        assert len(rc_result.units) == 2
        assert rc_result.units[0].target == "Zkopirovano"
        assert rc_result.units[1].target == "Copied"
示例#6
0
    def test_convert_comment_dos_eol(self):
        self.create_testfile(
            "simple.rc",
            b"""\r\nSTRINGTABLE\r\nBEGIN\r\n// Comment\r\nIDS_1 "Copied"\r\nEND\r\n""",
        )
        self.create_testfile(
            "simple.po",
            """
#: STRINGTABLE.IDS_1
msgid "Copied"
msgstr "Zkopirovano"
""",
        )
        self.run_command(template="simple.rc",
                         i="simple.po",
                         o="output.rc",
                         l="LANG_CZECH")
        with self.open_testfile("output.rc", "rb") as handle:
            content = handle.read()
            assert (
                content ==
                b"""\r\nSTRINGTABLE\r\nBEGIN\r\n    // Comment\r\n    IDS_1                   "Zkopirovano"\r\nEND\r\n"""
            )
        with self.open_testfile("output.rc") as handle:
            rc_result = rcfile(handle)
        assert len(rc_result.units) == 1
        assert rc_result.units[0].target == "Zkopirovano"
示例#7
0
 def convertfile(storefile, template_store):
     input_store = rcfile()
     input_store.parse(storefile.read())
     convertor = rc2po()
     store = convertor.convert_store(input_store)
     store.rcfile = input_store
     return store
示例#8
0
    def convertfile(storefile):
        from translate.storage.rc import rcfile
        from translate.convert.rc2po import rc2po

        input_store = rcfile(storefile)
        convertor = rc2po()
        store = convertor.convert_store(input_store)
        store.rcfile = input_store
        return store
示例#9
0
 def convertfile(storefile, template_store):
     input_store = rcfile()
     input_store.parse(storefile.read())
     converter = rc2po()
     if template_store:
         store = converter.merge_store(template_store.store.rcfile, input_store)
     else:
         store = converter.convert_store(input_store)
     store.rcfile = input_store
     return store
示例#10
0
 def test_convert(self):
     """Tests the conversion to a po file"""
     self.create_testfile("simple.rc", RC_SOURCE)
     self.create_testfile("simple.po", POFILE)
     self.run_command(
         template="simple.rc", i="simple.po", o="output.rc", l="LANG_CZECH"
     )
     with self.open_testfile("output.rc") as handle:
         rc_result = rcfile(handle)
     assert len(rc_result.units) == 14
     assert rc_result.units[0].target == "Licenční dialog"
示例#11
0
    def test_convert_comment(self):
        self.create_testfile(
            "simple.rc",
            """
STRINGTABLE
BEGIN
    // IDS_COMMENTED        "Comment"
    IDS_COPIED              "Copied"
    IDS_ADJACENT_STRINGS    "Line1 "
                            "Line2"
    IDS_UNTRANSLATED_STRING "This string has no translation. "
                            "It will appear verbatim in the output"
END
""",
        )
        self.create_testfile(
            "simple.po",
            """
#: STRINGTABLE.IDS_COPIED
msgid "Copied"
msgstr "Zkopirovano"
#: STRINGTABLE.IDS_ADJACENT_STRINGS
msgid ""
"Line1 "
"Line2"
msgstr ""
"Čára1 "
"Čára2"
""",
        )
        self.run_command(template="simple.rc",
                         i="simple.po",
                         o="output.rc",
                         l="LANG_CZECH")
        with self.open_testfile("output.rc") as handle:
            rc_result = rcfile(handle)
        assert len(rc_result.units) == 3
        assert rc_result.units[0].target == "Zkopirovano"
        assert rc_result.units[1].target == "Čára1 Čára2"
        assert (
            rc_result.units[2].target ==
            "This string has no translation. It will appear verbatim in the output"
        )
示例#12
0
    def test_convert_popup(self):
        self.create_testfile(
            "simple.rc",
            """
IDR_MAINFRAME MENU
BEGIN
   POPUP "&File"
   BEGIN
       MENUITEM "&New\tCrtl+N",                ID_FILE_NEW
       MENUITEM "&Open...\tCtrl+O",            ID_FILE_OPEN
       MENUITEM "&Exit",                       ID_FILE_CLOSE
   END
   POPUP "&View"
   BEGIN
       MENUITEM "&Toolbar",                    ID_VIEW_STATUS_BAR
   END
   POPUP "&Help"
   BEGIN
       MENUITEM "&About...",                   ID_APP_ABOUT
   END
END
""",
        )
        self.create_testfile(
            "simple.po",
            """
#: MENU.IDR_MAINFRAME.POPUP.CAPTION
msgid "&Help"
msgstr "&Pomoc"
""",
        )
        self.run_command(template="simple.rc",
                         i="simple.po",
                         o="output.rc",
                         l="LANG_CZECH")
        with self.open_testfile("output.rc") as handle:
            rc_result = rcfile(handle)
        assert len(rc_result.units) == 8
        assert rc_result.units[0].target == "&File"
        assert rc_result.units[6].target == "&Pomoc"