Search in sources :

Example 1 with StringSegmenter

use of net.heartsome.cat.converter.StringSegmenter in project translationstudio8 by heartsome.

the class TestWord2007 method docx2Xliff.

public void docx2Xliff() {
    try {
        //			String inputFile = "/home/robert/Desktop/测试简单word文档.docx";
        //			String inputFile = "/home/robert/Desktop/Word2007 for test.docx";
        //			String xliffFile = "/home/robert/workspace/runtime-UltimateEdition.product/testDocxConverter/XLIFF/zh-CN/测试简单word文档.docx.hsxliff";
        //			String sourceLanguage = "en-US";
        //			String targetLanguage = "zh-CN";
        //			String srx = "/home/robert/workspace/newR8/.metadata/.plugins/org.eclipse.pde.core/UltimateEdition.product/net.heartsome.cat.converter/srx/default_rules.srx";
        //			String catalogue = "/home/robert/workspace/newR8/.metadata/.plugins/org.eclipse.pde.core/UltimateEdition.product/net.heartsome.cat.converter/catalogue/catalogue.xml";
        String inputFile = "C:\\Users\\Administrator\\Desktop\\test word 2007 converter\\测试简单word文档.docx";
        //			String inputFile = "C:\\Users\\Administrator\\Desktop\\test word 2007 converter\\Word2007 for test.docx";
        String xliffFile = "E:\\workspaces\\runtime-UltimateEdition.product\\testWord2007Convert\\XLIFF\\zh-CN\\测试简单word文档.docx.hsxliff";
        String sourceLanguage = "en-US";
        String targetLanguage = "zh-CN";
        String srx = "E:\\workspaces\\newR8\\.metadata\\.plugins\\org.eclipse.pde.core\\UltimateEdition.product\\net.heartsome.cat.converter\\srx\\default_rules.srx";
        String catalogue = "E:\\workspaces\\newR8\\.metadata\\.plugins\\org.eclipse.pde.core\\UltimateEdition.product\\net.heartsome.cat.converter\\catalogue\\catalogue.xml";
        StringSegmenter segmenter = new StringSegmenter(srx, sourceLanguage, catalogue);
        // 先解压 docx 文件
        String docxFolderPath = ZipUtil.upZipFile(inputFile, null);
        PathUtil pathUtil = new PathUtil(docxFolderPath);
        // 定义一个 hsxliff 文件的写入方法
        xlfOutput = new XliffOutputer(xliffFile, sourceLanguage, targetLanguage);
        xlfOutput.writeHeader(inputFile, "skeletonFile", true, "UTF-8", "");
        // 先从主文档 document 文件入手
        String docPath = pathUtil.getPackageFilePath(PathConstant.DOCUMENT, false);
        DocumentPart docPart = new DocumentPart(docPath, pathUtil, xlfOutput, segmenter, inputFile, new NullProgressMonitor());
        docPart.converter();
        System.out.println("--------------");
        xlfOutput.outputEndTag();
        // 开始将文件进行压缩
        //			String zipPath = "/home/robert/Desktop/word 2007 skeleton/" + new File(pathUtil.getSuperRoot()).getName();
        String zipPath = "C:\\Users\\Administrator\\Desktop\\word 2007 skeleton\\" + new File(pathUtil.getSuperRoot()).getName();
        ZipUtil.zipFolder(zipPath, pathUtil.getSuperRoot());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            xlfOutput.close();
            System.out.println("----------");
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DocumentPart(net.heartsome.cat.converter.word2007.partOper.DocumentPart) PathUtil(net.heartsome.cat.converter.word2007.common.PathUtil) StringSegmenter(net.heartsome.cat.converter.StringSegmenter) File(java.io.File)

Example 2 with StringSegmenter

use of net.heartsome.cat.converter.StringSegmenter in project translationstudio8 by heartsome.

the class TestWord2007 method testSegDocument.

public void testSegDocument() {
    //		String inputFile = "/home/robert/Desktop/测试简单word文档.docx";
    //		String inputFile = "/home/robert/Desktop/Word2007 for test.docx";
    //		String xliffFile = "/home/robert/workspace/runtime-UltimateEdition.product/testDocxConverter/XLIFF/zh-CN/测试简单word文档.docx.hsxliff";
    //		String sourceLanguage = "en-US";
    //		String targetLanguage = "zh-CN";
    //		String srx = "/home/robert/workspace/newR8/.metadata/.plugins/org.eclipse.pde.core/UltimateEdition.product/net.heartsome.cat.converter/srx/default_rules.srx";
    //		String catalogue = "/home/robert/workspace/newR8/.metadata/.plugins/org.eclipse.pde.core/UltimateEdition.product/net.heartsome.cat.converter/catalogue/catalogue.xml";
    //		String docPath = "/home/robert/Desktop/document.xml";
    String inputFile = "C:\\Users\\Administrator\\Desktop\\test word 2007 converter\\测试简单word文档.docx";
    //		String inputFile = "C:\\Users\\Administrator\\Desktop\\test word 2007 converter\\Word2007 for test.docx";
    String xliffFile = "E:\\workspaces\\runtime-UltimateEdition.product\\testWord2007Convert\\XLIFF\\zh-CN\\测试简单word文档.docx.hsxliff";
    String sourceLanguage = "en-US";
    String targetLanguage = "zh-CN";
    String srx = "E:\\workspaces\\newR8\\.metadata\\.plugins\\org.eclipse.pde.core\\UltimateEdition.product\\net.heartsome.cat.converter\\srx\\default_rules.srx";
    String catalogue = "E:\\workspaces\\newR8\\.metadata\\.plugins\\org.eclipse.pde.core\\UltimateEdition.product\\net.heartsome.cat.converter\\catalogue\\catalogue.xml";
    String docPath = "C:\\Users\\Administrator\\Desktop\\document.xml";
    try {
        StringSegmenter segmenter = new StringSegmenter(srx, sourceLanguage, catalogue);
        // 定义一个 hsxliff 文件的写入方法
        xlfOutput = new XliffOutputer(xliffFile, sourceLanguage, targetLanguage);
        xlfOutput.writeHeader(inputFile, "skeletonFile", true, "UTF-8", "");
        // 先从主文档 document 文件入手
        DocumentPart docPart = new DocumentPart(docPath, null, xlfOutput, segmenter, inputFile, new NullProgressMonitor());
        docPart.testSegFile();
        System.out.println("--------------");
        xlfOutput.outputEndTag();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DocumentPart(net.heartsome.cat.converter.word2007.partOper.DocumentPart) StringSegmenter(net.heartsome.cat.converter.StringSegmenter)

Aggregations

StringSegmenter (net.heartsome.cat.converter.StringSegmenter)2 DocumentPart (net.heartsome.cat.converter.word2007.partOper.DocumentPart)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 File (java.io.File)1 PathUtil (net.heartsome.cat.converter.word2007.common.PathUtil)1