mirror of
https://github.com/Hopiu/django-rosetta.git
synced 2026-03-25 17:30:24 +00:00
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.
This commit is contained in:
parent
ed446f9321
commit
f00009686f
4 changed files with 38 additions and 16 deletions
13
README.rst
13
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
|
||||
*****
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -39,11 +39,13 @@
|
|||
<li {% ifequal rosetta_i18n_filter 'all' %}class="active"{% endifequal %}><a href="?filter=all">{% trans "All" %}</a></li>
|
||||
</ul>
|
||||
|
||||
{% if ENABLE_REFLANG %}
|
||||
REF : <select onchange="javascript:window.location.href = this.value;">
|
||||
{% for langid, langname in LANGUAGES %}
|
||||
<option{% ifequal ref_lang langid %} selected="selected"{% endifequal %} value="{% url 'rosetta-reference-selection' langid=langid %}">{{langname}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endif %}
|
||||
|
||||
<div id="changelist" class="module{% if rosetta_i18n_lang_bidi %} rtl{% endif %}">
|
||||
<div id="toolbar">
|
||||
|
|
@ -105,7 +107,11 @@
|
|||
</td>
|
||||
{% else %}
|
||||
<td class="original">
|
||||
{% if ENABLE_REFLANG %}
|
||||
<span class="message">{{ message.ref_txt|format_message|linebreaksbr }}</span>
|
||||
{% else %}
|
||||
<span class="message">{{ message.msgid|format_message|linebreaksbr }}</span>
|
||||
{% endif %}
|
||||
{% if message.msgctxt %}
|
||||
<span class="context">{% trans "Context hint" %}: "{{message.msgctxt|safe}}"</span>
|
||||
{% else %}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue