{% extends "base.html" %}
{% load url from future %}
{% load i18n %}
{% load static %}
{% load translations %}

{% block extra_meta %}
<link rel="canonical" href="{{ unit.get_absolute_url }}" />
{% endblock %}

{% block breadcrumbs %}
<li><a href="{{ unit.translation.subproject.project.get_absolute_url }}">{{ unit.translation.subproject.project }}</a></li>
<li><a href="{{ unit.translation.subproject.get_absolute_url }}">{{ unit.translation.subproject.name }}</a></li>
<li><a href="{{ unit.translation.get_absolute_url }}">{{ unit.translation.language }}</a></li>
<li><a href="{{ unit.translation.get_translate_url }}">{% trans "translate" %}</a></li>
{% endblock %}

{% block content %}

{% with unit.translation as object %}
{% include "show-lock.html" %}
{% endwith %}

{% if perms.trans.save_translation %}
<div class="menu-float">
<a href="{% url 'zen' project=unit.translation.subproject.project.slug subproject=unit.translation.subproject.slug lang=unit.translation.language.code %}?sid={{ search_id }}" class="button" title="{% trans "Edit in Zen mode" %} (experimental)">{% trans "Zen" %}</a>
</div>
{% endif %}

<h2>{% trans "Translate" %}</h2>

<span class="navi-toolbar ui-widget-header ui-corner-all">
<span id="navi">
<a id="button-first" href="{{ first_unit_url }}">{% trans "First" %}</a>
<a id="button-prev" href="{{ prev_unit_url }}">{% trans "Previous" %}</a>
<a id="button-pos" class="textbutton">{% blocktrans with unit.position as position %}{{ position }} / {{ total }}{% endblocktrans %}</a>
<a id="button-next" href="{{ next_unit_url }}">{% trans "Next" %}</a>
<a id="button-end" href="{{ last_unit_url }}">{% trans "Last" %}</a>
</span>

{% if filter_name %}
{% blocktrans %}Current filter: {{ filter_name }} ({{ filter_pos }} / {{ filter_count }}){% endblocktrans %}
{% endif %}
</span>

