Skip to content

Fix: translation repository browser#19184

Draft
BrenABarn wants to merge 8 commits intoWeblateOrg:mainfrom
BrenABarn:fix/translation-repoweb
Draft

Fix: translation repository browser#19184
BrenABarn wants to merge 8 commits intoWeblateOrg:mainfrom
BrenABarn:fix/translation-repoweb

Conversation

@BrenABarn
Copy link
Copy Markdown

Fixes #12308

What this PR does

Adds a new optional "Repository browser for translations" field to the component settings. When set, this URL is used to generate links to translation files instead of the existing "Repository browser" field. If left empty, it falls back to the existing field, maintaining backward compatibility.

Changes

  • New repoweb_translations model field on Component
  • Database migration
  • Updated get_repoweb_link to accept is_translation parameter
  • Updated translation_file_link in edit view to use the new field
  • Documentation added for the new field
  • Tests added for the new behavior and fallback logic

@BrenABarn BrenABarn requested a review from nijel as a code owner April 23, 2026 00:15
@BrenABarn BrenABarn changed the title Fix/translation repoweb Fix: translation repository browser Apr 23, 2026
@nijel nijel requested a review from Copilot April 23, 2026 06:22
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

Copy link
Copy Markdown
Member

@nijel nijel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request. Besides the bits I've commented inline, this needs to be exposed in the API and deserves a changelog entry.

I've also triggered copilot review now.

Comment thread docs/admin/projects.rst
You can use :ref:`markup`.

For example on GitHub, use something like:
``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}``
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will break rendering without newline:

Suggested change
``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}``
``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}``

Also, the seealso should be present in both of thse.

Comment thread weblate/trans/views/edit.py Outdated
"1",
is_translation=True,
user=user,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes support for direct https links.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration is not based on the current main:

Conflicting migrations detected; multiple leaf nodes in the migration graph: (0069_component_repoweb_translations, 0073_alter_change_action in trans).

Please rename it and adjust dependencies.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for a separate “repository browser” URL specifically for translation files, so the translation editor can link to a different repo than the source-string locations (fixing #12308).

Changes:

  • Adds a new Component.repoweb_translations field (with migration) and exposes it in component settings forms.
  • Extends Component.get_repoweb_link() with an is_translation flag to select the appropriate template (with fallback behavior) and adds tests for the new logic.
  • Documents the new setting in the admin documentation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
weblate/trans/models/component.py Adds repoweb_translations field and is_translation option in get_repoweb_link() template selection.
weblate/trans/migrations/0069_component_repoweb_translations.py Adds DB field for repoweb_translations.
weblate/trans/forms.py Exposes the new field in component settings UI.
weblate/trans/views/edit.py Updates translation editor context to generate translation file links via get_repoweb_link(..., is_translation=True).
docs/admin/projects.rst Documents “Repository browser for translations”.
weblate/trans/tests/test_component.py Adds tests validating selection and fallback logic for translation repoweb templates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1822 to 1827
@@ -1813,7 +1826,9 @@ def get_repoweb_link(
here.
"""
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for get_repoweb_link now says it generates a link to the “source code browser”, but the new is_translation flag makes it generate translation file links as well. Update the docstring to reflect the broader behavior so callers understand when to use is_translation vs. the default.

Copilot uses AI. Check for mistakes.
Comment thread docs/admin/projects.rst
You can use :ref:`markup`.

For example on GitHub, use something like:
``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}``
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RST directives generally need a blank line before them. Here .. seealso:: directly follows the example URL line, which can trigger Sphinx/reST warnings or mis-parsing. Add a blank line between the example and the .. seealso:: directive.

Suggested change
``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}``
``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}``

Copilot uses AI. Check for mistakes.
Comment thread weblate/trans/views/edit.py Outdated
Comment on lines +785 to +793
unit.translation.component.get_repoweb_link(
unit.translation.filename,
# '1' as a placeholder, because `get_repoweb_link` can't currently
# generate links without line specified. Although it's ok to use
# '' or '0' on GitHub or GitLab, let's play it safe for now.
"1",
is_translation=True,
user=user,
)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translation_file_link previously rendered as linkified HTML (via try_linkify_filename) with the filename as the visible text and support for user editor_link. It now returns a raw URL string from get_repoweb_link, which will be displayed as plain text (and not clickable) in translate.html and changes behavior for users with editor_link configured. Consider restoring the prior output shape (SafeString anchor with filename as label) while selecting the translation repoweb template (e.g., by extending the helper to support translation links or wrapping the generated URL in the same markup).

Suggested change
unit.translation.component.get_repoweb_link(
unit.translation.filename,
# '1' as a placeholder, because `get_repoweb_link` can't currently
# generate links without line specified. Although it's ok to use
# '' or '0' on GitHub or GitLab, let's play it safe for now.
"1",
is_translation=True,
user=user,
)
format_html('<a href="{}">{}</a>', translation_file_link, unit.translation.filename)
if (
translation_file_link := unit.translation.component.get_repoweb_link(
unit.translation.filename,
# '1' as a placeholder, because `get_repoweb_link` can't currently
# generate links without line specified. Although it's ok to use
# '' or '0' on GitHub or GitLab, let's play it safe for now.
"1",
is_translation=True,
user=user,
)
)
else format_html("{}", unit.translation.filename)

Copilot uses AI. Check for mistakes.
Comment on lines 1828 to 1833
if not template:
if self.repoweb:
if is_translation and self.repoweb_translations:
template = self.repoweb_translations
elif self.repoweb:
template = self.repoweb
elif user and user.has_perm("vcs.view", self):
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_translation influences template selection here, but the method later delegates to linked_component.get_repoweb_link(...) without passing is_translation. If template is still falsy at delegation time (e.g., relying on the linked component’s settings), translation links will be generated using the linked component’s non-translation fallback. Ensure the delegation path preserves the is_translation intent so linked repositories can use repoweb_translations correctly.

Copilot uses AI. Check for mistakes.
@BrenABarn BrenABarn marked this pull request as draft April 24, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting a separate repository browser url for translation files

3 participants