Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable version control service integration #252

Open
bittner opened this issue Jan 15, 2021 · 5 comments
Open

Configurable version control service integration #252

bittner opened this issue Jan 15, 2021 · 5 comments

Comments

@bittner
Copy link

bittner commented Jan 15, 2021

  • Which version of Django are you using?: 2.2
  • Which version of django-rosetta are you using?: 0.9.5
  • Have you looked trough recent issues and checked this isn't a duplicate? Yes

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.

@mondeja
Copy link
Contributor

mondeja commented Apr 30, 2021

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.

@bittner
Copy link
Author

bittner commented May 1, 2021

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.

@mbi
Copy link
Owner

mbi commented May 13, 2021

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?

@mondeja
Copy link
Contributor

mondeja commented May 13, 2021

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.

@bittner
Copy link
Author

bittner commented Jun 14, 2021

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.

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

No branches or pull requests

3 participants