Skip to content

Commit

Permalink
Show more matching units in other translations tab
Browse files Browse the repository at this point in the history
- Include units with same source, but different context
- Include units with same context, but different source

Those don't have to be bugs to be translated differently (thus
consistency check will not fire), but still it might be useful to see
them.

Fixes WeblateOrg#1429
Fixes WeblateOrg#1503

Signed-off-by: Michal Čihař <[email protected]>
  • Loading branch information
nijel committed Jun 8, 2017
1 parent 543a0ea commit f989d61
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes
weblate 2.15
------------

* Show more related translations in other translations.
* Add option to see translations of current unit to other languages.
* Use 4 plural forms for Lithuanian by default.
* Fixed upload for monolingual files of different format.
Expand Down
4 changes: 4 additions & 0 deletions weblate/static/style-bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,7 @@ legend {
counter-increment: tos_paragraph;
content: counter(tos_chapter) "." counter(tos_paragraph) ". ";
}

.vertical-badge .badge {
clear: right;
}
14 changes: 12 additions & 2 deletions weblate/templates/translate.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,18 @@ <h5>
<tbody>
{% for item in others %}
<tr>
<td{% if item.translated and item.translation.subproject != unit.translation.subproject %} rowspan="2"{% endif %}>
{% if item.translation.subproject == unit.translation.subproject %}<span class="badge pull-right flip">{% trans "This translation" %}</span>{% endif %}
<td{% if item.translated and item.translation.subproject != unit.translation.subproject %} rowspan="2"{% endif %} class="vertical-badge">
{% if item.source == unit.source and item.context == unit.context %}
{% elif item.source == unit.source %}
<span class="badge pull-right flip" title="{% trans "This string has different context but same source." %}">{% trans "Different context" %}</span>
{% elif item.context == unit.context %}
<span class="badge pull-right flip" title="{% trans "This string has different source but same context." %}">{% trans "Different source" %}</span>
{% else %}
<span class="badge pull-right flip">Bug!</span>
{% endif %}
{% if item.translation.subproject == unit.translation.subproject %}
<span class="badge pull-right flip">{% trans "This translation" %}</span>
{% endif %}
{% get_state_badge item %}
<a href="{{ item.get_absolute_url }}">{{ item.translation.subproject }}</a>
</td>
Expand Down
1 change: 0 additions & 1 deletion weblate/trans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,6 @@ def clean(self):
pk=self.cleaned_data['merge'],
translation__subproject__project=project,
translation__language=self.translation.language,
id_hash=self.cleaned_data['unit'].id_hash,
)
except Unit.DoesNotExist:
raise ValidationError(_('Merged unit not found!'))
Expand Down
28 changes: 28 additions & 0 deletions weblate/trans/models/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,3 +1094,31 @@ def checksum(self):

def same_units(self):
return Unit.objects.same(self)

def get_other_units(self):
"""Returns other units to show while translating."""
kwargs = {
'translation__subproject__project':
self.translation.subproject.project,
'translation__language':
self.translation.language,
'translated': True,
}

same = Unit.objects.same(self, False)
same_id = Unit.objects.prefetch().filter(
id_hash=self.id_hash,
**kwargs
)
same_source = Unit.objects.prefetch().filter(
source=self.source,
**kwargs
)

result = same | same_id | same_source

# Is it only this unit?
if result.count() == 1:
return Unit.objects.none()

return result
5 changes: 1 addition & 4 deletions weblate/trans/views/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,7 @@ def translate(request, project, subproject, lang):
# Prepare form
form = TranslationForm(request.user.profile, translation, unit)

others = Unit.objects.same(unit, False)
# Is it only this unit?
if others.count() == 1:
others = Unit.objects.none()
others = unit.get_other_units()

return render(
request,
Expand Down

0 comments on commit f989d61

Please sign in to comment.