Repository: WeblateOrg/weblate

Issue:
Conflict of phrases with same msgid but different msgctxt
**Describe the bug**

Hi!

For phrases that have the same msgid with different msgctxt in the PO file (monolingual) I get an alert "The component contains several duplicated translation strings."

What's my mistake?

When I try to translate, I find only one version of the phrase and I don’t see for what context this phrase is. I tried to translate - the last phrase was translated.

**To Reproduce**

<details>
<summary>menu/ru/trans.po</summary>

```po
msgid ""
msgstr ""
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"

msgctxt "company"
msgid "employee"
msgstr "Сотрудники"

msgctxt "companyv2"
msgid "employee"
msgstr "Сотрудники"
```

</details>

<details>
<summary>menu/en/trans.po</summary>

```po
msgid ""
msgstr ""
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"

msgctxt "company"
msgid "employee"
msgstr "Employees"

msgctxt "companyv2"
msgid "employee"
msgstr "Employees"
```

</details>

<details>
<summary>menu/uk/trans.po</summary>

```po
msgid ""
msgstr ""
"Language: uk\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Weblate 4.1.1\n"

msgctxt "company"
msgid "employee"
msgstr ""

msgctxt "companyv2"
msgid "employee"
msgstr "Співробітники"
```

</details>

<details>
<summary>Settings</summary>

![image](https://user-images.githubusercontent.com/4448063/86512906-463eb600-be1f-11ea-9688-cfb0bf8a48c0.png)

</details>

**Expected behavior**

Phrases with the same msgid and different msgctxt are different phrases.

**Screenshots**

<details>

![image](https://user-images.githubusercontent.com/4448063/86512854-ff50c080-be1e-11ea-96c2-4ec812ed7a0a.png)

</details>

**Server configuration and status**

<details>
<summary>list_version</summary>

```
 * Weblate: 4.1.1
 * Django: 3.0.7
 * siphashc: 1.3
 * Whoosh: 2.7.4
 * translate-toolkit: 3.0.0
 * lxml: 4.5.1
 * Pillow: 7.1.2
 * bleach: 3.1.5
 * python-dateutil: 2.8.1
 * social-auth-core: 3.3.3
 * social-auth-app-django: 3.4.0
 * django-crispy-forms: 1.9.1
 * oauthlib: 3.1.0
 * django-compressor: 2.4
 * djangorestframework: 3.11.0
 * django-filter: 2.3.0
 * django-appconf: 1.0.4
 * user-agents: 2.1
 * filelock: 3.0.12
 * setuptools: 40.8.0
 * jellyfish: 0.8.2
 * openpyxl: 3.0.1
 * celery: 4.4.5
 * kombu: 4.6.10
 * translation-finder: 2.1
 * html2text: 2020.1.16
 * pycairo: 1.16.2
 * pygobject: 3.30.4
 * diff-match-patch: 20181111
 * requests: 2.24.0
 * django-redis: 4.12.1
 * hiredis: 1.0.1
 * sentry_sdk: 0.15.1
 * Cython: 0.29.20
 * misaka: 2.1.1
 * GitPython: 3.1.3
 * borgbackup: 1.1.13
 * pyparsing: 2.4.7
 * Python: 3.7.3
 * Git: 2.20.1
 * psycopg2: 2.8.5
 * psycopg2-binary: 2.8.5
 * phply: 1.2.5
 * chardet: 3.0.4
 * ruamel.yaml: 0.16.10
 * tesserocr: 2.5.1
 * akismet: 1.1
 * boto3: 1.14.6
 * zeep: 3.4.0
 * aeidon: 1.7.0
 * iniparse: 0.5
 * mysqlclient: 1.4.6
 * Mercurial: 5.4.1
 * git-svn: 2.20.1
 * git-review: 1.28.0
 * hub: 2.13.0
 * lab: 0.16
 * Redis server: 4.0.12
 * PostgreSQL server: 9.6.11
 * Database backends: django.db.backends.postgresql
 * Cache backends: default:RedisCache, avatar:FileBasedCache
 * Email setup: django.core.mail.backends.smtp.EmailBackend: mx.ibc.ru
 * OS encoding: filesystem=utf-8, default=utf-8
 * Celery: redis://cache:6379/1, redis://cache:6379/1, regular
 * Platform: Linux 4.15.0-109-generic (x86_64)
```

</details>

**Weblate deploy checks**

<details>
<summary>deploy --check</summary>

```
System check identified some issues:

WARNINGS:
?: (security.W004) You have not set a value for the SECURE_HSTS_SECONDS setting. If your entire site is served only over SSL, you may want to consider setting a value and enabling HTTP Strict Transport Security. Be sure to read the documentation first; enabling HSTS carelessly can cause serious, irreversible problems.
?: (security.W008) Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS.
?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions.

INFOS:
?: (weblate.I021) Error collection is not set up, it is highly recommended for production use
	HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#collecting-errors
?: (weblate.I028) Backups are not configured, it is highly recommended for production use
	HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/backup.html
```

</details>



Discussion:
For monolingual files only one of msgid or msgctx is currently used as string identifier.
This issue has been put aside. Currently, it is unclear whether it will ever be implemented as it seems to cover too narrow of a use case or doesn't seem to fit into Weblate. Please try to clarify the use case or consider proposing something more generic to make it useful to more users.

Resolving patch:
diff --git a/weblate/formats/ttkit.py b/weblate/formats/ttkit.py
--- a/weblate/formats/ttkit.py
+++ b/weblate/formats/ttkit.py
@@ -459,7 +459,11 @@ def context(self):
         """
         # Monolingual PO files
         if self.template is not None:
-            return self.template.source or self.template.getcontext()
+            context = self.template.getcontext().strip()
+            source = self.template.source.strip()
+            if source and context:
+                return f"{context}.{source}"
+            return source or context
         return super().context
 
     @cached_property


Test patch: