Classes that represent various storage formats for localization.
Base classes for storage interfaces.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of TranslationUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Base class for stores for multiple translation units of type UnitClass.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
The class of units that will be instantiated and used by this class
alias of TranslationUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Base class for translation units.
Our concept of a translation unit is influenced heavily by XLIFF.
As such most of the method- and variable names borrows from XLIFF terminology.
A translation unit consists of the following:
A source string. This is the original translatable text.
A target string. This is the translation of the source.
Zero or more notes on the unit. Notes would typically be some comments from a translator on the unit, or some comments originating from the source code.
Zero or more locations. Locations indicate where in the original source code this unit came from.
Zero or more errors. Some tools (eg.
pofilter
) can run checks on translations and
produce error messages.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
class to aid in benchmarking Translate Toolkit stores.
Removes the given directory.
Creates sample files for benchmarking.
Parses all the files in the test directory into memory.
Parses placeables.
Represents a translate project bundle (zip archive).
Append the given file to the project with the given filename, marked
to be of type ftype
(‘src’, ‘trans’, ‘tgt’).
delete_orig – If True
, as set by
convert_forward()
,
afile
is deleted after appending, if
possible.
Note
For this implementation, the appended file will be deleted
from disk if delete_orig
is True
.
Clean up our mess: remove temporary files.
Retrieve a project file (source, translation or target file) from the project archive.
Get the type of file (‘src’, ‘trans’, ‘tgt’) with the given name.
Try and find a project file name for the given real file name.
Load the bundle project from the zip file of the given name.
Remove the file with the given project name from the project.
Save all project files to the bundle zip file.
Read-only access to self._sourcefiles
.
Read-only access to self._targetfiles
.
Read-only access to self._transfiles
.
Updates the file with the given project file name with the contents
of infile
.
the results from BundleProjStore.append_file()
.
Manage the Haiku catkeys translation format.
The Haiku catkeys format is the translation format used for localisation of the Haiku operating system.
It is a bilingual base class derived format with CatkeysFile
and
CatkeysUnit
providing file and unit level access. The file format is
described here:
http://www.haiku-os.org/blog/pulkomandy/2009-09-24_haiku_locale_kit_translator_handbook
The implementation covers the full requirements of a catkeys file. The files are simple Tab Separated Value (TSV) files that can be read by Microsoft Excel and other spreadsheet programs. They use the .txt extension which does make it more difficult to automatically identify such files.
The dialect of the TSV files is specified by CatkeysDialect
.
The files are UTF-8 encoded.
CatkeysHeader
provides header management support.
catkeys seem to escape things like in C++ (strings are just extracted from the source code unchanged, it seems.
Functions allow for _escape()
and _unescape()
.
Describe the properties of a catkeys generated TAB-delimited file.
A catkeys translation memory file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of CatkeysUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A catkeys translation memory header.
Set the checksum for the file.
Set a human readable target language.
A catkeys translation memory unit.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the dictionary of values for a catkeys line.
Get the message context.
Get the dictionary of values for a catkeys line.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Set the dictionary of values for a catkeys line.
newdict (Dict) – a new dictionary with catkeys line elements
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Field names for a catkeys TU
Field names for the catkeys header
Default or minimum header entries for a catkeys file
classes that hold units of comma-separated values (.csv) files (csvunit) or entire files (csvfile) for use with localisation.
This class represents a .csv file with various lines. The default format contains three columns: location, source, target.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Add common spreadsheet escapes to two strings.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
See if unit might be a header.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove common spreadsheet escapes from two strings.
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Test if file has a header or not, also returns number of columns in first row.
Check if fieldnames are valid, that is at least one field is identified as the source.
This module provides functionality to work with directories.
This class represents a directory.
Iterator over (dir, filename) for all files in this directory.
Returns a list of (dir, filename) tuples for all the file names in this directory.
List of all the units in all the files in this directory.
Populate the internal file data.
Iterator over all the units in all the files in this directory.
Classes that hold units of .dtd files (dtdunit
) or entire files
(dtdfile
).
These are specific .dtd files for localisation used by mozilla.
The following information is provided by Mozilla:
There is a grammar for entity definitions, which isn’t really precise, as the spec says. There’s no formal specification for DTD files, it’s just “whatever makes this work” basically. The whole piece is clearly not the strongest point of the xml spec
XML elements are allowed in entity values. A number of things that are allowed will just break the resulting document, Mozilla forbids these in their DTD parser.
There are two dialects:
Regular DTD
Android DTD
Both dialects are similar, but the Android DTD uses some particular escapes that regular DTDs don’t have.
In DTD usually there are characters escaped in the entities. In order to ease the translation some of those escaped characters are unescaped when reading from, or converting, the DTD, and that are escaped again when saving, or converting to a DTD.
In regular DTD the following characters are usually or sometimes escaped:
The % character is escaped using % or % or %
The “ character is escaped using "
The ‘ character is escaped using ' (partial roundtrip)
The & character is escaped using &
The < character is escaped using < (not yet implemented)
The > character is escaped using > (not yet implemented)
Besides the previous ones there are a lot of escapes for a huge number of characters. This escapes usually have the form of &#NUMBER; where NUMBER represents the numerical code for the character.
There are a few particularities in DTD escaping. Some of the escapes are not yet implemented since they are not really necessary, or because its implementation is too hard.
A special case is the ‘ escaping using ' which doesn’t provide a full roundtrip conversion in order to support some special Mozilla DTD files.
Also the “ character is never escaped in the case that the previous character is = (the sequence =” is present on the string) in order to avoid escaping the “ character indicating an attribute assignment, for example in a href attribute for an a tag in HTML (anchor tag).
It has the sames escapes as in regular DTD, plus this ones:
The ‘ character is escaped using ' or ' or u0027
The “ character is escaped using "
Accesskey Suffixes: entries with this suffix may be combined with labels
ending in labelsuffixes
into accelerator notation
A .dtd file made up of dtdunits.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source code of a dtd file in and include them as dtdunits in self.units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write content to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
An entity definition from a DTD file (and any associated comments).
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Set the entity to the given “location”.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
Return the entity as location (identifier).
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()
).
Convert the dtd entity back to string form.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
Returns whether this dtdunit doesn’t actually have an entity definition.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Read the first dtd element from the source code into this object, return linesprocessed.
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Gets the unquoted source string.
Ensure that plural count in string matches tags definition.
Gets the unquoted target string.
Iterator that only returns this unit.
Label suffixes: entries with this suffix are able to be comibed with accesskeys
found in in entries ending with accesskeysuffixes
Escapes a line for Android DTD files.
Quotes and escapes a line for regular DTD files.
Find and remove ampersands that are not part of an entity definition.
A stray & in a DTD file can break an application’s ability to parse the file. In Mozilla localisation this is very important and these can break the parsing of files used in XUL and thus break interface rendering. Tracking down the problem is very difficult, thus by removing potential broken ampersand and warning the users we can ensure that the output DTD will always be parsable.
name (String) – Entity name
value (String) – Entity text value
String
Entity value without bad ampersands
Unquotes a quoted Android DTD definition.
Unquotes a quoted dtd definition.
Py2exe can’t find stuff that we import dynamically, so we have this file just for the sake of the Windows installer to easily pick up all the stuff that we need and ensure they make it into the installer.
factory methods to build real storage objects that conform to base.py.
Factory that returns the applicable class for the type of file presented. Specify ignore to ignore some part at the back of the name (like .gz).
Factory that returns a usable object for the type of file presented.
storefile (file or str or TranslationStore) – File object or file name.
Specify ignore to ignore some part at the back of the name (like .gz).
module for parsing html files for translation.
An empty element is an element that cannot have any child nodes (i.e., nested elements or text nodes). In HTML, using a closing tag on an empty element is usually invalid. Reference https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Text from these HTML attributes will be extracted as translation units. Note: the content attribute of meta tags is a special case.
These HTML elements (tags) will be extracted as translation units, unless they lack translatable text content. In case one translatable element is embedded in another, the outer translation unit will be split into the parts before and after the inner translation unit.
Document metadata from meta elements with these names will be extracted as translation units. Reference https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Handle any buffered data.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Return the html text properly encoded based on a charset.
Simple detection based on BOM in case chardet is not available.
Feed data to the parser.
Call this as often as you want, with as little or as much text as you want (may include ‘n’).
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return full source of start tag: ‘<…>’.
Return a list of unit ids.
Return current line number and offset.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Returns the encoding of the html text.
We look for ‘charset=’ within a meta tag to do this.
Handle entries in the form &#NNNN; e.g. ⃡.
Handle named entities of the form &aaaa; e.g. ’.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Reset this instance. Loses all unprocessed data.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
An empty element is an element that cannot have any child nodes (i.e., nested elements or text nodes). In HTML, using a closing tag on an empty element is usually invalid. Reference https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Text from these HTML attributes will be extracted as translation units. Note: the content attribute of meta tags is a special case.
These HTML elements (tags) will be extracted as translation units, unless they lack translatable text content. In case one translatable element is embedded in another, the outer translation unit will be split into the parts before and after the inner translation unit.
Document metadata from meta elements with these names will be extracted as translation units. Reference https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Handle any buffered data.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Return the html text properly encoded based on a charset.
Simple detection based on BOM in case chardet is not available.
Feed data to the parser.
Call this as often as you want, with as little or as much text as you want (may include ‘n’).
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return full source of start tag: ‘<…>’.
Return a list of unit ids.
Return current line number and offset.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Returns the encoding of the html text.
We look for ‘charset=’ within a meta tag to do this.
Handle entries in the form &#NNNN; e.g. ⃡.
Handle named entities of the form &aaaa; e.g. ’.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Reset this instance. Loses all unprocessed data.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A unit of translatable/localisable HTML content.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Class that manages iCalender files for translation.
iCalendar files follow the RFC2445 specification.
The iCalendar specification uses the following naming conventions:
Component: an event, journal entry, timezone, etc
Property: a property of a component: summary, description, start time, etc
Attribute: an attribute of a property, e.g. language
The following are localisable in this implementation:
VEVENT component: SUMMARY, DESCRIPTION, COMMENT and LOCATION properties
While other items could be localised this is not seen as important until use cases arise. In such a case simply adjusting the component.name and property.name lists to include these will allow expanded localisation.
While the iCalendar format allows items to have a language attribute this is not used. The reason being that for most of the items that we localise they are only allowed to occur zero or once. Thus ‘summary’ would ideally be present in multiple languages in one file, the format does not allow such multiple entries. This is unfortunate as it prevents the creation of a single multilingual iCalendar file.
As this format used vobject which supports various formats including vCard it is possible to expand this format to understand those if needed.
An ical file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
An ical entry that is translatable.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Class that manages .ini files for translation.
# a comment ; a comment
[Section] a = a string b : a string
Base class for differentiating dialect options and functions.
An INI file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A INI file entry.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Decorator that registers the dialect.
Class that manages JSON data files for translation.
JSON is an acronym for JavaScript Object Notation, it is an open standard designed for human-readable data interchange.
JSON basic types:
Number (integer or real)
String (double-quoted Unicode with backslash escaping)
Boolean (true or false)
Array (an ordered sequence of values, comma-separated and enclosed in square brackets)
Object (a collection of key:value pairs, comma-separated and enclosed in curly braces)
null
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
},
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
Handle \u
and other escapes in Unicode
Manage data type storage and conversion. True –> “True” –> True
ARB JSON file.
See following URLs for doc:
https://github.com/google/app-resource-bundle/wiki/ApplicationResourceBundleSpecification https://docs.flutter.dev/development/accessibility-and-localization/internationalization#dart-tools
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of ARBJsonUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
A JSON entry.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Flat json file with support of i18next v4 format plurals.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of FlatI18NextV4Unit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
FormatJS JSON file.
See following URLs for doc:
https://formatjs.io/docs/getting-started/message-extraction/
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of FormatJSJsonUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
go-i18n JSON file.
See following URLs for doc:
https://github.com/nicksnyder/go-i18n/tree/v1 https://pkg.go.dev/github.com/nicksnyder/go-i18n
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of GoI18NJsonUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
go-i18n v2 JSON file.
See following URLs for doc:
https://github.com/nicksnyder/go-i18n https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of GoI18NV2JsonUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
gotext JSON file.
See following URLs for doc:
https://pkg.go.dev/golang.org/x/text/cmd/gotext https://github.com/golang/text/tree/master/cmd/gotext/examples/extract/locales/en-US
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of GoTextJsonUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
alias of GoTextUnitId
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Preserves id as stored in the JSON file.
A i18next v3 format, this is nested JSON with several additions.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of I18NextUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A i18next v3 format, JSON with plurals.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
A i18next v4 format, this is nested JSON with several additions.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of I18NextV4Unit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A i18next v4 format, JSON with plurals.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
A JSON file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of FlatJsonUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A JSON file with nested keys.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of JsonNestedUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A nested JSON entry.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
WebExtension JSON file.
See following URLs for doc:
https://developer.chrome.com/extensions/i18n https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Internationalization
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of WebExtensionJsonUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Returns dictionary for serialization.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Parent class for LISA standards (TMX, TBX, XLIFF).
A class representing a file store for one of the LISA file formats.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Method to be overridden to initialise headers, etc.
Adds and returns a new unit with the given string as first entry.
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Initialises self.body so it never needs to be retrieved from the XML again.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Populates this object from the given xml string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a string containing the file’s XML.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A single unit in the file. Provisional work is done to make several languages possible.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Returns a xml Element setup with given parameters to represent a single language entry. Has to be overridden.
Retrieves the term from the given languageNode
.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
Retrieves a languageNode
either by language or by index.
Returns a list of all nodes that contain per language information.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Sets the “target” string (second language), or alternatively appends to the list.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Module for parsing Markdown files for translation.
The principles for extraction of translation units are as follows:
Extract all content relevant for translation, at the cost of also including some formatting.
One translation unit per paragraph.
Keep formatting out of the translation units as much as possible. Exceptions include phrase emphasis and inline code. Use placeholders {1}, {2}, …, as needed.
Avoid HTML entities in the translation units. Use Unicode equivalents if possible.
White space within translation units is normalized, because the PO format does not preserve white space, and the translated Markdown content may have to be reflowed anyway.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of MarkdownUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Process the given source string (binary).
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A unit of translatable/localisable markdown content.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Expands placeholder fragments, recursively.
Sets the text of the (top-level) placeholder fragments to “{n}”. Returns an ordered list of placeholders.
Replaces sequences of placeholders and whitespace with larger placeholders.
Replaces placeholder markers in the given markdown with placeholder content.
Renders a sequence of span tokens to markdown, with translation.
Splits leading and trailing placeholders and whitespace, and the main content, into separate lists. Placeholders marked as important are kept with the main content.
Module for parsing Gettext .mo files for translation.
The coding of .mo files was produced from Gettext documentation, Pythons msgfmt.py and by observing and testing existing .mo files in the wild.
The hash algorithm is implemented for MO files, this should result in faster access of the MO file. The hash is optional for Gettext and is not needed for reading or writing MO files, in this implementation it is always on and does produce sometimes different results to Gettext in very small files.
A class representing a .mo file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Returns the nplural and plural values from the header.
Return a list of unit ids.
Return the project based on information in the header.
Use the ‘X-Project-Style’ entry in the header.
Use ‘Report-Msgid-Bug-To’ entry
Use the ‘X-Accelerator’ entry
Use the Project ID
Analyse the file itself (not yet implemented)
Get the source language for this store.
Return the target language based on information in the header.
Use the ‘Language’ entry in the header.
Poedit’s custom headers.
Analysing the ‘Language-Team’ entry.
Return a list of all units in this store.
Returns the header element, or None. Only the first element is allowed to be a header. Note that this could still return an empty header element, if present.
Sets default values for po headers.
Return True if the object doesn’t contain any translation units.
Create a header for the given filename.
Check .makeheaderdict() for information on parameters.
Create a header dictionary with useful defaults.
pot_creation_date can be None (current date) or a value (datetime or string) po_revision_date can be None (form), False (=pot_creation_date), True (=now), or a value (datetime or string)
Dictionary with the header items
dict of strings
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Merges another header with this header.
This header is assumed to be the template.
Parses the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Parses the PO header and returns the interpreted values as a dictionary.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Output a string representation of the MO data file.
Set the project in the header.
project_style (str) – the new project
Set the source language for this store.
Set the target language in the header.
This removes any custom Poedit headers if they exist.
lang (str) – the new target language code
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Add contribution comments if necessary.
Updates the fields in the PO style header.
This will create a header if add == True.
Update the Plural-Form PO header.
A class representing a .mo translation message.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Is this a header entry?.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
Is this message translateable?.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Helper to unpack Gettext MO files into a Python string.
A class to manage Mozilla .lang files.
See https://github.com/mozilla-l10n/langchecker/wiki/.lang-files-format for specifications on the format.
We extend TxtFile, since that has a lot of useful stuff for encoding.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read in text lines and create txtunits from the blocks of text.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
This is just a normal unit with a weird string output.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Manage the OmegaT glossary format.
OmegaT glossary format is used by the OmegaT computer aided translation tool.
It is a bilingual base class derived format with OmegaTFile
and OmegaTUnit
providing file and unit level access.
The OmegaT glossary format is a simple Tab Separated Value (TSV) file with the columns: source, target, comment.
The dialect of the TSV files is specified by OmegaTDialect
.
The files are either UTF-8 or encoded using the system default. UTF-8 encoded files use the .utf8 extension while system encoded files use the .tab extension.
Field names for an OmegaT glossary unit
Describe the properties of an OmegaT generated TAB-delimited glossary file.
An OmegaT glossary file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of OmegaTUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parsese the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
An OmegaT glossary file in the default system encoding.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of OmegaTUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parsese the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
An OmegaT glossary unit.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the dictionary of values for a OmegaT line.
Get the message context.
Get the dictionary of values for a OmegaT line.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Set the dictionary of values for a OmegaT line.
newdict (Dict) – a new dictionary with OmegaT line elements
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Classes that hold units of .oo files (oounit) or entire files (oofile).
These are specific .oo files for localisation exported by OpenOffice.org - SDF format (previously knows as GSI files).
The behaviour in terms of escaping is explained in detail in the programming comments.
Escapes the help text as it would be in an SDF file.
<, >, “ are only escaped in <[[:lower:]]> tags. Some HTML tags make it in in lowercase so those are dealt with. Some OpenOffice.org help tags are not escaped.
Escapes SDF text to be suitable for unit consumption.
converts an oo key tuple into a unique identifier.
Create a new dictionary with keys from iterable and values set to value.
Return the value for key if key is in the dictionary, else default.
If the key is not found, return the default if given; otherwise, raise a KeyError.
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
Converts any non-alphanumeric (standard roman) characters to _.
this represents an entire .oo file.
Adds a parsed line to the file.
Converts all the lines back to tab-delimited form.
Parses lines and adds them to the file.
Convert to a string. double check that unicode is handled.
this represents one line, one translation in an .oo file.
Get the key that identifies the resource.
Return a line in tab-delimited form.
Return a list of parts in this line.
Obtains the text column and handle escaping.
Create a line from its tab-delimited parts.
Sets the text column and handle escaping.
Obtains the text column and handle escaping.
this takes a huge GSI file and represents it as multiple smaller files…
Reads in all the lines and works out the subfiles.
Returns an oofile built up from the given subfile’s lines.
Looks up the subfile name for the line.
Returns the list of lines matching the subfile.
Returns a list of subfiles in the file.
Returns a pseudo-file object for the given subfile.
Returns a pseudo-file object for the given subfile.
this represents a number of translations of a resource.
Add a line to the oounit.
Return the lines in tab-delimited form.
Unescapes normal text to be suitable for writing to the SDF file.
Unescapes SDF text to be suitable for unit consumption.
This module implements basic functionality to support placeables.
Substitutions
For example, in ODF, footnotes appear in the ODF XML where they are defined; so if we extract a paragraph with some footnotes, the translator will have a lot of additional XML to with; so we separate the footnotes out into separate translation units and mark their positions in the original text with placeables.
Hiding of inline formatting data
The translator doesn’t want to have to deal with all the weird formatting conventions of wherever the text came from.
Marking variables
This is an old issue - translators translate variable names which should remain untranslated. We can wrap placeables around variable names to avoid this.
The placeables model follows the XLIFF standard’s list of placeables. Please refer to the XLIFF specification to get a better understanding.
Contains base placeable classes with names based on XLIFF placeables. See the XLIFF standard for more information about what the names mean.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Contains general placeable implementations. That is placeables that does not fit into any other sub-category.
Placeable for the “alt=…” attributes inside XML tags.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
A parser method to extract placeables from a string based on a regular
expression. Use this function as the @parse()
method of a placeable
class.
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Placeable handling XML entities (&xxxxx;
-style entities).
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
A parser method to extract placeables from a string based on a regular
expression. Use this function as the @parse()
method of a placeable
class.
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Placeable handling XML tags.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
A parser method to extract placeables from a string based on a regular
expression. Use this function as the @parse()
method of a placeable
class.
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
implementations.
Base class for all placeables.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Contains the parse
function that parses normal strings into StringElem-
based “rich” string element trees.
Parse placeables from the given string or sub-tree by using the parsing functions provided.
The output of this function is heavily dependent on the order of the parsing functions. This is because of the algorithm used.
An over-simplification of the algorithm: the leaves in the StringElem
tree are expanded to the output of the first parsing function in
parse_funcs
. The next level of recursion is then started on the new
set of leaves with the used parsing function removed from
parse_funcs
.
tree (unicode|StringElem) – The string or string element sub-tree to parse.
Contains the base StringElem
class that represents a node in a
parsed rich-string tree. It is the base class of all placeables.
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
This class represents a sub-tree of a string parsed into a rich structure. It is also the base class of all placeables.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Parse an instance of this class from the start of the given string.
This method should be implemented by any sub-class that wants to
parseable by translate.storage.placeables.parse
.
pstr (unicode) – The string to parse into an instance of this class.
An instance of the current class, or None
if the string
not parseable by this class.
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Contains the placeable that represents a terminology term.
Terminology distinguished from the rest of a string by being a placeable.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
A list of matcher objects to use to identify terminology.
Parse an instance of this class from the start of the given string.
This method should be implemented by any sub-class that wants to
parseable by translate.storage.placeables.parse
.
pstr (unicode) – The string to parse into an instance of this class.
An instance of the current class, or None
if the string
not parseable by this class.
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
The available translations for this placeable.
Contains XLIFF-specific placeables.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Placeable for unrecognized or umimplemented XML nodes. It’s main purpose is to preserve all associated XML data.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Parse an instance of this class from the start of the given string.
This method should be implemented by any sub-class that wants to
parseable by translate.storage.placeables.parse
.
pstr (unicode) – The string to parse into an instance of this class.
An instance of the current class, or None
if the string
not parseable by this class.
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Apply f
to all actual strings in the tree.
f – Must take one (str or unicode) argument and return a string or unicode.
Returns a copy of the sub-tree. This should be overridden in sub-classes with more data.
Note
self.renderer
is not copied.
Delete the text in the range given by the string-indexes
start_index
and end_index
.
Partial nodes will only be removed if they are editable.
A StringElem
representing the removed sub-string, the
parent node from which it was deleted as well as the offset
at which it was deleted from. None
is returned for the
parent value if the root was deleted. If the parent and
offset values are not None
, parent.insert(offset,
deleted)
effectively undoes the delete.
Returns a list of the nodes in the tree in depth-first order.
Get the StringElem
in the tree that contains the string rendered
at the given offset.
Find the offset of elem
in the current tree.
This cannot be reliably used if self.renderer
is used and even
less so if the rendering function renders the string differently
upon different calls. In Virtaal the StringElemGUI.index()
method
is used as replacement for this one.
The string index where element e
starts, or -1 if e
was not found.
More unicode
class emulation.
Find sub-string x
in this string tree and return the position at
which it starts.
Find all elements in the current sub-tree containing x
.
Flatten the tree by returning a depth-first search over the tree’s leaves.
Get info about the specified range in the tree.
A dictionary with the following items:
elem: The element in which index
resides.
index: Copy of the index
parameter
offset: The offset of index
into 'elem'
.
Searches the current sub-tree for and returns the parent of the
child
element.
Whether this string can have sub-elements.
Insert the given text at the specified offset of this string-tree’s string (Unicode) representation.
Insert the given text between the two parameter StringElem
s.
Whether this string should be changable by the user. Not used at the moment.
Whether this element should be deleted in its entirety when partially
deleted. Only checked when iseditable = False
Whether or not this instance is a leaf node in the StringElem
tree.
A node is a leaf node if it is a StringElem
(not a sub-class) and
contains only sub-elements of type str
or unicode
.
Whether this string is translatable into other languages.
Whether this string should be visible to the user. Not used at the moment.
Iterate through the nodes in the tree in dept-first order.
Apply f
to all nodes for which filter
returned True
(optional).
Print the tree from the current instance’s point in an indented manner.
Remove unnecessary nodes to make the tree optimal.
Replace nodes with type ptype
with base StringElem
s,
containing the same sub-elements. This is only applicable to elements
below the element tree root node.
An optional function that returns the Unicode representation of the string.
The sub-elements that make up this this string.
Transform the sub-tree according to some class-specific needs. This method should be either overridden in implementing sub-classes or dynamically replaced by specific applications.
The transformed Unicode string representing the sub-tree.
Classes that hold units of PHP localisation files phpunit
or
entire files phpfile
. These files are used in translating many
PHP based applications.
Only PHP files written with these conventions are supported:
<?php
$lang['item'] = "vale"; # Array of values
$some_entity = "value"; # Named variables
define("ENTITY", "value");
$lang = array(
'item1' => 'value1' , #Supports space before comma
'item2' => 'value2',
);
$lang = array( # Nested arrays
'item1' => 'value1',
'item2' => array(
'key' => 'value' , #Supports space before comma
'key2' => 'value2',
),
);
Nested arrays without key for nested array are not supported:
<?php
$lang = array(array('key' => 'value'));
The working of PHP strings and specifically the escaping conventions which differ between single quote (’) and double quote (”) characters are implemented as outlined in the PHP documentation for the String type.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of LaravelPHPUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a PHP file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Convert the units back to lines.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Convert the unit back into formatted lines for a php file.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
Return whether this is a blank element, containing only comments.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Convert PHP escaped string to a Python string.
Convert Python string to PHP escaping.
The encoding is implemented for ‘single quote’ and “double quote” syntax.
heredoc and nowdoc are not implemented and it is not certain whether this would ever be needed for PHP localisation needs.
This class represents a PHP file, made up of phpunits.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a PHP file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Convert the units back to lines.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A unit of a PHP file: a name, a value, and any comments associated.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Convert the unit back into formatted lines for a php file.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
Return whether this is a blank element, containing only comments.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Decorator for production functions to store lexer positions.
The one definitive way to extract a msgid comment out of an unescaped unicode string that might contain it.
unicode
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of TranslationUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Returns the nplural and plural values from the header.
Return a list of unit ids.
Return the project based on information in the header.
Use the ‘X-Project-Style’ entry in the header.
Use ‘Report-Msgid-Bug-To’ entry
Use the ‘X-Accelerator’ entry
Use the Project ID
Analyse the file itself (not yet implemented)
Get the source language for this store.
Return the target language based on information in the header.
Use the ‘Language’ entry in the header.
Poedit’s custom headers.
Analysing the ‘Language-Team’ entry.
Return a list of all units in this store.
Returns the header element, or None. Only the first element is allowed to be a header. Note that this could still return an empty header element, if present.
Sets default values for po headers.
Return True if the object doesn’t contain any translation units.
Create a header for the given filename.
Check .makeheaderdict() for information on parameters.
Create a header dictionary with useful defaults.
pot_creation_date can be None (current date) or a value (datetime or string) po_revision_date can be None (form), False (=pot_creation_date), True (=now), or a value (datetime or string)
Dictionary with the header items
dict of strings
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
Merges another header with this header.
This header is assumed to be the template.
Parser to process the given source string.
Reads the given file (or opens the given filename) and parses back to an object.
Parses the PO header and returns the interpreted values as a dictionary.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project in the header.
project_style (str) – the new project
Set the source language for this store.
Set the target language in the header.
This removes any custom Poedit headers if they exist.
lang (str) – the new target language code
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Add contribution comments if necessary.
Updates the fields in the PO style header.
This will create a header if add == True.
Update the Plural-Form PO header.
Adds an error message to this unit.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review. Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Quote the query fragment of a URL; replacing ‘ ‘ with ‘+’.
unquote(‘%7e/abc+def’) -> ‘~/abc def’.
class that handles all header functions for a header in a po file.
Parses an input string with the definition of a PO header and returns the interpreted values as a dictionary.
This class implements functionality for manipulation of po file headers. This class is a mix-in class and useless on its own. It must be used from all classes which represent a po file.
Returns the nplural and plural values from the header.
Return the project based on information in the header.
Use the ‘X-Project-Style’ entry in the header.
Use ‘Report-Msgid-Bug-To’ entry
Use the ‘X-Accelerator’ entry
Use the Project ID
Analyse the file itself (not yet implemented)
Return the target language based on information in the header.
Use the ‘Language’ entry in the header.
Poedit’s custom headers.
Analysing the ‘Language-Team’ entry.
Returns the header element, or None. Only the first element is allowed to be a header. Note that this could still return an empty header element, if present.
Sets default values for po headers.
Create a header for the given filename.
Check .makeheaderdict() for information on parameters.
Create a header dictionary with useful defaults.
pot_creation_date can be None (current date) or a value (datetime or string) po_revision_date can be None (form), False (=pot_creation_date), True (=now), or a value (datetime or string)
Dictionary with the header items
dict of strings
Merges another header with this header.
This header is assumed to be the template.
Parses the PO header and returns the interpreted values as a dictionary.
Set the project in the header.
project_style (str) – the new project
Set the target language in the header.
This removes any custom Poedit headers if they exist.
lang (str) – the new target language code
Add contribution comments if necessary.
Updates the fields in the PO style header.
This will create a header if add == True.
Update the Plural-Form PO header.
Returns the timezone as a string in the format [+-]0000, eg +0200.
WHITE-SPACE # TRANSLATOR-COMMENTS #. AUTOMATIC-COMMENTS #| PREVIOUS MSGID (Gettext 0.16 - check if this is the correct position - not yet implemented) #: REFERENCE… #, FLAG… msgctxt CONTEXT (Gettext 0.15) msgid UNTRANSLATED-STRING msgstr TRANSLATED-STRING.
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Append object to the end of the list.
Decode the bytes using the codec registered for encoding.
The encoding with which to decode the bytes.
The error handling scheme to use for the handling of decoding errors. The default is ‘strict’ meaning that decoding errors raise a UnicodeDecodeError. Other possible values are ‘ignore’ and ‘replace’ as well as any other name registered with codecs.register_error that can handle UnicodeDecodeErrors.
The header has been arbitrarily decoded with a single-byte encoding. We re-encode it to decode values with the proper encoding defined in the header (using decode_list above).
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
Read all the lines belonging to the current unit if obsolete.
Read all the lines belonging starting with #|. These lines contain the previous msgid and msgctxt info. We strip away the leading ‘#| ‘ and read until we stop seeing #|.
A class loader that will load C or Python implementations of the PO class
depending on the USECPO
variable.
Use the environment variable USECPO=2
(or USECPO=1
) to choose the
C implementation which uses Gettext’s libgettextpo for high parsing speed.
Otherwise the local Python based parser is used (slower but very well
tested).
XLIFF classes specifically suited for handling the PO representation in XLIFF.
This way the API supports plurals as if it was a PO file, for example.
a file for the po variant of Xliff files.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of PoXliffUnit
Add a unit to source and location idexes.
Initialise the file header.
adds the given trans-unit to the last used body node if the filename has changed it uses the slow method instead (will create the nodes required if asked). Returns success.
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
creates a filenode with the given filename. All parameters are needed for XLIFF compliance.
Adds a group tag into the specified file.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Finds the body node for the given filenode.
Returns the datatype of the stored file. If no filename is given, the datatype of the first file is given.
Returns the date attribute for the file.
If no filename is given, the date of the first file is given. If the date attribute is not specified, None is returned.
Date attribute of file
Date or None
Returns the name of the given file.
Returns all filenames in this XLIFF file.
Finds the filenode with the given name.
Finds the header node for the given filenode.
Returns the nplural and plural values from the header.
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Returns the header element, or None. Only the first element is allowed to be a header. Note that this could still return an empty header element, if present.
Sets default values for po headers.
Initialises self.body so it never needs to be retrieved from the XML again.
Return True if the object doesn’t contain any translation units.
Create a header for the given filename.
Check .makeheaderdict() for information on parameters.
Create a header dictionary with useful defaults.
pot_creation_date can be None (current date) or a value (datetime or string) po_revision_date can be None (form), False (=pot_creation_date), True (=now), or a value (datetime or string)
Dictionary with the header items
dict of strings
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Merges another header with this header.
This header is assumed to be the template.
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Populates this object from the given xml string.
Reads the given file (or opens the given filename) and parses back to an object.
Parses the PO header and returns the interpreted values as a dictionary.
Parses the string to return the correct file object.
Remove a unit from source and locaton indexes.
We want to remove the default file-tag as soon as possible if we know if still present and empty.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a string containing the file’s XML.
Set the name of the given file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
xliff units have alttrans tags which can be used to store suggestions
Adds the given trans-unit (will create the nodes required if asked).
Success
Boolean
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Add contribution comments if necessary.
Updates the fields in the PO style header.
This will create a header if add == True.
Update the Plural-Form PO header.
A class to specifically handle the plural units created from a po file.
Adds an alt-trans tag and alt-trans components to the unit.
txt (String) – Alternative translation of the source text.
Adds an error message to this unit.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Add a note specifically in a “note” tag.
Build a native unit from a foreign unit.
Preserving as much information as possible.
Check against node tag’s origin (e.g note or alt-trans).
Add the context group to the trans-unit with contexts a list with (type, text) tuples describing each context.
Returns an xml Element setup with given parameters.
Removes the supplied alternative from the list of alt-trans tags.
Retrieves the term from the given languageNode
.
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns <alt-trans> for the given origin as a list of units. No origin means all alternatives.
Returns the automatic comments (x-po-autocomment), which corresponds to the #. style po comments.
Get the message context.
Returns the contexts in the context groups with the specified name.
Returns the contexts in the context groups with the specified attributeName and attributeValue.
Get all error messages.
A unique identifier for this unit.
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.
Retrieves a languageNode
either by language or by index.
We override this to get source and target nodes.
Returns all the references (source locations).
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()
).
Returns the restype attribute in the trans-unit tag.
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
Returns the translator comments (x-po-trancomment), which corresponds to the # style po comments.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
States whether this unit is approved.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
States whether this unit needs to be reviewed.
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.
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).
Make a unit obsolete.
Mark this unit as approved.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Remove all the translator notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Sets the target string to the given value.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Manages a project store as well as the processes involved in a project workflow.
Proxy for self.store.append_sourcefile()
.
Convenience method that calls add_source()
and
convert_forward()
and returns the results from both.
Close underlying store.
Proxy for self.store.close()
.
Convert the given input file to the next type in the process.
Source document (eg. ODT) -> Translation file (eg. XLIFF) -> Translated document (eg. ODT).
input_fname (basestring) – The project name of the file to convert
convert_options (Dictionary (optional)) – Passed as-is to
translate.convert.factory.convert()
.
the converted file object and its project name.
Export the file with the specified filename to the given
destination. This method will raise
FileNotInProjectError
via the call
to get_file()
if
fname is not found in the project.
Return store filename.
Proxy for self.store.get_file()
.
Return project filename.
Proxy for self.store.get_proj_filename()
.
Try and find a real file name for the given project file name.
Remove a file.
Proxy for self.store.remove_file()
.
Save a store.
Proxy for self.store.save()
.
Update a file.
Proxy for self.store.update_file()
.
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Basic project file container.
Append the given file to the project with the given filename, marked
to be of type ftype
(‘src’, ‘trans’, ‘tgt’).
delete_orig (bool) – Whether or not the original (given) file should be
deleted after being appended. This is set to
True
by
convert_forward()
. Not used in this class.
Retrieve the file with the given name from the project store.
The file is looked up in the self._files
dictionary. The values
in this dictionary may be None
, to indicate that the file is not
cacheable and needs to be retrieved in a special way. This special
way must be defined in this method of sub-classes. The value may
also be a string, which indicates that it is a real file accessible
via open
.
mode (str) – The mode in which to re-open the file (if it is closed).
Get the type of file (‘src’, ‘trans’, ‘tgt’) with the given name.
Try and find a project file name for the given real file name.
Load the project in some way. Undefined for this (base) class.
Remove the file with the given project name from the project. If the file type (‘src’, ‘trans’ or ‘tgt’) is not given, it is guessed.
Save the project in some way. Undefined for this (base) class.
Read-only access to self._sourcefiles
.
Read-only access to self._targetfiles
.
Read-only access to self._transfiles
.
Remove the project file with name pfname
and add the contents
from infile
to the project under the same file name.
the results from ProjectStore.append_file()
.
Classes that hold units of .properties, and similar, files that are used in translating Java, Mozilla, MacOS and other software.
The propfile
class is a monolingual class with propunit
providing unit level access.
The .properties store has become a general key value pair class with
Dialect
providing the ability to change the behaviour of the
parsing and handling of the various dialects.
Currently we support:
Java .properties
Mozilla .properties
Adobe Flex files
MacOS X .strings files
Skype .lang files
XWiki .properties
The following provides references and descriptions of the various dialects supported:
Java .properties are supported completely except for the ability to drop pairs that are not translated.
The following .properties file description gives a good references to the .properties specification.
Properties file may also hold Java MessageFormat messages. No special handling is provided in this storage class for MessageFormat, but this may be implemented in future.
All delimiter types, comments, line continuations and spaces handling in delimeters are supported.
Mozilla files use ‘=’ as a delimiter, are UTF-8 encoded and thus don’t need \u escaping. Any \U values will be converted to correct Unicode characters.
Mac OS X strings files are implemented using these two articles as references.
Adobe Flex files seem to be normal .properties files but in UTF-8 just like Mozilla files. This page provides the information used to implement the dialect.
Skype .lang files seem to be UTF-16 encoded .properties files.
XWiki translations files are standard Java .properties but with specific escaping support for simple quotes, and support of missing translations. This XWiki document provides the information used to implement the dialect.
A simple summary of what is permissible follows.
Comments supported:
# a comment
// a comment (only at the beginning of a line)
# The following are # escaped to render in docs
# ! is standard but not widely supported
#! a comment
# /* is non-standard but used on some implementations
#/* a comment (not across multiple lines) */
Name and Value pairs:
# Delimiters
key = value
key : value
# Whitespace delimiter
# key[sp]value
# Space in key and around value
\ key\ = \ value
# Note that the b and c are escaped for reST rendering
b = a string with escape sequences \\t \\n \\r \\\\ \\" \\' \\ (space) \u0123
c = a string with a continuation line \\
continuation line
# Special cases
# key with no value
//key (escaped; doesn't render in docs)
# value no key (extractable in prop2po but not mergeable in po2prop)
=value
# .strings specific
"key" = "value";
Settings for the various behaviours in key=value files.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
XWiki dialect is mainly a Java properties behaviour but with special handling of simple quotes: they are escaped by doubling them when an argument on the form “{X}” is provided, X being a number.
Encode the string.
Find the type and position of the delimiter in a property line.
Property files can be delimited by “=”, “:” or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.
Strip unneeded characters from the key.
Strip unneeded characters from the value.
Represents a full XWiki Page translation: this file does not contains properties but its whole content needs to be translated. More information on https://dev.xwiki.org/xwiki/bin/view/Community/XWiki%20Translations%20Formats/#HXWikiFullContentTranslation.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Represents an XWiki Page containing translation properties as described in https://dev.xwiki.org/xwiki/bin/view/Community/XWiki%20Translations%20Formats/#HXWikiPageProperties.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Accesskey Suffixes: entries with this suffix may be combined with labels
ending in labelsuffixes
into accelerator notation
Determine whether a line ends a new multi-line comment.
line (unicode) – A properties line
True if line ends a new multi-line comment
Determine whether a line is a one-line comment.
line (unicode) – A properties line
True if line is a one-line comment
Determine whether a line starts a new multi-line comment.
line (unicode) – A properties line
True if line starts a new multi-line comment
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Determine whether line has a line continuation marker.
.properties files can be terminated with a backslash (\) indicating that the ‘value’ continues on the next line. Continuation is only valid if there are an odd number of backslashses (an even number would result in a set of N/2 slashes not an escape)
line (str) – A properties line
Does line end with a line continuation
Boolean
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Label suffixes: entries with this suffix are able to be comibed with accesskeys
found in in entries ending with accesskeysuffixes
this class represents a .properties file, made up of propunits.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
returns whether this is a blank element, containing only comments.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
An element of a properties file i.e. a name and value, and any comments associated.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Return the string representing a missing translation.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Convert the element back into formatted lines for a .properties file.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
Returns whether this is a blank element, containing only comments.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
The line represents a missing translation.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Remove the missing prefix from the line.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Decorator that registers the dialect.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a properties file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
the dialect used is xwiki for simple quote escape handling
missing translations are output with a dedicated “### Missing: “ prefix.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Return the string representing a missing translation.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Convert the element back into formatted lines for a .properties file.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
Returns whether this is a blank element, containing only comments.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
Return true if the line represents a missing translation.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Remove the missing prefix from the line.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Classes that hold units of Gettext .po files (pounit) or entire files (pofile).
Customized TextWrapper.
custom word separator regexp
full width chars accounting, based on https://bugs.python.org/issue24665
dropped support for unused features (for example max_lines or drop_whitespace)
Reformat the single paragraph in ‘text’ to fit in lines of no more than ‘self.width’ columns, and return a new string containing the entire wrapped paragraph.
Reformat the single paragraph in ‘text’ so it fits in lines of no more than ‘self.width’ columns, and return a list of wrapped lines. Tabs in ‘text’ are expanded with string.expandtabs(), and all other whitespace characters (including newline) are converted to space.
Return the real width of an unicode text, the len of any other type.
Fullwidth and Wide CJK chars are double-width.
Return the two slices of a text cut to the index.
Escapes a line for po format. assumes no n occurs in the line.
line – unescaped text
Separator for #: entries
A .po file containing various units.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Returns the nplural and plural values from the header.
Return a list of unit ids.
Return the project based on information in the header.
Use the ‘X-Project-Style’ entry in the header.
Use ‘Report-Msgid-Bug-To’ entry
Use the ‘X-Accelerator’ entry
Use the Project ID
Analyse the file itself (not yet implemented)
Get the source language for this store.
Return the target language based on information in the header.
Use the ‘Language’ entry in the header.
Poedit’s custom headers.
Analysing the ‘Language-Team’ entry.
Return a list of all units in this store.
Returns the header element, or None. Only the first element is allowed to be a header. Note that this could still return an empty header element, if present.
Sets default values for po headers.
Return True if the object doesn’t contain any translation units.
Create a header for the given filename.
Check .makeheaderdict() for information on parameters.
Create a header dictionary with useful defaults.
pot_creation_date can be None (current date) or a value (datetime or string) po_revision_date can be None (form), False (=pot_creation_date), True (=now), or a value (datetime or string)
Dictionary with the header items
dict of strings
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
Merges another header with this header.
This header is assumed to be the template.
Parses the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Parses the PO header and returns the interpreted values as a dictionary.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Make sure each msgid is unique ; merge comments etc from duplicates into original.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write to file.
Set the project in the header.
project_style (str) – the new project
Set the source language for this store.
Set the target language in the header.
This removes any custom Poedit headers if they exist.
lang (str) – the new target language code
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Add contribution comments if necessary.
Updates the fields in the PO style header.
This will create a header if add == True.
Update the Plural-Form PO header.
Adds an error message to this unit.
Add a location to sourcecomments in the PO unit.
location (String) – Text location e.g. ‘file.c:23’ does not include #:
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
This is modeled on the XLIFF method.
Build a native unit from a foreign unit.
Preserving as much information as possible.
Return a list of alternate units.
Previous msgid and current msgstr is combined to form a single alternative unit.
Get the message context.
Get all error messages.
Returns a unique identifier for this unit.
Get a list of locations from sourcecomments in the PO unit.
rtype: List return: A list of the locations with ‘#: ‘ stripped
Return comments based on origin value.
origin – programmer, developer, source code, translator or None
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Check whether the given comment marker is present.
These should appear as:
# (commentmarker) ...
Returns whether this pounit contains plural strings…
Check whether the given type comment is present.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Makes this unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review. Adds an optional explanation as a note.
Merges the otherpo (with the same msgid) into this one.
Overwrite non-blank self.msgstr only if overwrite is True merge comments only if comments is True
Extract KDE style msgid comments from the unit.
String
Returns the extracted msgidcomments found in this unit’s msgid.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Returns the unescaped msgid.
Remove all the translator’s notes (other comments).
Makes an obsolete unit normal.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Alters whether a given typecomment is present.
Returns the unescaped msgid.
Ensure that plural count in string matches tags definition.
Returns the unescaped msgstr.
Iterator that only returns this unit.
Quotes the given text for a PO file, returning quoted and escaped lines.
Split lines based on first newline char.
Can not use univerzal newlines as they match any newline like character inside text and that breaks on files with unix newlines and LF chars inside comments.
The code looks for first msgid and looks for newline used after it. This should safely cover weird newlines used in comments or filenames, while properly parsing po files with any newlines.
Unescape the given line.
Quotes on either side should already have been removed.
Module for parsing Qt .qm files.
Note
Based on documentation from Gettext’s .qm implementation (see write-qt.c) and on observation of the output of lrelease.
Note
Certain deprecated section tags are not implemented. These will break and print out the missing tag. They are easy to implement and should follow the structure in 03 (Translation). We could find no examples that use these so we’d rather leave it unimplemented until we actually have test data.
Note
Many .qm files are unable to be parsed as they do not have the source text. We assume that since they use a hash table to lookup the data there is actually no need for the source text. It seems however that in Qt4’s lrelease all data is included in the resultant .qm file.
Note
We can only parse, not create, a .qm file. The main issue is that we need to implement the hashing algorithm (which seems to be identical to the Gettext hash algorithm). Unlike Gettext it seems that the hash is required, but that has not been validated.
Note
The code can parse files correctly. But it could be cleaned up to be more readable, especially the part that breaks the file into sections.
http://qt.gitorious.org/+kde-developers/qt/kde-qt/blobs/master/tools/linguist/shared/qm.cpp Plural information QLocale languages
A class representing a .qm file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parses the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Output a string representation of the .qm data file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A class representing a .qm translation message.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Helper to unpack Qt .qm files into a Python string.
Module for handling Qt Linguist Phrase Book (.qph) files.
Extract from the Qt Linguist Manual: Translators: .qph Qt Phrase Book Files are human-readable XML files containing standard phrases and their translations. These files are created and updated by Qt Linguist and may be used by any number of projects and applications.
A DTD to define the format does not seem to exist, but the following code provides the reference implementation for the Qt Linguist product.
Class representing a QPH file store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Method to be overridden to initialise headers, etc.
Adds and returns a new unit with the given string as first entry.
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this .qph file.
We don’t implement setsourcelanguage as users really shouldn’t be altering the source language in .qph files, it should be set correctly by the extraction tools.
ISO code e.g. af, fr, pt_BR
String
Get the target language for this .qph file.
ISO code e.g. af, fr, pt_BR
String
Return a list of all units in this store.
Initialises self.body so it never needs to be retrieved from the XML again.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Populates this object from the given xml string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the XML document to the file out.
no XML declaration
Set the project type for this store.
Set the source language for this store.
Set the target language for this .qph file to targetlanguage.
targetlanguage (String) – ISO code e.g. af, fr, pt_BR
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A single term in the qph file.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Add a note specifically in a “definition” tag.
Build a native unit from a foreign unit.
Preserving as much information as possible.
Returns an xml Element setup with given parameters.
Retrieves the term from the given languageNode
.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
Retrieves a languageNode
either by language or by index.
We override this to get source and target nodes.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Remove all the translator notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Sets the “target” string (second language), or alternatively appends to the list.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Classes that hold units of .rc files (rcunit
) or entire files
(rcfile
) used in translating Windows Resources.
Unescape a given .rc string into a valid Python string.
Escape a given Python string into a valid .rc string.
Return the name generated for a caption of a dialog.
Return the name generated for a control of a dialog.
Return the pre-name generated for elements of a menu.
Return the name generated for a menuitem of a popup.
Return the name generated for a caption of a popup.
Return the pre-name generated for subelements of a popup.
pre_name – The pre_name that already have the popup.
caption – The caption (whitout quotes) of the popup.
The subelements pre-name based in the pre-name of the popup and its caption.
Return the name generated for a stringtable element.
Generate a RC statement parser that can be used to parse a RC file.
pyparsing.ParserElement
This class represents a .rc file, made up of rcunits.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Transverses the popup tree making new units as needed.
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read the source of a .rc file in and include them as units.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the units back to file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A unit of an rc file.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Convert the element back into formatted lines for a .rc file.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
Returns whether this is a blank element, containing only comments.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Module to provide statistics and related functionality.
Manages statistics for storage objects.
Returns a list of the classes that the unit belongs to.
unit – the unit to classify
Makes a dictionary of which units fall into which classifications.
This method iterates over all units.
Counts the source and target words in each of the units.
Returns the number of fuzzy units.
Return a list of fuzzy units.
Joins the unit source strings in a single string of text.
Returns a list of all units in this object.
Updates the classification of a unit in self.classification.
item – an integer that is an index in .getunits().
Returns the number of words in the source text.
Returns the number of translated units.
Return a list of translated units.
Returns the number of translated words in this object.
Returns the number of untranslated units.
Return a list of untranslated units.
Returns the number of untranslated words in this object.
Returns the number of words in the given text.
Class that manages subtitle files for translation.
This class makes use of the subtitle functionality of aeidon
.
specialized class for SubRipFile’s only.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of SubtitleUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Parse the given file.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
specialized class for SubRipFile’s only.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of MicroDVDUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Parse the given file.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
MicroDVD unit, it uses frames instead of time as start/end.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
specialized class for SubRipFile’s only.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of SubtitleUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Parse the given file.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
specialized class for SubRipFile’s only.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of SubtitleUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Parse the given file.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A subtitle file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of SubtitleUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Parse the given file.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A subtitle entry that is translatable.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
module for handling TBX glossary files.
Class representing a TBX file store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Initialise headers with TBX specific things.
Adds and returns a new unit with the given string as first entry.
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Initialises self.body so it never needs to be retrieved from the XML again.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Populates this object from the given xml string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a string containing the file’s XML.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A single term in the TBX file. Provisional work is done to make several languages possible.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Add a note specifically in a “note” tag.
Build a native unit from a foreign unit.
Preserving as much information as possible.
Returns a langset xml Element setup with given parameters.
Retrieves the term from the given languageNode
.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
Retrieves a languageNode
either by language or by index.
Returns a list of all nodes that contain per language information.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Remove all the translator notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Sets the “target” string (second language), or alternatively appends to the list.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Class that manages TikiWiki files for translation.
Tiki files are <strike>ugly and inconsistent</strike> formatted as a single large PHP array with several special sections identified by comments. Example current as of 2008-12-01:
<?php
// Many comments at the top
$lang=Array(
// ### Start of unused words
"aaa" => "zzz",
// ### end of unused words
// ### start of untranslated words
// "bbb" => "yyy",
// ### end of untranslated words
// ### start of possibly untranslated words
"ccc" => "xxx",
// ### end of possibly untranslated words
"ddd" => "www",
"###end###"=>"###end###");
?>
In addition there are several auto-generated //-style comments scattered through the page and array, some of which matter when being parsed.
This has all been gleaned from the TikiWiki source. As far as I know no detailed documentation exists for the tiki language.php files.
Represents a tiki language.php file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parse the given input into source units.
input – the source, either a string or filehandle
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Will return a formatted tiki-style language.php file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A tiki unit entry.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Location is defined by the comments in the file. This function will only set valid locations.
location – Where the string is located in the file. Must be a valid location.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
Returns the a list of the location(s) of the string.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Module to provide a translation memory database.
module for parsing TMX translation memeory files.
Class representing a TMX file store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Method to be overridden to initialise headers, etc.
Adds and returns a new unit with the given string as first entry.
Addtranslation method for testing old unit tests.
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Initialises self.body so it never needs to be retrieved from the XML again.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Populates this object from the given xml string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a string containing the file’s XML.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Method to test old unit tests.
Iterator over all the units in this store.
A single unit in the TMX file.
Adds an error message to this unit.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Add a note specifically in a “note” tag.
The origin parameter is ignored
Build a native unit from a foreign unit.
Preserving as much information as possible.
Make a copy of the translation unit.
We don’t want to make a deep copy - this could duplicate the whole XML tree. For now we just serialise and reparse the unit’s XML.
Returns a langset xml Element setup with given parameters.
Retrieves the term from the given languageNode
.
Get the message context.
Get all error messages.
Returns the identifier for this unit. The optional tuid property is used if available, otherwise we inherit .getid(). Note that the tuid property is only mandated to be unique from TMX 2.0.
Retrieves a languageNode
either by language or by index.
Returns a list of all nodes that contain per language information.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Remove all the translator notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Sets the “target” string (second language), or alternatively appends to the list.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Manage the Trados .txt Translation Memory format.
A Trados file looks like this:
<TrU>
<CrD>18012000, 13:18:35
<CrU>CAROL-ANN
<UsC>0
<Seg L=EN_GB>Association for Road Safety \endash Conference
<Seg L=DE_DE>Tagung der Gesellschaft für Verkehrssicherheit
</TrU>
<TrU>
<CrD>18012000, 13:19:14
<CrU>CAROL-ANN
<UsC>0
<Seg L=EN_GB>Road Safety Education in our Schools
<Seg L=DE_DE>Verkehrserziehung an Schulen
</TrU>
RTF control to Unicode map. See http://msdn.microsoft.com/en-us/library/aa140283(v=office.10).aspx
Time format used by Trados .txt
Manages the timestamps in the Trados .txt format of DDMMYYY, hh:mm:ss.
Get the time_struct object.
Get the time in the Trados time format.
Set the time_struct object.
newtime (time.time_struct) – a new time object
Set the time_struct object using a Trados time formated string.
timestring (String) – A Trados time string (DDMMYYYY, hh:mm:ss)
Get the time_struct object.
Get the time in the Trados time format.
A Trados translation memory file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of TradosUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parser to process the given source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Convert Unicode string to Trodas escapes.
Convert Trados text to normal Unicode string.
Module for handling Qt linguist (.ts) files.
This will eventually replace the older ts.py which only supports the older format. While converters haven’t been updated to use this module, we retain both.
TS file format 4.3, 4.8, 5. Example.
Specification of the valid variable entries, 2
Class representing a TS file store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Method to be overridden to initialise headers, etc.
Adds and returns a new unit with the given string as first entry.
Adds the given unit to the last used body node (current context).
If the contextname is specified, switch to that context (creating it if allowed by createifmissing).
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this .ts file.
The ‘sourcelanguage’ attribute was only added to the TS format in Qt v4.5. We return ‘en’ if there is no sourcelanguage set.
We don’t implement setsourcelanguage as users really shouldn’t be altering the source language in .ts files, it should be set correctly by the extraction tools.
ISO code e.g. af, fr, pt_BR
String
Get the target language for this .ts file.
ISO code e.g. af, fr, pt_BR
String
Return a list of all units in this store.
Initialises self.body.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Populates this object from the given xml string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Write the XML document to a file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this .ts file to targetlanguage.
targetlanguage (String) – ISO code e.g. af, fr, pt_BR
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A single term in the TS file.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Add a note specifically in the appropriate comment tag.
Build a native unit from a foreign unit.
Preserving as much information as possible.
Returns an xml Element setup with given parameters.
Retrieves the term from the given languageNode
.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
Retrieves a languageNode
either by language or by index.
We override this to get source and target nodes.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
States whether this unit needs to be reviewed.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Remove all the translator notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Sets the “target” string (second language), or alternatively appends to the list.
This maps the unit “type” attribute to state.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Module for parsing Qt .ts files for translation.
Currently this module supports the old format of .ts files. Some applictaions use the newer .ts format which are documented here: TS file format 4.3, Example
This class implements the functionality for handling plain text files, or similar wiki type files.
Plain text
dokuwiki
MediaWiki
This class represents a text file, made up of txtunits.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Read in text lines and create txtunits from the blocks of text.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
This class represents a block of text from a text file.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the message context.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Gets the unquoted target string.
Iterator that only returns this unit.
Manage the Universal Terminology eXchange (UTX) format.
UTX is a format for terminology exchange, designed it seems with Machine Translation (MT) as it’s primary consumer. The format is created by the Asia-Pacific Association for Machine Translation (AAMT).
It is a bilingual base class derived format with UtxFile
and UtxUnit
providing file and unit level access.
The format can manage monolingual dictionaries but these classes don’t implement that.
The format is implemented according to UTX v1.0 (No longer available from their website. The current UTX version may be downloaded instead).
The UTX format is a Tab Seperated Value (TSV) file in UTF-8. The first two lines are headers with subsequent lines containing a single source target definition.
The files are UTF-8 encoded with no BOM and CR+LF line terminators.
Describe the properties of an UTX generated TAB-delimited dictionary file.
A UTX dictionary file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parsese the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A UTX header entry.
#UTX-S <version>; < source language >/< target language>; <date created>; <optional fields (creator, license, etc.)>
UTX-S version is currently 1.00.
Source language/target language: ISO 639, 3166 formats. In the case of monolingual dictionary, target language should be omitted.
Date created: ISO 8601 format
Optional fields (creator, license, etc.)
A UTX dictionary unit.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the dictionary of values for a UTX line.
Get the message context.
Get the dictionary of values for a UTX line.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Set the dictionary of values for a UTX line.
newdict (Dict) – a new dictionary with UTX line elements
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Manage the Wordfast Translation Memory format.
Wordfast TM format is the Translation Memory format used by the Wordfast computer aided translation tool.
It is a bilingual base class derived format with WordfastTMFile
and WordfastUnit
providing file and unit level access.
Wordfast is a computer aided translation tool. It is an application built on top of Microsoft Word and is implemented as a rather sophisticated set of macros. Understanding that helps us understand many of the seemingly strange choices around this format including: encoding, escaping and file naming.
The implementation covers the full requirements of a Wordfast TM file. The files are simple Tab Separated Value (TSV) files that can be read by Microsoft Excel and other spreadsheet programs. They use the .txt extension which does make it more difficult to automatically identify such files.
The dialect of the TSV files is specified by WordfastDialect
.
The files are UTF-16 or ISO-8859-1 (Latin1) encoded. These choices are most likely because Microsoft Word is the base editing tool for Wordfast.
The format is tab separated so we are able to detect UTF-16 vs Latin-1 by searching for the occurance of a UTF-16 tab character and then continuing with the parsing.
WordfastTime
allows for the correct management of the Wordfast
YYYYMMDD~HHMMSS timestamps. However, timestamps on individual units are
not updated when edited.
WordfastHeader
provides header management support. The header
functionality is fully implemented through observing the behaviour of the
files in real use cases, input from the Wordfast programmers and
public documentation.
Wordfast TM implements a form of escaping that covers two aspects:
Placeable: bold, formating, etc. These are left as is and ignored. It is up to the editor and future placeable implementation to manage these.
Escapes: items that may confuse Excel or translators are escaped as
&'XX;
. These are fully implemented and are converted to and from
Unicode. By observing behaviour and reading documentation we where able
to observe all possible escapes. Unfortunately the escaping differs
slightly between Windows and Mac version. This might cause errors in
future. Functions allow for <_wf_to_char>
and back to Wordfast
escape (<_char_to_wf>
).
The last 4 columns allow users to define and manage extended attributes. These are left as is and are not directly managed byour implemenation.
The tab t character as it would appear in UTF-16 encoding
Mapping of Wordfast &’XX; escapes to correct Unicode characters
Field names for a Wordfast TU
Field names for the Wordfast header
Default or minimum header entries for a Wordfast file
Time format used by Wordfast
Describe the properties of a Wordfast generated TAB-delimited file.
A wordfast translation memory header.
Get the header dictionary.
Get the header dictionary.
A Wordfast translation memory file.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
alias of WordfastUnit
Add a unit to source and location idexes.
Add and returns a new unit with the given source string.
TranslationUnit
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Parsese the given file or file source string.
Reads the given file (or opens the given filename) and parses back to an object.
Convert the string representation back to an object.
Remove a unit from source and locaton indexes.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a bytes representation that can be parsed back using
parsestring()
.
out should be an open file-like objects to write to.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
Indicates if format can store suggestions and alternative translation for a unit
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
Manages time stamps in the Wordfast format of YYYYMMDD~hhmmss.
Get the time_struct object.
Get the time in the Wordfast time format.
Set the time_struct object.
newtime (time.time_struct) – a new time object
Set the time_sturct object using a Wordfast time formated string.
timestring (String) – A Wordfast time string (YYYMMDD~hhmmss)
Get the time_struct object.
Get the time in the Wordfast time format.
A Wordfast translation memory unit.
Adds an error message to this unit.
errorname (string) – A single word to id the error.
errortext (string) – The text describing the error.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Adds a note (comment).
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)
Build a native unit from a foreign unit.
Preserving as much information as possible.
Get the dictionary of values for a Wordfast line.
Get the message context.
Get the dictionary of values for a Wordfast line.
Get all error messages.
Dictionary
A unique identifier for this unit.
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.
A list of source code locations.
List
Note
Shouldn’t be implemented if the format doesn’t support it.
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()
).
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
Indicates whether this unit needs review.
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.
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).
Make a unit obsolete.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
needsreview – Defaults to True.
explanation – Adds an optional explanation as a note.
Do basic format agnostic merging.
Convert a multistring to a list of “rich” string trees.
>>> target = multistring(['foo', 'bar', 'baz'])
>>> TranslationUnit.multistring_to_rich(target)
[<StringElem([<StringElem(['foo'])>])>,
<StringElem([<StringElem(['bar'])>])>,
<StringElem([<StringElem(['baz'])>])>]
Remove all the translator’s notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Convert a “rich” string tree to a multistring
.
>>> from translate.storage.placeables.interfaces import X
>>> rich = [StringElem(['foo', X(id='xxx', sub=[' ']), 'bar'])]
>>> TranslationUnit.rich_to_multistring(rich)
multistring('foo bar')
Set the message context.
Set the dictionary of values for a Wordfast line.
newdict (Dict) – a new dictionary with Wordfast line elements
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
A workflow is defined by a set of states that a translation unit can be in and the (allowed) transitions between these states. A state is defined by a range between -128 and 127, indicating its level of “completeness”. The range is closed at the beginning and open at the end. That is, if a workflow contains states A, B and C where A < B < C, a unit with state number n is in state A if A <= n < B, state B if B <= n < C or state C if C <= n < MAX.
A value of 0 is typically the “empty” or “new” state with negative values reserved for states like “obsolete” or “do not use”.
Format specific workflows should be defined in such a way that the numeric state values correspond to similar states. For example state 0 should be “untranslated” in PO and “new” or “empty” in XLIFF, state 100 should be “translated” in PO and “final” in XLIFF. This allows formats to implicitly define similar states.
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Only contains the constants for default states.
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Module for handling XLIFF files for translation.
The official recommendation is to use the extention .xlf for XLIFF files.
Class representing a XLIFF file store.
A list of file extentions associated with this store type
A list of MIME types associated with this store type
The human usable name of this store type
Add a unit to source and location idexes.
Initialise the file header.
adds the given trans-unit to the last used body node if the filename has changed it uses the slow method instead (will create the nodes required if asked). Returns success.
Append the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
creates a filenode with the given filename. All parameters are needed for XLIFF compliance.
Adds a group tag into the specified file.
Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.
Simple detection based on BOM in case chardet is not available.
Find unit with matching id by checking id_index.
Find the unit with the given source string.
TranslationUnit
or None
Find the units with the given source string.
TranslationUnit
or None
Finds the body node for the given filenode.
Returns the datatype of the stored file. If no filename is given, the datatype of the first file is given.
Returns the date attribute for the file.
If no filename is given, the date of the first file is given. If the date attribute is not specified, None is returned.
Date attribute of file
Date or None
Returns the name of the given file.
Returns all filenames in this XLIFF file.
Finds the filenode with the given name.
Finds the header node for the given filenode.
Return a list of unit ids.
Get the project type for this store.
Get the source language for this store.
Get the target language for this store.
Return a list of all units in this store.
Initialises self.body so it never needs to be retrieved from the XML again.
Return True if the object doesn’t contain any translation units.
Indexes the items in this store. At least .sourceindex should be useful.
The matching criterion to use when merging on.
The default matching criterion for all the subclasses.
string
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Populates this object from the given xml string.
Reads the given file (or opens the given filename) and parses back to an object.
Parses the string to return the correct file object.
Remove a unit from source and locaton indexes.
We want to remove the default file-tag as soon as possible if we know if still present and empty.
Remove the given unit to the object’s list of units.
This method should always be used rather than trying to modify the list manually.
unit (TranslationUnit
) – The unit that will be added.
Make sure source index exists.
Save to the file that data was originally read from, if available.
Write the string representation to the given file (or filename).
Converts to a string containing the file’s XML.
Set the name of the given file.
Set the project type for this store.
Set the source language for this store.
Set the target language for this store.
xliff units have alttrans tags which can be used to store suggestions
Adds the given trans-unit (will create the nodes required if asked).
Success
Boolean
Return the translated string for a given source string.
String or None
Iterator over all the units in this store.
A single term in the xliff file.
Adds an alt-trans tag and alt-trans components to the unit.
txt (String) – Alternative translation of the source text.
Adds an error message to this unit.
Add one location to the list of locations.
Note
Shouldn’t be implemented if the format doesn’t support it.
Add a location or a list of locations.
Note
Most classes shouldn’t need to implement this, but should rather
implement TranslationUnit.addlocation()
.
Warning
This method might be removed in future.
Add a note specifically in a “note” tag.
Build a native unit from a foreign unit.
Preserving as much information as possible.
Check against node tag’s origin (e.g note or alt-trans).
Add the context group to the trans-unit with contexts a list with (type, text) tuples describing each context.
Returns an xml Element setup with given parameters.
Removes the supplied alternative from the list of alt-trans tags.
Retrieves the term from the given languageNode
.
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns <alt-trans> for the given origin as a list of units. No origin means all alternatives.
Get the message context.
Returns the contexts in the context groups with the specified name.
Returns the contexts in the context groups with the specified attributeName and attributeValue.
Get all error messages.
A unique identifier for this unit.
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.
Retrieves a languageNode
either by language or by index.
We override this to get source and target nodes.
Returns a list of locations.
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()
).
Returns the restype attribute in the trans-unit tag.
retrieves the “target” text (second entry), or the entry in the specified language, if it exists.
Returns the length of the target string.
Integer
Note
Plural forms might be combined.
This unit in a list.
Tells whether or not this specific unit has plural strings.
Empty method that should be overridden in sub-classes to infer the current state(_n) of the unit from its current state.
States whether this unit is approved.
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.
Indicates whether this unit is fuzzy.
Indicates whether this unit is a header.
Indicate whether a unit is obsolete.
States whether this unit needs to be reviewed.
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.
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).
Make a unit obsolete.
Mark this unit as approved.
Marks the unit as fuzzy or not.
Marks the unit to indicate whether it needs review.
Adds an optional explanation as a note.
Do basic format agnostic merging.
Override TranslationUnit.multistring_to_rich()
which is used
by the rich_source
and rich_target
properties.
Returns name in Clark notation.
For example namespaced("source")
in an XLIFF document
might return:
{urn:oasis:names:tc:xliff:document:1.1}source
This is needed throughout lxml.
Remove all the translator notes.
A list of functions to use for parsing a string into a rich string tree.
See also
See also
Override TranslationUnit.rich_to_multistring()
which is used
by the rich_source
and rich_target
properties.
Set the message context.
Sets the unique identified for this unit.
only implemented if format allows ids independant from other unit properties like source or context
Sets the target string to the given value.
Ensure that plural count in string matches tags definition.
Iterator that only returns this unit.
Maintain constants and variables used during the walking of a DOM tree (via the function apply).
A node corresponds to a translatable element. A node may have children, which correspond to placeables.
Check if it contains any chunk of text with more than whitespace.
If not, then there’s nothing to translate.
Build a store for the given IDML file.
Build a store for the given XML file.
Return a function which, when called with a Translatable will add a unit to ‘store’. The placeables will be represented as strings according to ‘placeable_quoter’.
Process a translatable DOM node.
Any translatable content present in a child node is treated as a placeable.
See also
For an inline placeable, find the root DOM node for the placeable in its parent.
Consider the diagram. In this pseudo-ODF example, there is an inline span element. However, the span is contained in other tags (which we never process). When splicing the template DOM tree (that is, the DOM which comes from the XML document we’re using to generate a translated XML document), we’ll need to move DOM sub-trees around and we need the roots of these sub-trees:
<p> This is text \/ <- Paragraph containing an inline placeable
<blah> <- Inline placeable's root (which we want to find)
... <- Any number of intermediate DOM nodes
<span> bold text <- The inline placeable's Translatable
holds a reference to this DOM node
Return a tuple with unit source and target DOM objects.
This method is method is meant to provide a way to retrieve the DOM objects for the unit source and target for XLIFF stores.
Generate a replacement functions.
Return a function:
action: etree_Element x base.TranslationUnit -> None
which takes a dom_node and a translation unit. The dom_node is rearranged according to rearrangement of placeables in unit.target (relative to their positions in unit.source).
Given two mappings left: A -> B and right: B -> C, create a hash result_map: A -> C. Only values in left (i.e. things from B) which have corresponding keys in right will have their keys mapped to values in right.
Parse a full XML tag name into namespace and tag name.
>>> parse_tag('{urn:oasis:names:tc:opendocument:xmlns:office:1.0}document-content')
('urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'document-content')
>>> parse_tag('document-content')
('', 'document-content').
Enumerate a tree, applying f to in a pre-order fashion to each node.
parent_unit_node contains the parent of unit_node. For the root of the tree, parent_unit_node == unit_node.
get_children is a single argument function applied to a unit_node to get a list/iterator to its children.
state is used by f to modify state information relating to whatever f does to the tree.
Enumerate a translation store and build a tree with XPath components as nodes and where a node contains a unit if a path from the root of the tree to the node containing the unit, is equal to the XPath of the unit.
The tree looks something like this:
root
`- ('document-content', 1)
`- ('body', 2)
|- ('text', 1)
| `- ('p', 1)
| `- <reference to a unit>
|- ('text', 2)
| `- ('p', 1)
| `- <reference to a unit>
`- ('text', 3)
`- ('p', 1)
`- <reference to a unit>
Initialize me with a DOM node or a DOM document node (the toplevel node you get when parsing an XML file). Then use me to generate fully qualified XML names.
>>> xml = '<office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"></office>'
>>> from lxml import etree
>>> namer = XmlNamer(etree.fromstring(xml))
>>> namer.name('office', 'blah')
{urn:oasis:names:tc:opendocument:xmlns:office:1.0}blah
>>> namer.name('office:blah')
{urn:oasis:names:tc:opendocument:xmlns:office:1.0}blah
I can also give you XmlNamespace objects if you give me the abbreviated namespace name. These are useful if you need to reference a namespace continuously.
>>> office_ns = name.namespace('office')
>>> office_ns.name('foo')
{urn:oasis:names:tc:opendocument:xmlns:office:1.0}foo
This module provides functionality to work with zip files.
This class represents a ZIP file like a directory.
Iterator over (dir, filename) for all files in this directory.
Returns a list of (dir, filename) tuples for all the file names in this directory.
List of all the units in all the files in this directory.
Populate the internal file data.
Iterator over all the units in all the files in this zip file.