Open bittner opened 3 years ago
If the reference content (see definition) is directly a valid URL (e.g. when I edit the PO file and add a #. https://foo.bar.com line to an item) that URL should be turned into a clickable link either.
#.
is used for extracted-comments, not for references, #:
is used for references.
Apart from that, if I'm not wrong you want to use URLs as references and convert URLs to a
DOM elements in Rosetta interface. This could be done tweaking a bit the Django makemessages extraction process with a custom management command:
import polib
from django.core.management.commands.makemessages import (
BuildFile as MakeMessagesBuildFile,
Command as MakeMessagesCommand
)
class MakeProperMessagesBuildFile(MakeMessagesBuildFile):
def postprocess_messages(self, msgs):
po = polib.POFile(super().postprocess_messages(msgs))
for entry in po:
# do whatever you want, in this case if "Url: <...>" found in msgctxt
# or URL found by regex, move it to `ocurrences`...
return str(po)
class Command(MakeMessagesCommand):
build_file_class = MakeProperMessagesBuildFile
And then, inherit from rosetta form.html
template and add a bit of Javascript. Something like:
from rosetta.views import TranslationFormView
TranslationFormView.template_name = "path/to/your/custom-template.html"
{% include 'rosetta/form.html' %}
{% include 'my-crazy-hack-for-rosetta-interface.html' %}
I think your proposal is interesting, but maybe not standard enough to be implemented in Django core.
I think your proposal is interesting, but maybe not standard enough to be implemented in Django core.
I think the contrary. My proposal is about improving the general usability of Rosetta. Think: What is a link to a file location worth in 2021 when it's not effortless to reach it in the source code repository to, e.g., fix the related text string?
If you have to do copy+paste, or plain remember filename and line number, and go searching in your file system then the project will rather sooner than later be abandoned, because it doesn't meet the expectations of a continuously larger part of the (developer) audience.
Translation support tools must allow translators to focus on translating, and in a similar manner developers to focus on fixing spelling mistakes. Speed matters, distractions count.
This could be done tweaking a bit the Django makemessages extraction process
That's technically possible, I agree, but I guess the better place is the rendering process for the user interface.
To answer the original request, the way I'd implement this is by defining a new setting, e.g. ROSETTA_LINK_OCCURRENCES
which should be a callable taking the occurrence string (e.g. "templates/test.html:3"
) and return an URL or None
. We could then call that callable for every entry in the form page and if the result is a link, we'd add a hyperlink on the occurrence.
Thoughts?
Could be interesting, but shouldn't be ROSETTA_OCCURRENCES
the name for this setting? You might want to modify the HTML code by adding other elements to the DOM beyond links.
Sounds good to me. Is your suggestion just about the setting and the implementation of turning the text into a link, or do you think about a default implementation of the callable, too?
If we had, say, a ROSETTA_VCS_URL
and a ROSETTA_VCS_REVISION
we could have a default implementation that might work for simple, single-repository projects. This could be a helpful starting point, aka reference implementation, for custom setups.
Feature: Link to source file
The "Occurrence(s)" column in the Web UI lists file names and the line numbers of where the text was extracted from. It should be easy to configure an external service URL and generate a link to display the text location in the file under version control.
If the reference content (see definition) is directly a valid URL (e.g. when I edit the PO file and add a
#. https://foo.bar.com
line to an item) that URL should be turned into a clickable link either.Related
See https://code.djangoproject.com/ticket/32356 for a related Django feature request.