Fix: translation repository browser#19184
Conversation
|
nijel
left a comment
There was a problem hiding this comment.
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.
| You can use :ref:`markup`. | ||
|
|
||
| For example on GitHub, use something like: | ||
| ``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}`` |
There was a problem hiding this comment.
I think it will break rendering without newline:
| ``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.
| "1", | ||
| is_translation=True, | ||
| user=user, | ||
| ) |
There was a problem hiding this comment.
This change removes support for direct https links.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_translationsfield (with migration) and exposes it in component settings forms. - Extends
Component.get_repoweb_link()with anis_translationflag 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.
| @@ -1813,7 +1826,9 @@ def get_repoweb_link( | |||
| here. | |||
| """ | |||
There was a problem hiding this comment.
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.
| You can use :ref:`markup`. | ||
|
|
||
| For example on GitHub, use something like: | ||
| ``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}`` |
There was a problem hiding this comment.
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.
| ``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}`` | |
| ``https://github.com/WeblateOrg/translations/blob/{{branch}}/{{filename}}#L{{line}}`` |
| 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, | ||
| ) |
There was a problem hiding this comment.
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).
| 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) |
| 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): |
There was a problem hiding this comment.
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.
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
repoweb_translationsmodel field onComponentget_repoweb_linkto acceptis_translationparametertranslation_file_linkin edit view to use the new field