file2xliff4j
Class PoImporter

java.lang.Object
  extended by file2xliff4j.PoImporter
All Implemented Interfaces:
Converter

public class PoImporter
extends java.lang.Object
implements Converter

Import a GNU Portable Object Template to XLIFF.

Author:
Weldon Whipple <weldon@lingotek.com>

Field Summary
 
Fields inherited from interface file2xliff4j.Converter
BLKSIZE, formatSuffix, skeletonSuffix, startXliff, stylesTSkeletonSuffix, tSkeletonSuffix, xliffSuffix, xmlDeclaration
 
Constructor Summary
PoImporter()
          Create a GNU Portable Object Template Importer
 
Method Summary
 ConversionStatus convert(ConversionMode mode, java.util.Locale language, java.lang.String phaseName, int maxPhase, java.nio.charset.Charset nativeEncoding, FileType nativeFileType, java.lang.String nativeFileName, java.lang.String baseDir, Notifier notifier)
          Deprecated. 
 ConversionStatus convert(ConversionMode mode, java.util.Locale language, java.lang.String phaseName, int maxPhase, java.nio.charset.Charset nativeEncoding, FileType nativeFileType, java.lang.String nativeFileName, java.lang.String baseDir, Notifier notifier, SegmentBoundary boundary, java.io.StringWriter generatedFileName)
          Convert a GNU Portable Object Template to XLIFF, creating XLIFF and a skeleton file as output.
 ConversionStatus convert(ConversionMode mode, java.util.Locale language, java.lang.String phaseName, int maxPhase, java.nio.charset.Charset nativeEncoding, FileType nativeFileType, java.lang.String nativeFileName, java.lang.String baseDir, Notifier notifier, SegmentBoundary boundary, java.io.StringWriter generatedFileName, java.util.Set<f2xutils.XMLTuXPath> skipList)
          Convert a GNU Portable Object Template to XLIFF, creating XLIFF and a skeleton file as output.
 java.lang.Object getConversionProperty(java.lang.String property)
          Return an object representing a format-specific (and converter-specific) property.
 FileType getFileType()
          Return the file type that this converter handles.
static java.nio.charset.Charset readPoEncoding(java.lang.String poFileName)
          Passed the name of a GNU Portable Object Template, try to determine its encoding.
 void setConversionProperty(java.lang.String property, java.lang.Object value)
          Set a format-specific property that might affect the way that the conversion occurs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PoImporter

public PoImporter()
Create a GNU Portable Object Template Importer

Method Detail

convert

public ConversionStatus convert(ConversionMode mode,
                                java.util.Locale language,
                                java.lang.String phaseName,
                                int maxPhase,
                                java.nio.charset.Charset nativeEncoding,
                                FileType nativeFileType,
                                java.lang.String nativeFileName,
                                java.lang.String baseDir,
                                Notifier notifier,
                                SegmentBoundary boundary,
                                java.io.StringWriter generatedFileName)
                         throws ConversionException
Convert a GNU Portable Object Template to XLIFF, creating XLIFF and a skeleton file as output.

Specified by:
convert in interface Converter
Parameters:
mode - The mode of conversion (to or from XLIFF). It should be ConversionMode.TO_XLIFF in this case.
language - The language of the original messages (that are to be translated).
nativeEncoding - The encoding of the PO template. If this parameter is null, the importer will read the file's Content-Type header, if present. If not present in the file (or if unchanged from the default "CHARSET"), use the default encoding for the language, as specified in the GNU gettext Utilities document.
phaseName - The target phase-name. This value is ignored.
maxPhase - The maximum phase number. This value is ignored.
nativeFileType - The type of the original native file. This value is ignored (It is assumed to be PO.)
nativeFileName - The name of the Portable Object Template file.
baseDir - The directory that contains the input PO template--from which we will read the input file. This is also the directory in which the output xliff and skeleton files are written. The output files will be named as follows:
  • <nativeFileName>.xliff
  • <nativeFileName>.skeleton
notifier - Instance of a class that implements the Notifier interface (to send notifications in case of conversion error).
boundary - The boundary on which to segment translation units (e.g., on paragraph or sentence boundaries). This value is ignored. (Each string becomes one segment in the XLIFF.)
generatedFileName - If non-null, the converter will write the name of the file (without parent directories) to which the generated XLIFF file was written.
Returns:
Indicator of the status of the conversion.
Throws:
ConversionException - If a conversion exception is encountered.

convert

public ConversionStatus convert(ConversionMode mode,
                                java.util.Locale language,
                                java.lang.String phaseName,
                                int maxPhase,
                                java.nio.charset.Charset nativeEncoding,
                                FileType nativeFileType,
                                java.lang.String nativeFileName,
                                java.lang.String baseDir,
                                Notifier notifier,
                                SegmentBoundary boundary,
                                java.io.StringWriter generatedFileName,
                                java.util.Set<f2xutils.XMLTuXPath> skipList)
                         throws ConversionException
Convert a GNU Portable Object Template to XLIFF, creating XLIFF and a skeleton file as output.

