storage

Classes that represent various storage formats for localization.

base

Base classes for storage interfaces.

class translate.storage.base.DictStore(unitclass=None, encoding=None)
Extensions = None

A list of file extentions associated with this store type

Mimetypes = None

A list of MIME types associated with this store type

Name = 'Base translation store'

The human usable name of this store type

UnitClass

alias of TranslationUnit

add_unit_to_index(unit)

Add a unit to source and location idexes

addsourceunit(source)

Add and returns a new unit with the given source string.

Return type:

TranslationUnit

addunit(unit)

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.

Parameters:

unit (TranslationUnit) – The unit that will be added.

detect_encoding(text: bytes, default_encodings: List[str] | None = None) Tuple[str, str]

Try to detect a file encoding from text, using either the chardet lib or by trying to decode the file.

static fallback_detection(text)

Simple detection based on BOM in case chardet is not available.

findid(id)

find unit with matching id by checking id_index

findunit(source)

Find the unit with the given source string.

Return type:

TranslationUnit or None

findunits(source)

Find the units with the given source string.

Return type:

TranslationUnit or None

getids()

return a list of unit ids

getprojectstyle()

Get the project type for this store.

getsourcelanguage()

Get the source language for this store.

gettargetlanguage()

Get the target language for this store.

getunits()

Return a list of all units in this store.

isempty()

Return True if the object doesn’t contain any translation units.

makeindex()

Indexes the items in this store. At least .sourceindex should be useful.

property merge_on

The matching criterion to use when merging on.

Returns:

The default matching criterion for all the subclasses.

Return type:

string

parse(data)

parser to process the given source string

classmethod parsefile(storefile)

Reads the given file (or opens the given filename) and parses back to an object.

classmethod parsestring(storestring)

Convert the string representation back to an object.

remove_unit_from_index(unit)

Remove a unit from source and locaton indexes

removeunit(unit)

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.

Parameters:

unit (TranslationUnit) – The unit that will be added.

require_index()

make sure source index exists

save()

Save to the file that data was originally read from, if available.

savefile(storefile)

Write the string representation to the given file (or filename).

serialize(out)

Converts to a bytes representation that can be parsed back using