def convert_Xliff2Tmx(self, src, dst):
     fin = open(src, 'r', encoding = "utf-8")
     data = fin.read()
     xliff_file = xlifffile.parsestring(data)
     tmx_file = tmxfile()
     for node in xliff_file.unit_iter():
         tmx_file.addtranslation(node.source, "en", node.target, "th")
     tmx_file.savefile(dst)
     QMessageBox.information(self, "Information", "Converting was done successfully")
    def test_xliff_roundtrip_unknown(self):
        with open(TEST_MRK, "rb") as handle:
            source = handle.read()

        store = xlifffile.parsestring(source)
        string = rich_to_xliff_string(store.units[0].rich_source)
        self.assertEqual('T: <mrk mtype="protected">%s</mrk>', string)
        store.units[0].rich_source = xliff_string_to_rich(string)
        self.assertEqual(source, bytes(store))
 def convert_Xliff2Text(self, src, dst):
     fin = open(src, 'r', encoding = "utf-8")
     data = fin.read()
     xliff_file = xlifffile.parsestring(data)
     txt_file = open(dst, 'w', encoding='utf-8')
     for node in xliff_file.unit_iter():
         txt_file.write(node.source + delimiter + node.target + '\n')
     txt_file.close()
     QMessageBox.information(self, "Information", "Converting was done successfully")
    def test_xliff_roundtrip(self):
        with open(TEST_X, "rb") as handle:
            source = handle.read()

        store = xlifffile.parsestring(source)
        string = rich_to_xliff_string(store.units[0].rich_source)
        self.assertEqual(
            'T: <x id="INTERPOLATION" equiv-text="{{ angular }}"/>', string)
        store.units[0].rich_source = xliff_string_to_rich(string)
        self.assertEqual(source, bytes(store))
Exemple #5
0
    def test_xliff_roundtrip_unknown(self):
        source = b'''<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
  <file datatype="xml" source-language="en-US" target-language="en-US" original="Translation Test">
    <body>
      <group id="body">
        <trans-unit id="1761676329" size-unit="char" translate="yes" xml:space="preserve">
          <source>T: <mrk mtype="protected">%s</mrk></source>
        </trans-unit>
      </group>
    </body>
  </file>
</xliff>
'''
        store = xlifffile.parsestring(source)
        string = rich_to_xliff_string(store.units[0].rich_source)
        self.assertEqual('T: <mrk mtype="protected">%s</mrk>', string)
        store.units[0].rich_source = xliff_string_to_rich(string)
        self.assertEqual(source, bytes(store))
 def convert_Xliff2Excel(self, src, dst):
     if not os.path.exists(dst):
         dst_wb = openpyxl.Workbook()
         ss_sheet = dst_wb['Sheet']
         ss_sheet.title = 'transmem'
         dst_wb.save(dst)
     dst_wb = openpyxl.load_workbook(dst)
     dst_ws = dst_wb['transmem']
     lines = open(src, encoding='utf-8').read().strip().split('\n')
     dst_ws.cell(1, 1).value = 'en'
     dst_ws.cell(1, 2).value = 'th'
     fin = open(src, 'r', encoding = "utf-8")
     data = fin.read()
     xliff_file = xlifffile.parsestring(data)
     row = 2
     for node in xliff_file.unit_iter():
         dst_ws.cell(row, 1).value = node.source
         dst_ws.cell(row, 2).value = node.target
         row += 1
     dst_wb.save(dst)
     QMessageBox.information(self, "Information", "Converting was done successfully")
    def test_xliff_roundtrip_unknown(self):
        source = b'''<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
  <file datatype="xml" source-language="en-US" target-language="en-US" original="Translation Test">
    <body>
      <group id="body">
        <trans-unit id="1761676329" size-unit="char" translate="yes" xml:space="preserve">
          <source>T: <mrk mtype="protected">%s</mrk></source>
        </trans-unit>
      </group>
    </body>
  </file>
</xliff>
'''
        store = xlifffile.parsestring(source)
        string = rich_to_xliff_string(store.units[0].rich_source)
        self.assertEqual(
            'T: <mrk mtype="protected">%s</mrk>',
            string
        )
        store.units[0].rich_source = xliff_string_to_rich(string)
        self.assertEqual(source, bytes(store))