Repository: WeblateOrg/weblate

Issue:
Improvement: show location for texts in screenshot management
### Steps to reproduce

1. Add a new screenshot
2. Search for a text string
3. See multiple identical results

### Actual behaviour

Sometimes you have the exact same text in multiple places in your project, but the translations can differ depending on the context. This is currently not supported very well in screenshot management, resulting in impossible to make choices like this:

![image](https://user-images.githubusercontent.com/199657/43308724-c35488ca-9182-11e8-8753-f0c887038937.png)

### Expected behaviour

There should be some way to see differentiate the otherwise identical results in the source string list. Showing the context (where possible; I'm not sure any format other than gettext supports it?) and comments would help. A tooltip or something to show locations would also be very useful.

### Server configuration and status

Currently running the `weblate/weblate:2.20-1` docker image:

```
Postgres is up
 * Weblate 2.20
 * Python 2.7.13
 * Django 1.11.12
 * six 1.10.0
 * social-auth-core 1.7.0
 * social-auth-app-django 2.1.0
 * django-appconf 1.0.2
 * Translate Toolkit 2.3.0
 * Whoosh 2.7.4
 * defusedxml 0.5.0
 * Git 2.11.0
 * Pillow (PIL) 1.1.7
 * dateutil 2.5.3
 * lxml 3.7.1
 * django-crispy-forms 1.7.2
 * compressor 2.2
 * djangorestframework 3.8.1
 * user-agents 1.1.0
 * pytz 2018.3
 * pyuca N/A
 * pyLibravatar N/A
 * PyYAML 3.12
 * tesserocr 2.2.2
 * Mercurial 4.0
 * git-svn 2.11.0
 * Database backends: django.db.backends.postgresql_psycopg2
```




<bountysource-plugin>

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/61401631-improvement-show-location-for-texts-in-screenshot-management?utm_campaign=plugin&utm_content=tracker%2F253393&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F253393&utm_medium=issues&utm_source=github).
</bountysource-plugin>


Discussion:
To clarify, the table should list context and location attributes from an unit:

https://github.com/WeblateOrg/weblate/blob/3d3a78eebcad9a60f7644bd11d22bce2704d2f17/weblate/trans/models/unit.py#L339-L340
Code to generate the results table is in javascript:

https://github.com/WeblateOrg/weblate/blob/6ab618151874d6bc029f46fa14fcc0c4e9c5db4d/weblate/static/loader-bootstrap.js#L179-L197

The server side response is generated here:

https://github.com/WeblateOrg/weblate/blob/6ab618151874d6bc029f46fa14fcc0c4e9c5db4d/weblate/screenshots/views.py#L187-L202
Also it seems that while the table contains context, it's not filled in on backend, that should be fixed as well.
So it's not that the context is empty.. it's not linked on backend. Thank you!
> Also it seems that while the table contains context, it's not filled in on backend, that should be fixed as well.

Nor the location.

Resolving patch:
diff --git a/weblate/screenshots/views.py b/weblate/screenshots/views.py
--- a/weblate/screenshots/views.py
+++ b/weblate/screenshots/views.py
@@ -193,7 +193,11 @@ def search_results(code, obj, units=None):
         )
 
     results = [
-        {'text': unit.get_source_plurals()[0], 'pk': unit.source_info.pk}
+        {'text': unit.get_source_plurals()[0],
+         'pk': unit.source_info.pk,
+         'context': unit.context,
+         'location': unit.location}
+
         for unit in units
     ]
 


Test patch: