l.t.u.t.FileImporter(object) : class documentation

Part of lp.translations.utilities.translation_import View In Hierarchy

Known subclasses: lp.translations.utilities.translation_import.POFileImporter, lp.translations.utilities.translation_import.POTFileImporter

Base class for importing translations or translation templates.

This class is meant to be subclassed for the specialised tasks of importing translations (PO)or translation templates (POT) respectively. Subclasses need to implement the importMessage method and extend the constructor to set self.pofile and self.potemplate correctly.

Method __init__ Base constructor to set up common attributes and parse the imported
Method getOrCreatePOTMsgSet Get the POTMsgSet that this message belongs to or create a new
Method share_with_other_side Returns True if translations should be shared with the other side.
Method is_upstream_import_on_sourcepackage Use TranslationMessage.acceptFromUpstreamImportOnPackage`.
Method translations_are_msgids Are these English strings instead of translations?
Method storeTranslationsInDatabase Try to store translations in the database.
Method importMessage Import a single message.
Method importFile Import a parsed file into the database.
Method format_exporter Get the exporter to display a message in error messages.
Method _storeCredits Store credits but only those provided by the maintainer.
Method _validateMessage Validate the message and report success or failure.
Method _acceptMessage Try to approve the message, return None on TranslationConflict.
Method _addUpdateError Add an error returned by updateTranslation.
Method _addConflictError Add an error if there was an edit conflict.
def __init__(self, translation_import_queue_entry, importer, logger=None):
Base constructor to set up common attributes and parse the imported file into a member variable (self.translation_file).

Subclasses must extend this constructor to set the default values according to their needs, most importantly self.pofile and self.potemplate.

Parameterstranslation_import_queue_entryThe queue entry, as has been provided to TranslationImporter.importFile.
importerThe importer to use for parsing the file.
loggerAn optional logger.
def getOrCreatePOTMsgSet(self, message):
Get the POTMsgSet that this message belongs to or create a new one if none was found.
ParametersmessageThe message.
ReturnsThe POTMsgSet instance, existing or new.
@cachedproperty
def share_with_other_side(self):
Returns True if translations should be shared with the other side.
@cachedproperty
def is_upstream_import_on_sourcepackage(self):
Use TranslationMessage.acceptFromUpstreamImportOnPackage`.
@cachedproperty
def translations_are_msgids(self):
Are these English strings instead of translations?

If this template uses symbolic message ids, the English POFile will contain the English original texts that correspond to the symbols.

def _storeCredits(self, potmsgset, credits):
Store credits but only those provided by the maintainer.
def _validateMessage(self, potmsgset, message, translations, message_data):
Validate the message and report success or failure.
def _acceptMessage(self, potmsgset, message, message_data):
Try to approve the message, return None on TranslationConflict.
def storeTranslationsInDatabase(self, message_data, potmsgset):
Try to store translations in the database.

Perform check if a PO file is available and if the message has any translations that can be stored. If an exception is caught, an error is added to the list in self.errors but the translations are stored anyway, marked as having an error.

Parametersmessage_dataThe message data for which translations will be stored.
potmsgsetThe POTMsgSet that this message belongs to.
ReturnsThe updated translation_message entry or None, if no storing war done.
def importMessage(self, message):
Import a single message.

This method must be implemented by the derived class to perform all necessary steps to import a single message into the database.

ParametersmessageThe message to be imported.
RaisesNotImplementedErrorif no implementation is provided.
def importFile(self):
Import a parsed file into the database.

Loop through all message entries in the parsed file and import them using the importMessage.

ReturnsThe errors encountered during the import.
@property
def format_exporter(self):
Get the exporter to display a message in error messages.
def _addUpdateError(self, message, potmsgset, errormsg):
Add an error returned by updateTranslation.

This has been put in a method enhance clarity by removing the long error text from the calling method.

ParametersmessageThe current message from the translation file.
potmsgsetThe current messageset for this message id.
errormsgThe errormessage returned by updateTranslation.
def _addConflictError(self, message, potmsgset):
Add an error if there was an edit conflict.

This has been put in a method enhance clarity by removing the long error text from the calling method.

ParametersmessageThe current message from the translation file.
potmsgsetThe current messageset for this message id.
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.