Giter VIP home page Giter VIP logo

django-inlinetrans's Introduction

Introduction

image

image

Inlinetrans is a django application that allows the translation of django templates from the rendered html in the browser. Once you have your templates internationalized with inlinetrans, you can click on the untranslated messages in their corresponding web pages to add their translations. This can be of great help for translators, as they will be able to translate the messages right in their intended context.

Features

  • A templatetag, inline_trans (or itrans), intended as a replacement for django's trans.
  • A management command, inline_makemessage, intended as a replacement for django's makemessages.
  • A translation bar to show translatable messages, by default visible only to staff members (you can change this behavior with the variable USER_CAN_TRANSLATE, add it in the settings)

To translate the messages in a web page rendered in your browser, you first find out, through the translation bar, which messages have already been translated (marked light green) and which ones lack translation (marked light red).

Then, you click on a marked message, and are prompted for its translation; on entering the text and clicking OK, the new translation is sent to the server and saved in the correct .po file.

Once you have translated all messages in a page, you can click on "apply changes" on the translation bar. This forces a restart on the server, and the reloading of the page with the translations applied.

Requirements

To use inlinetrans, you need:

Demo (this video use a very old version of django-inlinetrans)

Video Demo, of django-inlinetrans, django-inplaceedit and django-inplaceedit-extra-fields (Set full screen mode to view it correctly)

image

Using inlinetrans

Make sure you load inlinetrans in all templates you want to internationalize, by adding the following code:

>>>
{% load inlinetrans %}
{% inlinetrans_static %}
<div id="inlinetrans-toolbar">place holder for inlinetrans toolbar</div>
{% inlinetrans_toolbar "inlinetrans-toolbar" %}

Then, you can use:

>>> {% inline_trans "translate this" %}

Or:

>>> {% itrans "translate this" %}

Instead of:

>>> {% trans "translate this" %}

Also, you can customize the toolbar and other parameters using inlinetrans as follow:

{% load i18n inlinetrans %}

{% inlinetrans_media %}

<script language="javascript">
    (function ($) {
        $(document).ready(function () {
            var messages_dict = {
                givetranslationfor: 'Give a new translation for {0} to {{ language }}',
                emptytranslation: "You're sending an empty translation ¿Are you sure? ",
                reloading: "Reloading",
                apply_changes: "Apply changes",
                applying_changes: "Applying changes",
                error_cant_send: "Can't send translation",
                error_cant_restart: "Can't restart server"
            };
            var new_translation_url = "{% url inlinetrans.views.set_new_translation %}";
            var restart_url = "{% url inlinetrans.views.do_restart %}";

            var toolbar_tpl = '\
                <div class="inlinetransContainer">\
                    <img id="changes-loading" src="{{ INLINETRANS_MEDIA_URL }}img/ajax-loader-transparent.gif"/>\
                    <span class="inlinetransActions">\
                        <span class="inlinetransAction hightlightTrans">See translatable items</span>\
                        <span class="inlinetransAction hightlightNotrans">See non translated items</span>\
                        <span class="inlinetransAction restartServer">Apply changes</span>\
                    </span>\
                </div>';
            // init inlinetrans toolbar
            $('#{{ node_id }}').inlinetranstoolbar(toolbar_tpl, new_translation_url, restart_url, messages_dict);
        });
    })(jQuery);
</script>

Inlinetrans adds html code to each translation, so make sure you don't use inline_trans tags inside html attributes, such as this:

>>> <a href="#" alt="{% inline_trans "translate this" %}"></a>

In these cases you have to use the regular trans tag.

Once your template is internationalized, you run the following command:

>>> $ ./manage.py inline_makemessages

This extracts both inline_trans (itrans) and trans messages from the templates, and incorporates them to the gettext catalogs, just as makemessages does for trans messages.

Afterwords, you can start your server, navigate to the rendered pages (by default, as a staff member), and, as explained above, translate the messages through the web.

django-inlinetrans's People

Contributors

goinnn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-inlinetrans's Issues

Compatibility with django 1.6

It seems that some things changed in django 1.6
And django-inline fails:
urls.py -
"from django.conf.urls.defaults import patterns, url" should be changed to "from django.conf.urls import patterns, url"

inlinetrans.py
"from django.template.base import _render_value_in_context" to "from django.template.base import render_value_in_context" or smth else.

Add option to override {% trans "" %}

Manually changing all occurences or {% trans "" %} to {% itrans "" %} is a bit intrusive.
Could there be an override option to just assume all trans tags are handled by django-inlinetrans ?

Commit translation to a git repo

Instead of forcing server reload, the translations could be commited to a GIT repo (or better yet, as a pull request to a repo)

Feature: iblocktrans

iblocktrans so that blocktrans (trans with variables) can be edited inline aswell

Will probably need to validate clientside that the variables are in string before posting to server.

Python3?

Will this module be ported to Python3 in the future?

Thanks.

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.