def translate(self, request, new_target, new_state, change_action=None, propagate=True): """Store new translation of a unit.""" # Fetch current copy from database and lock it for update self.old_unit = Unit.objects.select_for_update().get(pk=self.pk) # Update unit and save it if isinstance(new_target, six.string_types): self.target = new_target not_empty = bool(new_target) else: self.target = join_plural(new_target) not_empty = bool(max(new_target)) # Newlines fixup if 'dos-eol' in self.all_flags: self.target = NEWLINES.sub('\r\n', self.target) if not_empty: self.state = new_state else: self.state = STATE_EMPTY saved = self.save_backend(request, change_action=change_action, propagate=propagate) if (propagate and request and self.target != self.old_unit.target and self.state >= STATE_TRANSLATED): update_memory(request.user, self) return saved
def translate(self, request, new_target, new_state, change_action=None, propagate=True): """Store new translation of a unit.""" # Fetch current copy from database and lock it for update self.old_unit = Unit.objects.select_for_update().get(pk=self.pk) # Update unit and save it if isinstance(new_target, six.string_types): self.target = new_target not_empty = bool(new_target) else: self.target = join_plural(new_target) not_empty = bool(max(new_target)) # Newlines fixup if 'dos-eol' in self.all_flags: self.target = NEWLINES.sub('\r\n', self.target) if not_empty: self.state = new_state else: self.state = STATE_EMPTY saved = self.save_backend( request, change_action=change_action, propagate=propagate ) if (propagate and request and self.target != self.old_unit.target and self.state >= STATE_TRANSLATED): update_memory(request.user, self) return saved
def translate( self, user, new_target, new_state, change_action=None, propagate=True, author=None, ): """Store new translation of a unit.""" # Fetch current copy from database and lock it for update self.old_unit = Unit.objects.select_for_update().get(pk=self.pk) # Handle simple string units if isinstance(new_target, str): new_target = [new_target] # Apply autofixes if not self.translation.is_template: new_target, self.fixups = fix_target(new_target, self) # Update unit and save it self.target = join_plural(new_target) not_empty = bool(max(new_target)) # Newlines fixup if "dos-eol" in self.all_flags: self.target = NEWLINES.sub("\r\n", self.target) if not_empty: self.state = new_state else: self.state = STATE_EMPTY self.original_state = self.state saved = self.save_backend( user, change_action=change_action, propagate=propagate, author=author ) # Enforced checks can revert the state to needs editing (fuzzy) if ( self.state >= STATE_TRANSLATED and self.translation.component.enforced_checks and self.all_checks_names & set(self.translation.component.enforced_checks) ): self.state = self.original_state = STATE_FUZZY self.save(same_state=True, same_content=True, update_fields=["state"]) if ( propagate and user and self.target != self.old_unit.target and self.state >= STATE_TRANSLATED ): update_memory(user, self) return saved
def translate( self, user, new_target, new_state, change_action=None, propagate=True ): """Store new translation of a unit.""" # Fetch current copy from database and lock it for update self.old_unit = Unit.objects.select_for_update().get(pk=self.pk) # Update unit and save it if isinstance(new_target, six.string_types): self.target = new_target not_empty = bool(new_target) else: self.target = join_plural(new_target) not_empty = bool(max(new_target)) # Newlines fixup if 'dos-eol' in self.all_flags: self.target = NEWLINES.sub('\r\n', self.target) if not_empty: self.state = new_state else: self.state = STATE_EMPTY self.original_state = self.state saved = self.save_backend( user, change_action=change_action, propagate=propagate ) # Enforced checks can revert the state to needs editing (fuzzy) if ( self.state >= STATE_TRANSLATED and self.check_set.filter( check__in=self.translation.component.enforced_checks ).exists() ): self.state = self.original_state = STATE_FUZZY self.save(same_state=True, same_content=True, update_fields=['state']) if ( propagate and user and self.target != self.old_unit.target and self.state >= STATE_TRANSLATED ): update_memory(user, self) return saved