Specified by:
convert in interface Converter
Parameters:
mode - The mode of conversion (to or from XLIFF). It should be ConversionMode.TO_XLIFF in this case.
language - The language of the original messages (that are to be translated).
nativeEncoding - The encoding of the PO template. If this parameter is null, the importer will read the file's Content-Type header, if present. If not present in the file (or if unchanged from the default "CHARSET"), use the default encoding for the language, as specified in the GNU gettext Utilities document.
phaseName - The target phase-name. This value is ignored.
maxPhase - The maximum phase number. This value is ignored.
nativeFileType - The type of the original native file. This value is ignored (It is assumed to be PO.)
nativeFileName - The name of the Portable Object Template file.
baseDir - The directory that contains the input PO template--from which we will read the input file. This is also the directory in which the output xliff and skeleton files are written. The output files will be named as follows:
  • <nativeFileName>.xliff
  • <nativeFileName>.skeleton
notifier - Instance of a class that implements the Notifier interface (to send notifications in case of conversion error).
boundary - The boundary on which to segment translation units (e.g., on paragraph or sentence boundaries). This value is ignored. (Each string becomes one segment in the XLIFF.)
generatedFileName - If non-null, the converter will write the name of the file (without parent directories) to which the generated XLIFF file was written.
skipList - (Not used by this converter.)
Returns:
Indicator of the status of the conversion.
Throws:
ConversionException - If a conversion exception is encountered.

convert

@Deprecated
public ConversionStatus convert(ConversionMode mode,
                                           java.util.Locale language,
                                           java.lang.String phaseName,
                                           int maxPhase,
                                           java.nio.charset.Charset nativeEncoding,
                                           FileType nativeFileType,
                                           java.lang.String nativeFileName,
                                           java.lang.String baseDir,
                                           Notifier notifier)
                         throws ConversionException
Deprecated. 

Convert a GNU Portable Object Template to XLIFF, creating XLIFF and a skeleton file as output.

Specified by:
convert in interface Converter
Parameters:
mode - The mode of conversion (to or from XLIFF). It should be ConversionMode.TO_XLIFF in this case.
language - The language of the original messages (that are to be translated).
nativeEncoding - The encoding of the PO template. If this parameter is null, the importer will read the file's Content-Type header, if present. If not present in the file (or if unchanged from the default "CHARSET"), use the default encoding for the language, as specified in the GNU gettext Utilities document.
phaseName - The target phase-name. This value is ignored.
maxPhase - The maximum phase number. This value is ignored.
nativeFileType - The type of the original native file. This value is ignored (It is assumed to be PO.)
nativeFileName - The name of the Portable Object Template file.
baseDir - The directory that contains the input PO template file--from which we will read the input file. This is also the directory in which the output xliff and skeleton files are written. The output files will be named as follows:
  • <nativeFileName>.xliff
  • <nativeFileName>.skeleton
notifier - Instance of a class that implements the Notifier interface (to send notifications in case of conversion error).
Returns:
Indicator of the status of the conversion.
Throws:
ConversionException - If a conversion exception is encountered.

getConversionProperty

public java.lang.Object getConversionProperty(java.lang.String property)
Return an object representing a format-specific (and converter-specific) property.

Specified by:
getConversionProperty in interface Converter
Parameters:
property - The name of the property to return.
Returns:
An Object that represents the property's value.

getFileType

public FileType getFileType()
Return the file type that this converter handles. (For importers, this means the file type that it imports to XLIFF; for exporters, it is the file type that ie exports to (from XLIFF).

Specified by:
getFileType in interface Converter
Returns:
the GNU Portable Object (Template) type.

readPoEncoding

public static java.nio.charset.Charset readPoEncoding(java.lang.String poFileName)
                                               throws ConversionException
Passed the name of a GNU Portable Object Template, try to determine its encoding. Emacs creates the following PO boilerplate when invoked with a non-existent .po file as an argument:
 # SOME DESCRIPTIVE TITLE.
 # Copyright (C) YEAR Free Software Foundation, Inc.
 # FIRST AUTHOR , YEAR.
 #
 #, fuzzy
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
 "Last-Translator: FULL NAME \n"
 "Language-Team: LANGUAGE \n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=CHARSET\n"
 "Content-Transfer-Encoding: 8bit\n"
 
This method will (accordingly), look for the first msgstr value (which includes all the immediately following quoted strings, concatenated together) and look for a charset indication.

Parameters:
poFileName - The name of a POT file--fully qualified
Returns:
The encoding the file uses (or null if not apparent).
Throws:
ConversionException - if an error is encountered.

setConversionProperty

public void setConversionProperty(java.lang.String property,
                                  java.lang.Object value)
                           throws ConversionException
Set a format-specific property that might affect the way that the conversion occurs.

Note: This converter needs no format-specific properties. If any are passed, they will be silently ignored.

Specified by:
setConversionProperty in interface Converter
Parameters:
property - The name of the property
value - The value of the property
Throws:
ConversionException - If the property isn't recognized (and if it matters).