def save(self, *args, **kwargs): """ Wrapper around save to warn when save did not come from git backend (eg. commit or by parsing file). """ # Warn if request is not coming from backend if 'backend' not in kwargs: self.log_error( 'Unit.save called without backend sync: %s', ''.join(traceback.format_stack()) ) else: del kwargs['backend'] # Pop parameter indicating that we don't have to process content same_content = kwargs.pop('same_content', False) same_state = kwargs.pop('same_state', False) # Keep the force_insert for parent save force_insert = kwargs.get('force_insert', False) # Store number of words if not same_content or not self.num_words: self.num_words = len(self.get_source_plurals()[0].split()) # Actually save the unit super(Unit, self).save(*args, **kwargs) # Update checks if content or fuzzy flag has changed if not same_content or not same_state: self.run_checks(same_state, same_content, force_insert) # Update fulltext index if content has changed or this is a new unit if force_insert or not same_content: update_index_unit(self)
def save(self, *args, **kwargs): """ Wrapper around save to warn when save did not come from git backend (eg. commit or by parsing file). """ # Warn if request is not coming from backend if 'backend' not in kwargs: weblate.logger.error( 'Unit.save called without backend sync: %s', ''.join(traceback.format_stack()) ) else: del kwargs['backend'] # Pop parameter indicating that we don't have to process content same_content = kwargs.pop('same_content', False) same_state = kwargs.pop('same_state', False) # Keep the force_insert for parent save force_insert = kwargs.get('force_insert', False) # Store number of words if not same_content or not self.num_words: self.num_words = len(self.get_source_plurals()[0].split()) # Actually save the unit super(Unit, self).save(*args, **kwargs) # Update checks if content or fuzzy flag has changed if not same_content or not same_state: self.run_checks(same_state, same_content, force_insert) # Update fulltext index if content has changed or this is a new unit if force_insert or not same_content: update_index_unit(self, force_insert)
def do_index_update(self): translation = self.subproject.translation_set.get(language_code='cs') unit = translation.unit_set.get( source='Try Weblate at <http://demo.weblate.org/>!\n' ) update_index_unit(unit, True) update_index_unit(unit, False)
def update_source_units(self, previous_source): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__subproject=self.translation.subproject, context=self.context, ).exclude(id=self.id) # Update source, number of words and content_hash same_source.update(source=self.source, num_words=self.num_words, content_hash=self.content_hash) # Find reverted units reverted = same_source.filter(translated=False, fuzzy=True, previous_source=self.source) reverted_ids = set(reverted.values_list('id', flat=True)) reverted.update(translated=True, fuzzy=False, previous_source='') # Set fuzzy on changed same_source.filter(translated=True).exclude( id__in=reverted_ids).update( translated=False, fuzzy=True, previous_source=previous_source, ) # Update source index and stats for unit in same_source.iterator(): update_index_unit(unit, True) unit.translation.update_stats()
def update_source_units(self): """Updates source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__subproject=self.translation.subproject, context=self.context, ) # Update source and contentsum previous_source = same_source[0].source same_source.update( source=self.target, contentsum=calculate_checksum(self.source, self.context), ) same_source.filter( translated=True ).exclude( id=self.id ).update( translated=False, fuzzy=True, previous_source=previous_source, ) # Update source index, it's enough to do it for one as we index by # checksum which is same for all update_index_unit(self, True)
def save(self, same_content=False, same_state=False, force_insert=False, backend=False, **kwargs): """ Wrapper around save to warn when save did not come from git backend (eg. commit or by parsing file). """ # Warn if request is not coming from backend if not backend: self.log_error( 'Unit.save called without backend sync: %s', ''.join(traceback.format_stack()) ) # Store number of words if not same_content or not self.num_words: self.num_words = len(self.get_source_plurals()[0].split()) # Actually save the unit super(Unit, self).save(**kwargs) # Update checks if content or fuzzy flag has changed if not same_content or not same_state: self.run_checks(same_state, same_content, force_insert) # Update fulltext index if content has changed or this is a new unit if force_insert or not same_content: update_index_unit(self)
def update_source_units(self): """Updates source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__subproject=self.translation.subproject, context=self.context, ) # Update source and contentsum previous_source = same_source[0].source same_source.update( source=self.target, contentsum=calculate_checksum(self.source, self.context), ) same_source.filter(translated=True).exclude(id=self.id).update( translated=False, fuzzy=True, previous_source=previous_source, ) # Update source index for unit in same_source.iterator(): update_index_unit(unit, True)
def update_source_units(self, previous_source, user): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__subproject=self.translation.subproject, context=self.context, ).exclude( id=self.id ) # Update source, number of words and content_hash same_source.update( source=self.source, num_words=self.num_words, content_hash=self.content_hash ) # Find reverted units reverted = same_source.filter( translated=False, fuzzy=True, previous_source=self.source ) reverted_ids = set(reverted.values_list('id', flat=True)) reverted.update( translated=True, fuzzy=False, previous_source='' ) # Set fuzzy on changed same_source.filter( translated=True ).exclude( id__in=reverted_ids ).update( translated=False, fuzzy=True, previous_source=previous_source, ) # Update source index and stats for unit in same_source.iterator(): unit.update_has_comment(update_stats=False) unit.update_has_suggestion(update_stats=False) unit.run_checks(False, False) update_index_unit(unit) Change.objects.create( unit=unit, translation=unit.translation, action=Change.ACTION_SOURCE_CHANGE, user=user, author=user, old=previous_source, target=self.source, ) unit.translation.update_stats()
def do_index_update(self): self.edit_unit( 'Hello, world!\n', 'Nazdar svete!\n' ) unit = self.get_translation().unit_set.get( source='Hello, world!\n', ) update_index_unit(unit) update_index_unit(unit)
def update_source_units(self, previous_source, user): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__component=self.translation.component, context=self.context, ).exclude( id=self.id ) # Update source, number of words and content_hash same_source.update( source=self.source, num_words=self.num_words, content_hash=self.content_hash ) # Find reverted units reverted = same_source.filter( state=STATE_FUZZY, previous_source=self.source ) reverted_ids = set(reverted.values_list('id', flat=True)) reverted.update( state=STATE_TRANSLATED, previous_source='' ) # Set fuzzy on changed same_source.filter( state=STATE_TRANSLATED ).exclude( id__in=reverted_ids ).update( state=STATE_FUZZY, previous_source=previous_source, ) # Update source index and stats for unit in same_source.iterator(): unit.update_has_comment() unit.update_has_suggestion() unit.run_checks(False, False) update_index_unit(unit) Change.objects.create( unit=unit, action=Change.ACTION_SOURCE_CHANGE, user=user, author=user, old=previous_source, target=self.source, ) unit.translation.invalidate_cache()
def update_source_units(self, previous_source): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__subproject=self.translation.subproject, context=self.context, ).exclude( id=self.id ) # Update source, number of words and content_hash same_source.update( source=self.source, num_words=self.num_words, content_hash=self.content_hash ) # Find reverted units reverted = same_source.filter( translated=False, fuzzy=True, previous_source=self.source ) reverted_ids = set(reverted.values_list('id', flat=True)) reverted.update( translated=True, fuzzy=False, previous_source='' ) # Set fuzzy on changed same_source.filter( translated=True ).exclude( id__in=reverted_ids ).update( translated=False, fuzzy=True, previous_source=previous_source, ) # Update source index and stats for unit in same_source.iterator(): update_index_unit(unit, True) unit.translation.update_stats()
def update_source_units(self): """Updates source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__subproject=self.translation.subproject, context=self.context, ) # Update source and contentsum same_source.update( source=self.target, contentsum=calculate_checksum(self.source, self.context), ) # Update source index, it's enough to do it for one as we index by # checksum which is same for all update_index_unit(self, True)
def do_index_update(self): self.edit_unit("Hello, world!\n", "Nazdar svete!\n") unit = self.get_translation().unit_set.get(source="Hello, world!\n") # update_index_unit(unit, False) update_index_unit(unit, True) update_index_unit(unit, True)
def do_index_update(self): translation = self.subproject.translation_set.get(language_code='cs') unit = translation.unit_set.get( source='Try Weblate at <http://demo.weblate.org/>!\n') update_index_unit(unit, True) update_index_unit(unit, False)