Class TMXWriter


  • public class TMXWriter
    extends Object
    Writer for TMX documents.
    • 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 the writeAlternate(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 its creationid attribute 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. Includes StartDocument to allow access to header props and notes stored as Propertys.
        Parameters:
        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.
      • 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 an AltTranslationsAnnotation annotation(s) of a given text unit to the TMX document.
        Parameters:
        tu - text unit to use.
        trgLoc - target locale.
      • 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.
      • writeProp

        protected void writeProp​(String name,
                                 String value)
      • writeAllPropertiesAsAttibutes

        protected void writeAllPropertiesAsAttibutes​(XMLWriter writer,
                                                     Set<String> names,
                                                     ITextUnit 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)