From f00009686fd002cc3a591e9ac209123b00aeb7ee Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 30 Jan 2013 14:18:34 -0500 Subject: [PATCH] Added the ROSETTA_ENABLE_REFLANG flag. This way, it's possible to disable the feature. Also, added a description of the feature in the README. --- README.rst | 13 +++++++++++ rosetta/conf/settings.py | 2 ++ rosetta/templates/rosetta/pofile.html | 6 +++++ rosetta/views.py | 33 ++++++++++++++------------- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index 304ccf9..0dc86a7 100644 --- a/README.rst +++ b/README.rst @@ -61,6 +61,7 @@ Rosetta can be configured via the following parameters, to be defined in your pr * ``ROSETTA_REQUIRES_AUTH``: Require authentication for all Rosetta views. Defaults to ``True``. * ``ROSETTA_POFILE_WRAP_WIDTH``: Sets the line-length of the edited PO file. Set this to ``0`` to mimic ``makemessage``'s ``--no-wrap`` option. Defaults to ``78``. * ``ROSETTA_STORAGE_CLASS``: See the note below on Storages. Defaults to ``rosetta.storage.CacheRosettaStorage`` +* ``ROSETTA_ENABLE_REFLANG``: See the note below on Reference Language. Defaults to ``False``. ******** Storages @@ -85,6 +86,18 @@ If you wish to grant editing access to other users: 1. Create a 'translators' group in your admin interface 2. Add the user you wish to grant translating rights to this group +****************** +Reference Language +****************** + +If this option is enabled, a selector will appear on the translation page allowing you to choose +a reference language. A reference language will allow you to display your ``msgid`` in a laguage +that has already been translated. For example, if you already have a translation in French, a +translator that only knows French and Spanish (but not English) could select French as a reference +language to perform a "second hand" translation. + +The last row of the reference language selector, "MSGID", is to directly display ``msgid``. + ***** Usage ***** diff --git a/rosetta/conf/settings.py b/rosetta/conf/settings.py index 967afaf..af5894f 100644 --- a/rosetta/conf/settings.py +++ b/rosetta/conf/settings.py @@ -51,3 +51,5 @@ POFILE_WRAP_WIDTH = getattr(settings, 'ROSETTA_POFILE_WRAP_WIDTH', 78) # Storage class to handle temporary data storage STORAGE_CLASS = getattr(settings, 'ROSETTA_STORAGE_CLASS', 'rosetta.storage.CacheRosettaStorage') + +ENABLE_REFLANG = getattr(settings, 'ROSETTA_ENABLE_REFLANG', False) diff --git a/rosetta/templates/rosetta/pofile.html b/rosetta/templates/rosetta/pofile.html index 86c6e55..63353fa 100644 --- a/rosetta/templates/rosetta/pofile.html +++ b/rosetta/templates/rosetta/pofile.html @@ -39,11 +39,13 @@
  • {% trans "All" %}
  • + {% if ENABLE_REFLANG %} REF : + {% endif %}
    @@ -105,7 +107,11 @@ {% else %} + {% if ENABLE_REFLANG %} {{ message.ref_txt|format_message|linebreaksbr }} + {% else %} + {{ message.msgid|format_message|linebreaksbr }} + {% endif %} {% if message.msgctxt %} {% trans "Context hint" %}: "{{message.msgctxt|safe}}" {% else %} diff --git a/rosetta/views.py b/rosetta/views.py index 57f4d5e..d480464 100644 --- a/rosetta/views.py +++ b/rosetta/views.py @@ -51,13 +51,6 @@ def home(request): if storage.has('rosetta_i18n_fn'): rosetta_i18n_fn = storage.get('rosetta_i18n_fn') - ref_lang = storage.get('rosetta_i18n_ref_lang_code', 'msgid') - ref_pofile = None - if ref_lang != 'msgid': - ref_fn = re.sub('/locale/[a-z]{2}/','/locale/%s/'%ref_lang, rosetta_i18n_fn) - ref_pofile = pofile(ref_fn) - - rosetta_i18n_app = get_app_name(rosetta_i18n_fn) rosetta_i18n_lang_code = storage.get('rosetta_i18n_lang_code') rosetta_i18n_lang_bidi = rosetta_i18n_lang_code.split('-')[0] in settings.LANGUAGES_BIDI @@ -203,13 +196,23 @@ def home(request): else: paginator = Paginator([e for e in rosetta_i18n_pofile if not e.obsolete], rosetta_settings.MESSAGES_PER_PAGE) - for o in paginator.object_list: - # default - o.ref_txt = o.msgid - if ref_pofile is not None: - ref_entry = ref_pofile.find(o.msgid) - if ref_entry is not None and ref_entry.msgstr: - o.ref_txt = ref_entry.msgstr + # We put constants in the local namespace so that they're sent to the template context + ENABLE_REFLANG = rosetta_settings.ENABLE_REFLANG + if ENABLE_REFLANG: + ref_lang = storage.get('rosetta_i18n_ref_lang_code', 'msgid') + ref_pofile = None + if ref_lang != 'msgid': + ref_fn = re.sub('/locale/[a-z]{2}/','/locale/%s/' % ref_lang, rosetta_i18n_fn) + ref_pofile = pofile(ref_fn) + + for o in paginator.object_list: + # default + o.ref_txt = o.msgid + if ref_pofile is not None: + ref_entry = ref_pofile.find(o.msgid) + if ref_entry is not None and ref_entry.msgstr: + o.ref_txt = ref_entry.msgstr + LANGUAGES = list(settings.LANGUAGES) + [('msgid', 'MSGID')] if 'page' in request.GET and int(request.GET.get('page')) <= paginator.num_pages and int(request.GET.get('page')) > 0: page = int(request.GET.get('page')) @@ -259,8 +262,6 @@ def home(request): storage.delete('rosetta_last_save_error') rosetta_last_save_error = True - LANGUAGES = list(settings.LANGUAGES) + [('msgid', 'MSGID')] - return render_to_response('rosetta/pofile.html', locals(), context_instance=RequestContext(request)) else: return list_languages(request, do_session_warn=True)