Repository: WeblateOrg/weblate

Issue:
Support absolute web links (at least) in PO files
### Describe the problem

Our translators are working on a documentation site that gets updated (in a staging area) almost instantly after they updated their translation. They have no intuitive, direct way to access the result of this rendering, or maybe even the situation _before_ the translation to get more context.


### Describe the solution you'd like

We are thinking about adding the absolute link as a reference (`#:`) to the PO files. They are then showing up as expected in the "Source String Location" section. The only issue is that weblate tries to interpret them as a VCS link, interpreting "https" as the file name and "//www.example.com/path/doc.html" as the line number.
If we could add a detection for web links (either checking for `https?://` or, more generically, for `[\w]+://`), which would lead to just linking to that absolute location, we could very seamlessly use that feature.

While this scenario is not mentioned in any documentation I could find about the "formal" gettext format, I do not think that it contradicts the intention of the reference field.

### Describe alternatives you've considered

Screenshots: Adding screenshots to source strings is cumbersome and does not provide the best experience for the translator. 

I don't know if there are alternative approaches, short of buliding some kind of add-on, hook, or the like.

### Screenshots

![image](https://user-images.githubusercontent.com/2277681/182678868-a3b06642-9c1e-4f54-a3d9-1f43e398973f.png)


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/weblate/trans/templatetags/translations.py b/weblate/trans/templatetags/translations.py
--- a/weblate/trans/templatetags/translations.py
+++ b/weblate/trans/templatetags/translations.py
@@ -603,9 +603,16 @@ def unit_state_title(unit) -> str:
 def try_linkify_filename(
     text, filename: str, line: str, unit, profile, link_class: str = ""
 ):
-    """Attemp to convert `text` to a repo link to `filename:line`."""
+    """
+    Attempt to convert `text` to a repo link to `filename:line`.
+
+    If the `text` is prefixed with http:// or https://, the
+    link will be an absolute link to the specified resource.
+    """
     link = None
-    if profile:
+    if re.search(r"^https?://", text):
+        link = text
+    elif profile:
         link = unit.translation.component.get_repoweb_link(
             filename, line, profile.editor_link
         )


Test patch:
diff --git a/weblate/trans/tests/test_templatetags.py b/weblate/trans/tests/test_templatetags.py
--- a/weblate/trans/tests/test_templatetags.py
+++ b/weblate/trans/tests/test_templatetags.py
@@ -197,6 +197,42 @@ def test_filename_quote(self):
             """,
         )
 
+    def test_absolute_url(self):
+        self.unit.translation.component.repoweb = (
+            "http://example.net/{{filename}}#L{{line}}"
+        )
+        self.unit.location = (
+            "foo.bar:123,bar.foo:321,https://example.com/foo,http://example.org/bar"
+        )
+        self.assertHTMLEqual(
+            get_location_links(self.profile, self.unit),
+            """
+            <a class="wrap-text"
+                href="http://example.net/foo.bar#L123" target="_blank"
+                dir="ltr" rel="noopener noreferrer">
+            foo.bar:123
+            </a>
+            <span class="divisor">•</span>
+            <a class="wrap-text"
+                href="http://example.net/bar.foo#L321" target="_blank"
+                dir="ltr" rel="noopener noreferrer">
+            bar.foo:321
+            </a>
+            <span class="divisor">•</span>
+            <a class="wrap-text"
+                href="https://example.com/foo" target="_blank"
+                dir="ltr" rel="noopener noreferrer">
+            https://example.com/foo
+            </a>
+            <span class="divisor">•</span>
+            <a class="wrap-text"
+                href="http://example.org/bar" target="_blank"
+                dir="ltr" rel="noopener noreferrer">
+            http://example.org/bar
+            </a>
+            """,
+        )
+
 
 class TranslationFormatTestCase(FixtureTestCase):
     def setUp(self):