<form action="{{ this_unit_url }}" method="post" class="translation-form">
<a href="{% url 'js-get' checksum=unit.checksum %}" class="hidden" id="js-get"></a>
<a href="{% url 'js-translate' unit_id=unit.id %}" class="hidden" id="js-translate"></a>
<a href="{% url 'js-lock' project=unit.translation.subproject.project.slug subproject=unit.translation.subproject.slug lang=unit.translation.language.code %}" class="hidden" id="js-lock"></a>
{% csrf_token %}
{% if antispam %}<div id="s_content">{{ antispam }}</div>{% endif %}
<table>
{% if secondary %}
{% for unit in secondary %}
<tr>
<th class="source labelscolumn">{{ unit.translation.language }}</th>
<td class="translatetext">{{ unit.target|fmttranslation:unit.translation.language }}</td>
</tr>
{% endfor %}
{% endif %}
{% if unit.previous_source and unit.fuzzy %}
<tr>
<th class="labelscolumn">{% trans "Source change" %}</th>
<td>{{ unit.previous_source|fmtsourcediff:unit }}</td>
</tr>
{% endif %}
<tr>
<th class="source labelscolumn">{% trans "Source" %}</th>
<td class="translatetext">{{ unit.source|fmtsearchmatch:search_query }}</td>
</tr>
{% if unit.context %}
<tr>
<th class="labelscolumn">{% trans "Context" %}</th>
<td>{{ unit.context|fmtsearchmatch:search_query }}</td>
</tr>
{% endif %}
<tr>
<td class="labelscolumn"></td>
<td class="toolbar">
<a href="#" id="copy-text">{% trans "Copy" %}</a>
<img src="{% get_media_prefix %}loading.gif" id="loading" style="display: none" />
{% if unit.translation.language.direction == "rtl" %}
<div id="toggle-direction" title="{% trans "Toggle text direction" %}" class="small-button menu-float">
<input type="radio" id="direction-rtl" name="direction" value="rtl" checked="checked" /><label for="direction-rtl">RTL</label>
<input type="radio" id="direction-ltr" name="direction" value="ltr" /><label for="direction-ltr">LTR</label>
</div>
{% endif %}
</td>
</tr>
<tr>
<th class="labelscolumn">{% if unit.is_plural %}{% trans "Translations" %}{% else %}{% trans "Translation" %}{% endif %}</th>
<td class="translator">
{{ form.checksum }}
{{ form.target }}
<br />
{{ form.fuzzy }}<label for="id_fuzzy">{% trans "Fuzzy" context "Message is fuzzy" %}</label>
<span class="specialchars">{% trans "Special characters:" %}
<a class="specialchar" title="{% trans "Insert tab character" %}">→</a>
<a class="specialchar" title="{% trans "Insert new line" %}">↵</a>
<a class="specialchar" title="{% trans "Insert horizontal ellipsis" %}">…</a>
</span>
</td></tr>
{% with unit.active_checks as checks %}
{% if checks %}
<tr>
<th class="labelscolumn">{% trans "Failing checks" %}</th>
<td>
{% show_checks checks user %}
</td>
</tr>
{% endif %}
{% endwith %}
{% with unit.suggestions as suggestions %}
{% if suggestions %}
<tr>
<th class="labelscolumn">{% trans "Suggestions" %}</th>
<td>
<table class="suggestions">
{% for suggestion in suggestions %}
<tr><td class="translatetext">{{ suggestion.target|fmttranslationdiff:unit }}</td></tr>
<tr><td>
{% if suggestion.user %}
{% blocktrans with suggestion.get_user_display as user %}Suggested by {{ user }}{% endblocktrans %}
{% else %}
{% trans "Suggested by anonymous user" %}
{% endif %}
{% if unit.can_vote_suggestions %}
{% blocktrans count count=suggestion.get_num_votes %}, {{ count }} vote{% plural %}, {{ count }} votes{% endblocktrans %}
{% endif %}
<div class="menu-float action-buttons">
{% if unit.can_vote_suggestions and perms.trans.vote_suggestion %}
<button type="submit" class="sug-upvote" name="upvote" value="{{ suggestion.id }}">{% trans "+1 vote" %}</button>
<button type="submit" class="sug-downvote" name="downvote" value="{{ suggestion.id }}">{% trans "-1 vote" %}</button>
{% endif %}
{% if not unit.only_vote_suggestions or perms.trans.override_suggestion %}
{% if perms.trans.accept_suggestion %}
<button type="submit" class="sug-accept" name="accept" value="{{ suggestion.id }}">{% trans "Accept" %}</button>
{% endif %}
{% if perms.trans.delete_suggestion %}
<button type="submit" class="sug-delete" name="delete" value="{{ suggestion.id }}">{% trans "Delete" %}</button>
{% endif %}
{% endif %}
</div>
</td>
{% endfor %}
</table>
</td>
</tr>
{% endif %}
{% endwith %}
{% include "unit-details.html" %}
{% if unit.flags %}
<tr>
<th class="labelscolumn">{% trans "Flags" %}</th>
<td><span class="legend">{{ unit.flags }}</span></td>
</tr>
{% endif %}
<tr><td class="labelscolumn"></td><td>
{% if not unit.only_vote_suggestions or perms.trans.override_suggestion %}
{% if perms.trans.save_translation %}
<input class="button" type="submit" value="{% trans "Save" %}" name="save" tabindex="150" {% if locked %}disabled="disabled"{% endif %} />
{% else %}
{% url 'login' as login_url %}
{% with unit.translation.get_translate_url as translate_url %}
{% blocktrans %}<a href="{{ login_url }}?next={{ translate_url }}">Log in</a> for saving translations.{% endblocktrans %}
{% endwith %}
{% endif %}
{% endif %}

{% if perms.trans.add_suggestion %}
<input class="button" type="submit" value="{% trans "Suggest" %}" name="suggest" tabindex="151" {% if project_locked %}disabled="disabled"{% endif %} />
{% else %}
{% trans "No privileges for adding suggestions!" %}
{% endif %}

{% if perms.trans.save_translation %}
<div class="menu-float tooltip">
<div class="tooltip-content">{% trans "You can leave this empty in most cases as Weblate generates basic commit messages automatically." %}</div>
{% trans "Commit message:" %} <input type="text" name="commit_message" class="commit_message" placeholder="{% trans "Additional text to include in the commit message." %}" tabindex="152" value="{{ unit.translation.commit_message }}" />
</div>
{% endif %}
</td></tr>

</table>
</form>

<h2>{% trans "Translation context" %}</h2>

