l.t.b.t.BaseTranslationView(LaunchpadView) : class documentation

Part of lp.translations.browser.translationmessage View In Hierarchy

Known subclasses: lp.translations.browser.pofile.POFileTranslateView, lp.translations.browser.translationmessage.CurrentTranslationMessagePageView

Base class that implements a framework for modifying translations.

This class provides a basis for building a batched translation page. It relies on one or more subviews being used to actually display the translations and form elements. It processes the form submitted and constructs data which can be then fed back into the subviews.

The subviews must be (or behave like) CurrentTranslationMessageViews.

Child classes must define:
  • self.pofile
  • _buildBatchNavigator()
  • _initializeTranslationMessageViews()
  • _submitTranslations()
Method label The label will be used as the main page heading.
Method initialize Undocumented
Method share_with_other_side Should these translations be shared with the other side?
Method user_is_official_translator Determine whether the current user is an official translator.
Method form_is_writeable Whether the form should accept write operations.
Method _extractLockTimestamp Extract the lock timestamp from the request.
Method _checkSubmitConditions Verify that this submission is possible and valid.
Method _buildBatchNavigator Construct a BatchNavigator of POTMsgSets and return it.
Method _initializeTranslationMessageViews Construct subviews as necessary.
Method _submitTranslations Handle translations submitted via a form.
Method _receiveTranslations Process and store submitted translations for potmsgset.
Method _storeTranslations Store the translation submitted for a POTMsgSet.
Method _approveTranslation Approve message.
Method _areSuggestionsEmpty Return true if all suggestions are empty strings or None.
Method _prepareView Collect data and build a TranslationMessageView for display.
Method _initializeAltLanguage Initialize the alternative language widget and check form data.
Method _extractFormPostedTranslations Look for translations for this POTMsgSet in the form submitted.
Method _observeTranslationUpdate Observe that a translation was updated for the potmsgset.
Method _buildRedirectParams Construct parameters for redirection.
Method _redirect Redirect to the given url adding the selected filtering rules.
Method _redirectToNextPage After a successful submission, redirect to the next batch page.
@property
def label(self):
The label will be used as the main page heading.
def initialize(self):
Undocumented
def _extractLockTimestamp(self):
Extract the lock timestamp from the request.

The lock_timestamp is used to detect conflicting concurrent translation updates: if the translation that is being changed has been set after the current form was generated, the user chose a translation based on outdated information. In that case there is a conflict.

def _checkSubmitConditions(self):
Verify that this submission is possible and valid.
RaisesUnexpectedFormData if conditions are not met. In principle the user should not have been given the option to submit the current request.
@cachedproperty
def share_with_other_side(self):
Should these translations be shared with the other side?
def _buildBatchNavigator(self):
Construct a BatchNavigator of POTMsgSets and return it.
def _initializeTranslationMessageViews(self):
Construct subviews as necessary.
def _submitTranslations(self):
Handle translations submitted via a form.

Return True if processing went fine; return False if errors occurred.

Implementing this method is complicated. It needs to find out what TranslationMessage were updated in the form post, call _receiveTranslations() for each of those, check for errors that may have occurred during that (displaying them using addErrorNotification), and otherwise call _redirectToNextPage if everything went fine.

def _receiveTranslations(self, potmsgset):
Process and store submitted translations for potmsgset.
ReturnsAn error string in case of failure, or None otherwise.
def _storeTranslations(self, potmsgset):
Store the translation submitted for a POTMsgSet.
RaisesGettextValidationErrorif the submitted translation fails gettext validation. The translation is not stored.
TranslationConflictif the current translations have changed since the translator/reviewer last saw them. The submitted translations are stored as suggestions.
def _approveTranslation(self, message, force_diverge=False):
Approve message.
def _areSuggestionsEmpty(self, suggestions):
Return true if all suggestions are empty strings or None.
def _prepareView(self, view_class, current_translation_message, pofile, can_edit, error=None):
Collect data and build a TranslationMessageView for display.
def _initializeAltLanguage(self):
Initialize the alternative language widget and check form data.
@property
def user_is_official_translator(self):
Determine whether the current user is an official translator.
@cachedproperty
def form_is_writeable(self):
Whether the form should accept write operations.
def _extractFormPostedTranslations(self, potmsgset):
Look for translations for this POTMsgSet in the form submitted.

Store the new translations at self.form_posted_translations and its fuzzy status at self.form_posted_needsreview, keyed on the POTMsgSet.

In this method, we look for various keys in the form, and use them as follows:

  • 'msgset_ID' to know if self is part of the submitted form. If it isn't found, we stop parsing the form and return.
  • 'msgset_ID_LANGCODE_translation_PLURALFORM': Those will be the submitted translations and we will have as many entries as plural forms the language self.context.language has. This identifier format is generated by TranslationMessage.makeHTMLID.
  • 'msgset_ID_LANGCODE_needsreview': If present, will note that the 'needs review' flag has been set for the given translations.

In all those form keys, 'ID' is the ID of the POTMsgSet.

def _observeTranslationUpdate(self, potmsgset):
Observe that a translation was updated for the potmsgset.

Subclasses should redefine this method if they need to watch the successful calls to potmsgset.updateTranslation.

def _buildRedirectParams(self):
Construct parameters for redirection.

Redefine this method if you have additional parameters to preserve.

def _redirect(self, new_url):
Redirect to the given url adding the selected filtering rules.
def _redirectToNextPage(self):
After a successful submission, redirect to the next batch page.
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.