Commit 9e2b3fe4 authored by Michal Čihař's avatar Michal Čihař

Show nearby messages while translating

parent 166a7d98
......@@ -26,6 +26,10 @@ All settings are stored in :file:`settings.py` (as usual for Django).
API key for Microsoft Translator service, you can register at http://www.bing.com/developers/createapp.aspx
.. envvar:: NEARBY_MESSAGES
How many messages around current one to show during translating.
.. envvar:: SITE_TITLE
Site title to be used in website and emails as well.
......
......@@ -156,6 +156,19 @@
<li><a href="/js/similar/{{ unit.id }}/">{% trans "Similar messages" %}</a></li>
</ul>
<div id="tab-nearby">
<table>
<thead>
<tr><th>{% trans "Source" %}</th><th>{% trans "Translation" %}</th></tr>
</thead>
<tbody>
{% for item in unit.nearby %}
<tr>
<td class="translatetext">{{ item.source|fmttranslation }}</td>
<td class="translatetext">{{ item.target|fmttranslation:unit.translation.language }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
......
......@@ -248,3 +248,6 @@ EMAIL_SUBJECT_PREFIX = '[%s] ' % SITE_TITLE
# Enable remote hooks
ENABLE_HOOKS = True
# Number of nearby messages to show in each direction
NEARBY_MESSAGES = 5
......@@ -612,6 +612,18 @@ class Unit(models.Model):
check = check
)
def nearby(self):
'''
Returns list of nearby messages based on location.
'''
print self.position - settings.NEARBY_MESSAGES
print self.position + settings.NEARBY_MESSAGES
return Unit.objects.filter(
translation = self.translation,
position__gte = self.position - settings.NEARBY_MESSAGES,
position__lte = self.position + settings.NEARBY_MESSAGES,
)
class Suggestion(models.Model):
checksum = models.CharField(max_length = 40, default = '', blank = True, db_index = True)
target = models.TextField()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment