Package net.sf.okapi.common.filterwriter
Class TMXWriter
- java.lang.Object
-
- net.sf.okapi.common.filterwriter.TMXWriter
-
public class TMXWriter extends Object
Writer for TMX documents.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCREATIONID
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the current output document if one is opened.intgetItemCount()Gets the number of TU elements that have been written in the current output document.LocaleIdgetSrcLoc()LocaleIdgetTrgLoc()booleanisWriteAllPropertiesAsAttributes()Write all TU level properties as TMX attributes?voidsetAltTranslationOption(String pattern)Sets a pattern used to indicate which entries to include when using thewriteAlternate(AltTranslation, TextFragment)method.voidsetAutoGenerateTuId(boolean autoGenerateTuId)voidsetExclusionOption(String pattern)Sets a pattern of content to not output.voidsetExpandDuplicateProps(boolean expandDuplicateProps)voidsetGenerateUUID(boolean generateUUID)voidsetLetterCodedMode(boolean value, boolean zeroBased)Sets the flag indicating whether the writer should output letter-coded content (e.g.voidsetNormalizeCodeIds(boolean normalizeCodeIds)protected voidsetPath(String path)voidsetPropValueSep(String propValueSep)voidsetQuoteMode(int quoteMode)Sets the default quote mode to use in escaping the TMX segment content (1 is the default).voidsetSrcLoc(LocaleId srcLoc)voidsetTradosWorkarounds(boolean value)Sets the flag indicating whether the writer should output workaround codes specific for Trados.voidsetTrgLoc(LocaleId trgLoc)voidsetUseMTPrefix(boolean useMTPrefix)Sets the flag indicating if entries originating from MT should be written with a special prefix in the source text (forcing a fuzzy match).voidsetWriteAllPropertiesAsAttributes(boolean writeAllPropertiesAsAttributes)If true then all TU level properties will be written as TMX attributes.protected voidsetXmlWriter(XMLWriter writer)protected voidwriteAllPropertiesAsAttibutes(XMLWriter writer, Set<String> names, ITextUnit item)protected voidwriteAllPropertiesAsAttibutes(XMLWriter writer, Set<String> names, TextContainer item)voidwriteAlternate(AltTranslation alt, TextFragment srcOriginal)Writes the data of anAltTranslationto this TMX output.voidwriteAlternates(ITextUnit tu, LocaleId trgLoc)Writes the entries of anAltTranslationsAnnotationannotation(s) of a given text unit to the TMX document.voidwriteEndDocument()Writes the end of the TMX document.voidwriteItem(ITextUnit tu, Map<String,String> attributes)Writes a given text unit.protected voidwriteProp(String name, String value)protected voidwriteResourceLevelProperties(Set<String> names, ITextUnit item, TextFragment srcSegment)voidwriteStartDocument(LocaleId sourceLocale, LocaleId targetLocale, String creationTool, String creationToolVersion, String segType, String originalTMFormat, String dataType)Writes the start of the TMC document.voidwriteStartDocument(StartDocument startDocument, LocaleId sourceLocale, LocaleId targetLocale, String creationTool, String creationToolVersion, String segType, String originalTMFormat, String dataType)Writes the start of the TMC document.voidwriteTU(TextFragment source, TextFragment target, String tuid, Map<String,String> attributes)Writes a TMX TU element.voidwriteTU(TextFragment source, TextFragment target, String tuid, Map<String,String> attributes, LocaleId altTrgLoc)Writes a TMX TU element.voidwriteTUFull(ITextUnit item)Writes a TextUnit (all targets) with all the properties associated to it.voidwriteTUFull(ITextUnit item, LocaleId sourceLocId)Writes a TextUnit (all targets) with all the properties associated to it.protected voidwriteTUV(TextFragment frag, LocaleId locale, TextContainer contForProp)Writes a TUV element.
-
-
-
Field Detail
-
CREATIONID
public static final String CREATIONID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TMXWriter
public TMXWriter(String path)
Creates a new TMXWriter object. Creates a new TMX document.- Parameters:
path- The full path of the TMX document to create. If another document exists already it will be overwritten.
-
TMXWriter
public TMXWriter(XMLWriter writer)
Creates a new TMXWriter object. Creates a new TMX document.- Parameters:
writer- an instance of an XMLWriter to use. If another document exists already it will be overwritten.
-
-
Method Detail
-
setPath
protected void setPath(String path)
-
setXmlWriter
protected void setXmlWriter(XMLWriter writer)
-
close
public void close()
Closes the current output document if one is opened.
-
getItemCount
public int getItemCount()
Gets the number of TU elements that have been written in the current output document.- Returns:
- The number of TU elements written in the current output document.
-
setTradosWorkarounds
public void setTradosWorkarounds(boolean value)
Sets the flag indicating whether the writer should output workaround codes specific for Trados.- Parameters:
value- true to output Trados-specific workarounds. False otherwise.
-
setLetterCodedMode
public void setLetterCodedMode(boolean value, boolean zeroBased)Sets the flag indicating whether the writer should output letter-coded content (e.g. to work for OmegaT).- Parameters:
value- true to output letter-coded content. False otherwise.zeroBased- true to have 0-based code, false for unaltered IDs.
-
setExclusionOption
public void setExclusionOption(String pattern)
Sets a pattern of content to not output. The given pattern is matched against the source content of each item, if it matches, the item is not written.- Parameters:
pattern- the regular expression pattern of the contents to not output.
-
setAltTranslationOption
public void setAltTranslationOption(String pattern)
Sets a pattern used to indicate which entries to include when using thewriteAlternate(AltTranslation, TextFragment)method. When this pattern is set to null (the default) all entries are included.- Parameters:
pattern- the regular expression of the origin(s) to include. Use null to include all entries.
-
setQuoteMode
public void setQuoteMode(int quoteMode)
Sets the default quote mode to use in escaping the TMX segment content (1 is the default).- Parameters:
quoteMode- 0=no quote escaped, 1=apos and quot, 2=#39 and quot, and 3=quot only.
-
setUseMTPrefix
public void setUseMTPrefix(boolean useMTPrefix)
Sets the flag indicating if entries originating from MT should be written with a special prefix in the source text (forcing a fuzzy match). An entry is deemed originating from MT when itscreationidattribute is set to.Util.MTFLAG- Parameters:
useMTPrefix- true to use a prefix for entries originating from MT.
-
writeStartDocument
public void writeStartDocument(LocaleId sourceLocale, LocaleId targetLocale, String creationTool, String creationToolVersion, String segType, String originalTMFormat, String dataType)
Writes the start of the TMC document.- Parameters:
sourceLocale- The source locale (must be set).targetLocale- The target locale (must be set).creationTool- The identifier of the creation tool (can be null).creationToolVersion- The version of the creation tool (can be null).segType- The type of segments in the output.originalTMFormat- The identifier for the original TM engine (can be null).dataType- The type of data to output.
-
writeStartDocument
public void writeStartDocument(StartDocument startDocument, LocaleId sourceLocale, LocaleId targetLocale, String creationTool, String creationToolVersion, String segType, String originalTMFormat, String dataType)
Writes the start of the TMC document. IncludesStartDocumentto allow access to header props and notes stored asPropertys.- Parameters:
startDocument- TheStartDocumentevent.sourceLocale- The source locale (must be set).targetLocale- The target locale (must be set).creationTool- The identifier of the creation tool (can be null).creationToolVersion- The version of the creation tool (can be null).segType- The type of segments in the output.originalTMFormat- The identifier for the original TM engine (can be null).dataType- The type of data to output.
-
writeEndDocument
public void writeEndDocument()
Writes the end of the TMX document.
-
writeItem
public void writeItem(ITextUnit tu, Map<String,String> attributes)
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.- Parameters:
tu- The text unit to output.attributes- The optional set of attribute to put along with the entry.
-
writeAlternates
public void writeAlternates(ITextUnit tu, LocaleId trgLoc)
Writes the entries of anAltTranslationsAnnotationannotation(s) of a given text unit to the TMX document.- Parameters:
tu- text unit to use.trgLoc- target locale.
-
writeAlternate
public void writeAlternate(AltTranslation alt, TextFragment srcOriginal)
Writes the data of anAltTranslationto this TMX output.Which entries will be output also depends on what patterns have been set with
setAltTranslationOption(String)andsetExclusionOption(String).- Parameters:
alt- the alternate translation.srcOriginal- the default source (coming from the segment or container where the annotation was attached to).
-
writeTU
public void writeTU(TextFragment source, TextFragment target, String tuid, Map<String,String> attributes)
Writes a TMX TU element.- Parameters:
source- the fragment for the source text.target- the fragment for the target text.tuid- the TUID attribute (can be null).attributes- the optional set of attribute to put along with the entry.
-
writeTU
public void writeTU(TextFragment source, TextFragment target, String tuid, Map<String,String> attributes, LocaleId altTrgLoc)
Writes a TMX TU element.- Parameters:
source- the fragment for the source text.target- the fragment for the target text.tuid- the TUID attribute (can be null).attributes- the optional set of attribute to put along with the entry.altTrgLoc- the target locale id to use (in case it is different from the default one, use null to get the default).
-
writeTUFull
public void writeTUFull(ITextUnit item)
Writes a TextUnit (all targets) with all the properties associated to it.Note: If the srclang in the TMX header is "*all*", you must use
writeTUFull(ITextUnit, LocaleId)instead.- Parameters:
item- The text unit to write.
-
writeTUFull
public void writeTUFull(ITextUnit item, LocaleId sourceLocId)
Writes a TextUnit (all targets) with all the properties associated to it.- Parameters:
item- The text unit to write.sourceLocId- The source locale id to use for this TU.
-
writeResourceLevelProperties
protected void writeResourceLevelProperties(Set<String> names, ITextUnit item, TextFragment srcSegment)
-
writeAllPropertiesAsAttibutes
protected void writeAllPropertiesAsAttibutes(XMLWriter writer, Set<String> names, ITextUnit item)
-
writeAllPropertiesAsAttibutes
protected void writeAllPropertiesAsAttibutes(XMLWriter writer, Set<String> names, TextContainer item)
-
writeTUV
protected void writeTUV(TextFragment frag, LocaleId locale, TextContainer contForProp)
Writes a TUV element.- Parameters:
frag- the TextFragment for the content of this TUV. This can be a segment of a TextContainer.locale- the locale for this TUV.contForProp- the TextContainer that has the properties to write for this TUV, or null for no properties.
-
setWriteAllPropertiesAsAttributes
public void setWriteAllPropertiesAsAttributes(boolean writeAllPropertiesAsAttributes)
If true then all TU level properties will be written as TMX attributes.- Parameters:
writeAllPropertiesAsAttributes- true to write out all TU level properties as TMX attributes.
-
isWriteAllPropertiesAsAttributes
public boolean isWriteAllPropertiesAsAttributes()
Write all TU level properties as TMX attributes?- Returns:
- true if all TU level properties will be written, false otherwise.
-
setExpandDuplicateProps
public void setExpandDuplicateProps(boolean expandDuplicateProps)
-
setPropValueSep
public void setPropValueSep(String propValueSep)
-
setGenerateUUID
public void setGenerateUUID(boolean generateUUID)
-
setNormalizeCodeIds
public void setNormalizeCodeIds(boolean normalizeCodeIds)
-
getSrcLoc
public LocaleId getSrcLoc()
-
setSrcLoc
public void setSrcLoc(LocaleId srcLoc)
-
getTrgLoc
public LocaleId getTrgLoc()
-
setTrgLoc
public void setTrgLoc(LocaleId trgLoc)
-
setAutoGenerateTuId
public void setAutoGenerateTuId(boolean autoGenerateTuId)
-
-