Package translate :: Package storage :: Module base :: Class TranslationUnit
[hide private]
[frames] | no frames]

Class TranslationUnit

source code

object --+
         |
        TranslationUnit
Known Subclasses:

Base class for translation units.

Our concept of a translation unit is influenced heavily by XLIFF: http://www.oasis-open.org/committees/xliff/documents/xliff-specification.htm

As such most of the method- and variable names borrows from XLIFF terminology.

A translation unit consists of the following:

Instance Methods [hide private]
 
__init__(self, source)
Constructs a TranslationUnit containing the given source string.
source code
Boolean
__eq__(self, other)
Compares two TranslationUnits.
source code
string
getid(self)
A unique identifier for this unit.
source code
 
getcontext(self)
Get the message context.
source code
 
markreviewneeded(self, needsreview=True, explanation=None)
Marks the unit to indicate whether it needs review.
source code
 
istranslated(self)
Indicates whether this unit is translated.
source code
 
istranslatable(self)
Indicates whether this unit can be translated.
source code
 
isfuzzy(self)
Indicates whether this unit is fuzzy.
source code
 
markfuzzy(self, value=True)
Marks the unit as fuzzy or not.
source code
 
isheader(self)
Indicates whether this unit is a header.
source code
 
isreview(self)
Indicates whether this unit needs review.
source code
 
isblank(self)
Used to see if this unit has no source or target string.
source code
 
hasplural(self)
Tells whether or not this specific unit has plural strings.
source code
 
merge(self, otherunit, overwrite=False, comments=True)
Do basic format agnostic merging.
source code
 
unit_iter(self)
Iterator that only returns this unit.
source code
 
getunits(self)
This unit in a list.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

    Source
 
getsourcelanguage(self) source code
    Target
 
settarget(self, target)
Sets the target string to the given value.
source code
Integer
gettargetlen(self)
Returns the length of the target string.
source code
 
gettargetlanguage(self) source code
    Notes
 
getnotes(self, origin=None)
Returns all notes about this unit.
source code
 
addnote(self, text, origin=None)
Adds a note (comment).
source code
 
removenotes(self)
Remove all the translator's notes.
source code
    Locations
List
getlocations(self)
A list of source code locations.
source code
 
addlocation(self, location)
Add one location to the list of locations.
source code
 
addlocations(self, location)
Add a location or a list of locations.
source code
    Errors
 
adderror(self, errorname, errortext)
Adds an error message to this unit.
source code
Dictionary
geterrors(self)
Get all error messages.
source code
Class Methods [hide private]
 
buildfromunit(cls, unit)
Build a native unit from a foreign unit, preserving as much information as possible.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, source)
(Constructor)

source code 

Constructs a TranslationUnit containing the given source string.

Overrides: object.__init__

__eq__(self, other)
(Equality operator)

source code 

Compares two TranslationUnits.

Parameters:
Returns: Boolean
Returns True if the supplied TranslationUnit equals this unit.

gettargetlen(self)

source code 

Returns the length of the target string.

Returns: Integer

Note: Plural forms might be combined.

getid(self)

source code 

A unique identifier for this unit.

Returns: string
an identifier for this unit that is unique in the store

Derived classes should override this in a way that guarantees a unique identifier for each unit in the store.

getlocations(self)

source code 

A list of source code locations.

Returns: List

Note: Shouldn't be implemented if the format doesn't support it.

addlocation(self, location)

source code 

Add one location to the list of locations.

Note: Shouldn't be implemented if the format doesn't support it.

addlocations(self, location)

source code 

Add a location or a list of locations.

Note: Most classes shouldn't need to implement this, but should rather implement addlocation().

Warning: This method might be removed in future.

getnotes(self, origin=None)

source code 

Returns all notes about this unit.

It will probably be freeform text or something reasonable that can be synthesised by the format. It should not include location comments (see getlocations()).

addnote(self, text, origin=None)

source code 

Adds a note (comment).

Parameters:
  • text (string) - Usually just a sentence or two.
  • origin (string) - Specifies who/where the comment comes from. Origin can be one of the following text strings:
    • 'translator'
    • 'developer', 'programmer', 'source code' (synonyms)

adderror(self, errorname, errortext)

source code 

Adds an error message to this unit.

Parameters:
  • errorname (string) - A single word to id the error.
  • errortext (string) - The text describing the error.

markreviewneeded(self, needsreview=True, explanation=None)

source code 

Marks the unit to indicate whether it needs review.

Parameters:
  • needsreview - Defaults to True.
  • explanation - Adds an optional explanation as a note.

istranslated(self)

source code 

Indicates whether this unit is translated.

This should be used rather than deducing it from .target, to ensure that other classes can implement more functionality (as XLIFF does).

istranslatable(self)

source code 

Indicates whether this unit can be translated.

This should be used to distinguish real units for translation from header, obsolete, binary or other blank units.

isblank(self)

source code 

Used to see if this unit has no source or target string.

Note: This is probably used more to find translatable units, and we might want to move in that direction rather and get rid of this.