{% with unit.get_comments as comments and unit.get_source_comments as source_comments %}
<div id="translate-tabs">
    <ul>
        <li><a href="#tab-nearby" title="{% trans "Messages placed around this one" %}">{% trans "Nearby messages" %}</a></li>
        <li><a href="{% url 'js-other' unit_id=unit.id %}?type={{ type }}&amp;offset={{ offset }}&amp;sid={{ search_id }}" title="{% trans "Same message used in different subprojects" %}">{% trans "All locations" %}</a></li>
        <li><a href="{% url 'js-dictionary' unit_id=unit.id %}" title="{% trans "Words extracted from glossary" %}">{% trans "Glossary" %}</a></li>
        {% if mt_enabled and perms.trans.use_mt %}
        <li><a href="#tab-machine" title="{% trans "Machine translation suggestions" %}">{% trans "Machine translation" %}</a></li>
        {% endif %}
        <li><a href="#tab-comments" title="{% trans "Comments about this translation" %}">
        {% if comments %}
        {% blocktrans with comments.count as  count %}Comments ({{ count }}){% endblocktrans %}
        {% else %}
        {% trans "Comments" %}
        {% endif %}
        </a></li>
        <li><a href="{% url 'js-unit-changes' unit_id=unit.id %}" title="{% trans "List of recent changes done in Weblate" %}">{% trans "History" %}</a></li>
        <li><a href="#tab-source" title="{% trans "Source string details and feedback" %}">
        {% if source_comments %}
        {% blocktrans with source_comments.count as  count %}Source ({{ count }}){% endblocktrans %}
        {% else %}
        {% trans "Source" %}
        {% endif %}
        </a></li>
        <li><a href="#tab-search">{% trans "Search" %}</a></li>
    </ul>
    <div id="tab-nearby">
    <table>
    <thead>
    <tr><th></th><th>{% trans "Source" %}</th><th>{% trans "Translation" %}</th><th>{% trans "State" %}</th></tr>
    </thead>
    <tbody>
    {% for item in unit.nearby %}
    <tr {% if unit.position == item.position %}class="current_translation"{% endif %}>
    <td class="number"><a href="{{ item.get_absolute_url }}">{{ item.position }}</a></td>
    <td class="translatetext"><a href="{{ item.get_absolute_url }}">{{ item.source|fmttranslation }}</a></td>
    <td class="translatetext translation_html_markup" {{ item.translation.language.get_html }}><a href="{{ item.get_absolute_url }}">{{ item.target|fmttranslation:unit.translation.language }}</a></td>
    <td>{{ item.get_state_flags }}</td>
    </tr>
    {% endfor %}
    </tbody>
    </table>
    </div>
    {% if mt_enabled and perms.trans.use_mt %}
    <div id="tab-machine">
    <img src="{% get_media_prefix %}loading.gif" id="mt-loading" style="display: none" />
    <table>
    <thead>
    <tr>
    <th>{% trans "Translation" %}</th>
    <th>{% trans "Source" %}</th>
    <th>{% trans "Service" %}</th>
    <th></th>
    <tr>
    </thead>
    <tbody id="machine-translations">
    </tbody>
    </table>
    <ul id="mt-errors">
    </ul>
    </div>
    {% endif %}
    <div id="tab-comments">
    <p>{% trans "You can share comments about this translation with other translators." %}</p>
    <table>
    {% include "list-comments.html" %}
    <tr>
    <th>{% trans "New comment" %}</th>
    <td>
    {% if perms.trans.add_comment %}
    <form method="post" action="{% url 'comment' pk=unit.id %}">
    {% csrf_token %}
    <input type="hidden" name="next" value="{{ this_unit_url }}" />
    {{ comment_form.comment }}
    <br />
    <input class="button" type="submit" value="{% trans "Add" %}" />
    </form>
    {% else %}
    {% trans "You are not allowed to add comments." %}
    {% endif %}
    </td>
    </tr>
    </table>
    </div>
    <div id="tab-source">

    {% with unit.active_source_checks as checks %}
    {% if checks %}
    <h4>{% trans "Failing checks" %}</h4>
    {% show_checks checks user %}
    {% endif %}
    {% endwith %}

    <h4>{% trans "User comments" %}</h4>
    <p>{% trans "You can share comments about source string for this translation with other translators and developers." %}</p>
    <table>
    {% with source_comments as comments %}
    {% include "list-comments.html" %}
    {% endwith %}
    <tr>
    <th>{% trans "New comment" %}</th>
    <td>
    {% if perms.trans.add_comment %}
    <form method="post" action="{% url 'comment' pk=unit.id %}">
    {% csrf_token %}
    <input type="hidden" name="type" value="source" />
    <input type="hidden" name="next" value="{{ this_unit_url }}" />
    {{ comment_form.comment }}
    <br />
    <input class="button" type="submit" value="{% trans "Add" %}" />
    </form>
    {% else %}
    {% trans "You are not allowed to add comments." %}
    {% endif %}
    </td>
    </tr>
    </table>
    </div>
    <div id="tab-search">
    <form action="{{ unit.translation.get_translate_url }}" method="GET">
    {{ search_form.as_p }}
    <input type="submit" value="{% trans "Search" %}" class="button" />
    </form>
    </div>

</div>
{% endwith %}

{% endblock %}
