Otter TMXTMX 的 Java 类库
Otter 是一个用于读写 Translation Memory Exchange (TMX) 文档的 Java 类库。要求 Java 7 支持。
示例代码:
TMXReader reader = TestUtil.getTMXReader("/header.tmx"); List<TMXEvent> events = readEvents(reader); assertNotNull(events); checkEvent(events.get(0), START_TMX); // Check the header Header header = events.get(0).getHeader(); assertNotNull(header); assertEquals("TRADOS Translator's Workbench for Windows", header.getCreationTool()); assertEquals("Edition 8 Build 863", header.getCreationToolVersion()); assertEquals("sentence", header.getSegType()); assertEquals("TW4Win 2.0 Format", header.getTmf()); assertEquals("EN-US", header.getAdminLang()); assertEquals("EN-US", header.getSrcLang()); assertEquals("rtf", header.getDataType()); // Optional ones assertEquals(new TMXDateParser().parseDate("20100223T044327Z"), header.getCreationDate()); assertEquals("TESTERSON", header.getCreationId()); assertNull(header.getEncoding()); assertNull(header.getChangeDate()); assertNull(header.getChangeId()); List<Property> properties = header.getProperties(); assertEquals(3, properties.size()); checkProperty(properties.get(0), "type1", "Property", null, null); checkProperty(properties.get(1), "type2", "Property with o-encoding", "ASCII", null); checkProperty(properties.get(2), "type3", "Property with lang \"fr\"", null, "fr"); List<Note> notes = header.getNotes(); assertEquals(2, notes.size()); assertEquals(new Note("This is a note with an encoding.").setEncoding("ASCII"), notes.get(0)); assertEquals(new Note("This is a note with lang \"en\".").setLang("en"), notes.get(1)); checkEvent(events.get(1), END_TMX);
评论