Git Product home page Git Product logo

Comments (5)

mbi avatar mbi commented on June 15, 2024 1

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?

from django-rosetta.

mondeja avatar mondeja commented on June 15, 2024

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.

from django-rosetta.

bittner avatar bittner commented on June 15, 2024

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.

from django-rosetta.

mondeja avatar mondeja commented on June 15, 2024

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.

from django-rosetta.

bittner avatar bittner commented on June 15, 2024

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.

from django-rosetta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.