public void close () { if ( writer == null ) return; writer.writeEndDocument(); writer.close(); writer = null; }
/** * Exports only a specific target locale Pensieve to TMX * @param sourceLang The source language of desired translation * @param targetLang The target language of desired translation (or null for all target languages) * @param tmSeeker The TMSeeker to use when reading from the TM * @param tmxWriter The TMXWriter to use when writing out the TMX */ public void exportTmx(LocaleId sourceLang, LocaleId targetLang, ITmSeeker tmSeeker, TMXWriter tmxWriter) throws IOException { checkExportTmxParams(sourceLang, tmSeeker, tmxWriter); try { tmxWriter.writeStartDocument(sourceLang, targetLang, "pensieve", "0.0.1", "sentence", "pensieve", "unknown"); //TODO might eat up too much memory for large TMs Iterator<TranslationUnit> iterator = ((PensieveSeeker) tmSeeker).iterator(); while (iterator.hasNext()) { TranslationUnit tu = iterator.next(); if (isWriteTextUnit(sourceLang, targetLang, tu)) { tmxWriter.writeTUFull(PensieveUtil.convertToTextUnit(tu)); } } tmxWriter.writeEndDocument(); } finally { tmxWriter.close(); } }
@Override protected Event handleStartBatch(final Event event) { // Start TMX writer (one for all input documents) if (tmx == null && params.getGenerateTMX()) { File outFile = new File(params.getTmxOutputPath()); if ( outFile.exists() ) promptShouldOverwrite(); tmx = new TMXWriter(outFile.getAbsolutePath()); tmx.writeStartDocument(sourceLocale, targetLocale, getClass().getName(), null, "paragraph", null, null); } return event; }
tmxWriterApproved.writeEndDocument(); tmxWriterApproved.close(); if ( tmxWriterApproved.getItemCount() == 0 ) { File file = new File(tempTmxPathApproved); file.delete(); tmxWriterUnApproved.writeEndDocument(); tmxWriterUnApproved.close(); if ( tmxWriterUnApproved.getItemCount() == 0 ) { File file = new File(tempTmxPathUnApproved); file.delete(); tmxWriterAlternates.writeEndDocument(); tmxWriterAlternates.close(); if ( tmxWriterAlternates.getItemCount() == 0 ) { File file = new File(tempTmxPathAlternates); file.delete(); tmxWriterLeverage.writeEndDocument(); tmxWriterLeverage.close(); if ( tmxWriterLeverage.getItemCount() == 0 ) { File file = new File(tempTmxPathLeverage); file.delete();
TMXWriter writer = null; try { writer = new TMXWriter(outputPath); writer.writeStartDocument(sourceLocale, targetLocale, null, null, "sentence", "simpleTM", null); stm = conn.createStatement(); attributes.put(NGRPNAME, result.getString(2)); attributes.put(NFILENAME, result.getString(3)); writer.writeItem(tu, attributes); } while ( result.next() ); writer.writeEndDocument(); if ( writer != null ) writer.close(); try { if ( stm != null ) {
private void processStartDocument (Event event) { StartDocument sd = (StartDocument)event.getResource(); // Create the output if ( outputStream == null ) { if (writer == null) { writer = new TMXWriter(outputPath); } else { writer.setPath(outputPath); } } else if ( outputStream != null ) { if (writer == null) { writer = new TMXWriter(new XMLWriter( new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))); } else { writer.setXmlWriter(new XMLWriter( new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))); } } writer.setWriteAllPropertiesAsAttributes(params.isWriteAllPropertiesAsAttributes()); writer.setExpandDuplicateProps(params.isEnableDuplicateProps()); writer.setPropValueSep(params.getPropValueSep()); writer.setGenerateUUID(params.isGenerateUUID()); writer.setNormalizeCodeIds(params.isNormalizeInlineIDs()); writer.writeStartDocument(sd, sd.getLocale(), locale, null, null, segType, "unknown", "text"); }
protected void initializeTMXWriters () { if ( tmxPathApproved != null ) { tmxWriterApproved = new TMXWriter(tempTmxPathApproved); tmxWriterApproved.setLetterCodedMode(useLetterCodes, zeroBasedLetterCodes); tmxWriterApproved.writeStartDocument(manifest.getSourceLocale(), manifest.getTargetLocale(), getClass().getName(), null, null, null, null); } if ( tmxPathUnApproved != null ) { tmxWriterUnApproved = new TMXWriter(tempTmxPathUnApproved); tmxWriterUnApproved.setLetterCodedMode(useLetterCodes, zeroBasedLetterCodes); tmxWriterUnApproved.writeStartDocument(manifest.getSourceLocale(), manifest.getTargetLocale(), getClass().getName(), null, null, null, null); } if ( tmxPathAlternates != null ) { tmxWriterAlternates = new TMXWriter(tempTmxPathAlternates); tmxWriterAlternates.setLetterCodedMode(useLetterCodes, zeroBasedLetterCodes); tmxWriterAlternates.writeStartDocument(manifest.getSourceLocale(), manifest.getTargetLocale(), getClass().getName(), null, null, null, null); } if ( tmxPathLeverage != null ) { tmxWriterLeverage = new TMXWriter(tempTmxPathLeverage); tmxWriterLeverage.setLetterCodedMode(useLetterCodes, zeroBasedLetterCodes); tmxWriterLeverage.writeStartDocument(manifest.getSourceLocale(), manifest.getTargetLocale(), getClass().getName(), null, null, null, null); } }
realPath = LocaleId.replaceVariables(realPath, sourceLocale, targetLocale); tmxWriter = new TMXWriter(realPath); tmxWriter.setUseMTPrefix(params.getUseMTPrefix()); tmxWriter.writeStartDocument(sourceLocale, targetLocale, getClass().getName(), "1", // Version is irrelevant here "sentence", "undefined", "undefined");
/** * Writes a TMX TU element. * @param source the fragment for the source text. * @param target the fragment for the target text. * @param tuid the TUID attribute (can be null). * @param attributes the optional set of attribute to put along with the entry. */ public void writeTU (TextFragment source, TextFragment target, String tuid, Map<String, String> attributes) { writeTU(source, target, tuid, attributes, null); }
String dataType) writeStartDocument(null, sourceLocale, targetLocale, creationTool, creationToolVersion, segType, originalTMFormat, dataType);
/** * Writes a TextUnit (all targets) with all the properties associated to it. * <p>Note: If the srclang in the TMX header is "*all*", you must use * {@link #writeTUFull(ITextUnit, LocaleId)} instead. * @param item The text unit to write. */ public void writeTUFull (ITextUnit item) { writeTUFull(item, srcLoc); }
/** * Writes a given text unit. One TMX TU per segment if the text unit is segment, * or one TU for the full content, if the text unit is not segmented. * @param tu The text unit to output. * @param attributes The optional set of attribute to put along with the entry. */ public void writeItem (ITextUnit tu, Map<String, String> attributes) { if ( !tu.hasTarget(trgLoc) ) { return; // No target } ISegments srcSegs = tu.getSourceSegments(); ISegments trgSegs = tu.getTargetSegments(trgLoc); // Output each segment (handles single-segment entry) String tuId = tu.getId(); for ( Segment srcSeg : srcSegs ) { Segment trgSeg = trgSegs.get(srcSeg.id); if (( trgSeg == null ) || trgSeg.text.isEmpty() ) continue; // No target // Else: output writeTU(srcSeg.text, trgSeg.text, String.format("%s_s%s", tuId, srcSeg.id), attributes); } }
private void processTextUnit (Event event) { writer.writeTUFull(event.getTextUnit()); } }
private void closeAndClean () { if ( tmxWriter != null ) { tmxWriter.writeEndDocument(); tmxWriter.close(); tmxWriter = null; } if ( events != null ) { events.clear(); events = null; } }
tmxWriter = new TMXWriter(tmxOutputPath); tmxWriter.writeStartDocument(sourceLocale, targetLocale, getClass().getCanonicalName(), "1", "sentence", null, "unknown");
srcFrag = qutil.fromCodedHTMLToFragment(srcElem.getContent().toString(), null); trgFrag = qutil.fromCodedHTMLToFragment(trgElem.getContent().toString(), null); tmxWriter.writeTU(srcFrag, trgFrag, null, attributes);
tmx.writeTUFull(alignedTextUnit);
private void closeAndClean () { if ( tmxWriter != null ) { tmxWriter.writeEndDocument(); tmxWriter.close(); tmxWriter = null; } if (( gtt != null ) && ( tmId != null )) { gtt.deleteTM(tmId); } }
resolvedPath = Util.fillInputRootDirectoryVariable(resolvedPath, inputRootDir); resolvedPath = LocaleId.replaceVariables(resolvedPath, sourceLocale, targetLocale); tmx = new TMXWriter(resolvedPath); tmx.writeStartDocument(sourceLocale, targetLocale, getClass().getName(), null, null, null, null);