public class TMXWriter extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CREATIONID |
| Constructor and Description |
|---|
TMXWriter(String path)
Creates a new TMXWriter object.
|
TMXWriter(XMLWriter writer)
Creates a new TMXWriter object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the current output document if one is opened.
|
int |
getItemCount()
Gets the number of TU elements that have been written in the current output document.
|
LocaleId |
getSrcLoc() |
LocaleId |
getTrgLoc() |
boolean |
isWriteAllPropertiesAsAttributes()
Write all TU level properties as TMX attributes?
|
void |
setAltTranslationOption(String pattern)
Sets a pattern used to indicate which entries to include when using the
writeAlternate(AltTranslation, TextFragment) method. |
void |
setAutoGenerateTuId(boolean autoGenerateTuId) |
void |
setExclusionOption(String pattern)
Sets a pattern of content to not output.
|
void |
setExpandDuplicateProps(boolean expandDuplicateProps) |
void |
setGenerateUUID(boolean generateUUID) |
void |
setLetterCodedMode(boolean value,
boolean zeroBased)
Sets the flag indicating whether the writer should output
letter-coded content (e.g.
|
void |
setNormalizeCodeIds(boolean normalizeCodeIds) |
protected void |
setPath(String path) |
void |
setPropValueSep(String propValueSep) |
void |
setQuoteMode(int quoteMode)
Sets the default quote mode to use in escaping the TMX segment content (1 is the default).
|
void |
setSrcLoc(LocaleId srcLoc) |
void |
setTradosWorkarounds(boolean value)
Sets the flag indicating whether the writer should output
workaround codes specific for Trados.
|
void |
setTrgLoc(LocaleId trgLoc) |
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).
|
void |
setWriteAllPropertiesAsAttributes(boolean writeAllPropertiesAsAttributes)
If true then all TU level properties will be written as TMX attributes.
|
protected void |
setXmlWriter(XMLWriter writer) |
protected void |
writeAllPropertiesAsAttibutes(XMLWriter writer,
Set<String> names,
ITextUnit item) |
protected void |
writeAllPropertiesAsAttibutes(XMLWriter writer,
Set<String> names,
TextContainer item) |
void |
writeAlternate(AltTranslation alt,
TextFragment srcOriginal)
Writes the data of an
AltTranslation to this TMX output. |
void |
writeAlternates(ITextUnit tu,
LocaleId trgLoc)
Writes the entries of an
AltTranslationsAnnotation
annotation(s) of a given text unit to the TMX document. |
void |
writeEndDocument()
Writes the end of the TMX document.
|
void |
writeItem(ITextUnit tu,
Map<String,String> attributes)
Writes a given text unit.
|
protected void |
writeProp(String name,
String value) |
protected void |
writeResourceLevelProperties(Set<String> names,
ITextUnit item,
TextFragment srcSegment) |
void |
writeStartDocument(LocaleId sourceLocale,
LocaleId targetLocale,
String creationTool,
String creationToolVersion,
String segType,
String originalTMFormat,
String dataType)
Writes the start of the TMC document.
|
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.
|
void |
writeTU(TextFragment source,
TextFragment target,
String tuid,
Map<String,String> attributes)
Writes a TMX TU element.
|
void |
writeTU(TextFragment source,
TextFragment target,
String tuid,
Map<String,String> attributes,
LocaleId altTrgLoc)
Writes a TMX TU element.
|
void |
writeTUFull(ITextUnit item)
Writes a TextUnit (all targets) with all the properties associated to it.
|
void |
writeTUFull(ITextUnit item,
LocaleId sourceLocId)
Writes a TextUnit (all targets) with all the properties associated to it.
|
protected void |
writeTUV(TextFragment frag,
LocaleId locale,
TextContainer contForProp)
Writes a TUV element.
|
public static final String CREATIONID
public TMXWriter(String path)
path - The full path of the TMX document to create.
If another document exists already it will be overwritten.public TMXWriter(XMLWriter writer)
writer - an instance of an XMLWriter to use.
If another document exists already it will be overwritten.protected void setPath(String path)
protected void setXmlWriter(XMLWriter writer)
public void close()
public int getItemCount()
public void setTradosWorkarounds(boolean value)
value - true to output Trados-specific workarounds. False otherwise.public void setLetterCodedMode(boolean value,
boolean zeroBased)
value - true to output letter-coded content. False otherwise.zeroBased - true to have 0-based code, false for unaltered IDs.public void setExclusionOption(String pattern)
pattern - the regular expression pattern of the contents to not output.public void setAltTranslationOption(String pattern)
writeAlternate(AltTranslation, TextFragment) method. When this pattern is set to null (the default)
all entries are included.pattern - the regular expression of the origin(s) to include. Use null to include all entries.public void setQuoteMode(int quoteMode)
quoteMode - 0=no quote escaped, 1=apos and quot, 2=#39 and quot,
and 3=quot only.public void setUseMTPrefix(boolean useMTPrefix)
creationid attribute is set to Util.MTFLAG.useMTPrefix - true to use a prefix for entries originating from MT.public void writeStartDocument(LocaleId sourceLocale, LocaleId targetLocale, String creationTool, String creationToolVersion, String segType, String originalTMFormat, String dataType)
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.public void writeStartDocument(StartDocument startDocument, LocaleId sourceLocale, LocaleId targetLocale, String creationTool, String creationToolVersion, String segType, String originalTMFormat, String dataType)
StartDocument to allow access
to header props and notes stored as Propertys.startDocument - The StartDocument event.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.public void writeEndDocument()
public void writeItem(ITextUnit tu, Map<String,String> attributes)
tu - The text unit to output.attributes - The optional set of attribute to put along with the entry.public void writeAlternates(ITextUnit tu, LocaleId trgLoc)
AltTranslationsAnnotation
annotation(s) of a given text unit to the TMX document.tu - text unit to use.trgLoc - target locale.public void writeAlternate(AltTranslation alt, TextFragment srcOriginal)
AltTranslation to this TMX output.
Which entries will be output also depends on what patterns have been set with
setAltTranslationOption(String) and setExclusionOption(String).
alt - the alternate translation.srcOriginal - the default source (coming from the segment or container where
the annotation was attached to).public void writeTU(TextFragment source, TextFragment target, String tuid, Map<String,String> attributes)
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.public void writeTU(TextFragment source, TextFragment target, String tuid, Map<String,String> attributes, LocaleId altTrgLoc)
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).public void writeTUFull(ITextUnit item)
Note: If the srclang in the TMX header is "*all*", you must use
writeTUFull(ITextUnit, LocaleId) instead.
item - The text unit to write.public void writeTUFull(ITextUnit item, LocaleId sourceLocId)
item - The text unit to write.sourceLocId - The source locale id to use for this TU.protected void writeResourceLevelProperties(Set<String> names, ITextUnit item, TextFragment srcSegment)
protected void writeAllPropertiesAsAttibutes(XMLWriter writer, Set<String> names, ITextUnit item)
protected void writeAllPropertiesAsAttibutes(XMLWriter writer, Set<String> names, TextContainer item)
protected void writeTUV(TextFragment frag, LocaleId locale, TextContainer contForProp)
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.public void setWriteAllPropertiesAsAttributes(boolean writeAllPropertiesAsAttributes)
writeAllPropertiesAsAttributes - true to write out all TU level properties as TMX attributes.public boolean isWriteAllPropertiesAsAttributes()
public void setExpandDuplicateProps(boolean expandDuplicateProps)
public void setPropValueSep(String propValueSep)
public void setGenerateUUID(boolean generateUUID)
public void setNormalizeCodeIds(boolean normalizeCodeIds)
public LocaleId getSrcLoc()
public void setSrcLoc(LocaleId srcLoc)
public LocaleId getTrgLoc()
public void setTrgLoc(LocaleId trgLoc)
public void setAutoGenerateTuId(boolean autoGenerateTuId)
Copyright © 2021. All rights reserved.