{% extends "rosetta/base.html" %}
{% load rosetta i18n %}
{% load url from future %}

{% block title %}{{ block.super }} - {{ rosetta_settings.MESSAGES_SOURCE_LANGUAGE_NAME }} - {{ rosetta_i18n_lang_name }} ({{ rosetta_i18n_pofile.percent_translated|floatformat:0 }}%){% endblock %}

{% block breadcumbs %}
    <ul class="breadcrumb">
    <li><a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
        <span class="divider">&raquo;</span></li>
    <li>
        <a href="{% url 'rosetta-pick-file' %}">{% trans "Translation selection" %}</a>
        <span class="divider">&raquo;</span></li>
    <li>{{ rosetta_i18n_lang_name }}
        <span class="divider">&raquo;</span></li>
    <li>{{ rosetta_i18n_app|title }}
        {% if title %}
            <span class="divider">&raquo;</span>
            </li>
            <li class="active">
            {{ title }}
        {% endif %}
        </li>

    {% blocktrans with rosetta_i18n_pofile.percent_translated|floatformat:2 as percent_translated %}Progress: {{ percent_translated }}%{% endblocktrans %}
    </div>
    {% if not rosetta_i18n_write %}
        <p class="errornote read-only">{% trans "File is read-only: download the file when done editing!" %}</p>{% endif %}
    {% if rosetta_last_save_error %}
        <p class="errornote save-conflict">{% trans "Some items in your last translation block couldn't be saved: this usually happens when the catalog file changes on disk after you last loaded it." %}</p>{% endif %}
{% endblock %}

{% block main %}
    <!--<h1>{% blocktrans  %}Translate into {{rosetta_i18n_lang_name}}{% endblocktrans %}</h1>-->

    <div class="toolbar-content clearfix">


        <div id="toolbar" class="pull-left">
            <form id="changelist-search" class="form-inline" action="" method="post">{% rosetta_csrf_token %}
                <input type="text" size="40" name="query" value="{% if query %}{{ query }}{% endif %}" id="searchbar" tabindex="0"/>
                <input type="submit" name="search" value="{% trans "Go" %}" class="btn btn-info"/>
                    &nbsp; 

                <div class="btn-group">
                    <a href="{% url 'rosetta-pick-file' %}" class="btn">{% trans "Pick another file" %}</a>
                    <a href="{% url 'rosetta-download-file' %}" class="btn">{% trans "Download this catalog" %}</a>
                </div>
            </form>
        </div>

        <div class="object-tools pull-right">
            <div class="btn-group">
                <a href="?filter=untranslated" class="btn {% if rosetta_i18n_filter == 'untranslated' %}btn-info{% endif %}">
                    {% trans "Untranslated only" %}
                </a>
                <a href="?filter=translated" class="btn {% if rosetta_i18n_filter == 'translated' %}btn-info{% endif %}">
                    {% trans "Translated only" %}
                </a>
                <a href="?filter=fuzzy" class="btn {% if rosetta_i18n_filter == 'fuzzy' %}btn-info{% endif %}">
                    {% trans "Fuzzy only" %}
                </a>
                <a href="?filter=all" class="btn {% if rosetta_i18n_filter == 'all' %}btn-info{% endif %}">
                    {% trans "All" %}
                </a>
            </div>
        </div>

    </div>

    <div id="changelist" class="module{% if rosetta_i18n_lang_bidi %} rtl{% endif %}">
        <form method="post" action="">{% rosetta_csrf_token %}

            <table class="table table-bordered table-striped">
                <thead>
                <tr>
                    <th>{% trans "Original" %}</th>
                    {% if main_language %}
                        <th>{{ main_language }}</th>{% endif %}
                    <th>{{ rosetta_i18n_lang_name }}</th>
                    <th class="c">
                        <span class="checkall">[-]</span> {% trans "Fuzzy" %}
                    </th>
                    <th>{% trans "Occurrences(s)" %}</th>
                </tr>
                </thead>
                <tbody>
                {% for message in rosetta_messages %}
                    <tr class="{% cycle row1,row2 %}">
                        {% if message.msgid_plural %}
                            <td class="original plural">
                                <div class="plural-container">
                                    <span class="part">{{ message.msgid|format_message|linebreaksbr }}</span>
                                    <span class="part">{{ message.msgid_plural|format_message|linebreaksbr }}</span>
                                </div>

                                {% if message.msgctxt %}
                                    <span class="context">{% trans "Context hint" %}: {{ message.msgctxt|safe }}</span>
                                {% else %}
                                    {% if message.comment %}
                                        <span class="context">{% trans "Context hint" %}: {{ message.comment|safe }}</span>
                                    {% endif %}
                                {% endif %}

                            </td>
                            <td class="translation">
                                {% for k, msgstr in message.msgstr_plural.items|dictsort:"0" %}
                                    <label for="m_{{ message.md5hash }}_{{ k }}">{{ k }}:</label>
                                    <textarea rows="{{ message.msgid|format_message|lines_count }}" cols="40" id="m_{{ message.md5hash }}_{{ k }}" name="m_{{ message.md5hash }}_{{ k }}" tabindex="{% increment tab_idx %}">{{ msgstr }}</textarea>
                                {% endfor %}
                            </td>
                        {% else %}
                            <td class="original">
                                <span class="message">{{ message.msgid|format_message|linebreaksbr }}</span>
                                {% if message.msgctxt %}
                                    <span class="context">{% trans "Context hint" %}: "{{ message.msgctxt|safe }}"</span>
                                {% else %}
                                    {% if message.comment %}
                                        <span class="context">{% trans "Context hint" %}: {{ message.comment|safe }}</span>
                                    {% endif %}
                                {% endif %}
                            </td>
                            {% if main_language %}
                                <td class="original">{{ message.main_lang|format_message|linebreaksbr }}</td>{% endif %}
                            <td class="translation">
                                <textarea rows="{{ message.msgid|format_message|lines_count }}" cols="40" name="m_{{ message.md5hash }}" tabindex="{% increment tab_idx %}">{{ message.msgstr }}</textarea>
                                {% if rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS %}
                                    <a href="#" class="suggest">{% trans "suggest" %}</a>{% endif %}
                            </td>
                        {% endif %}
                        <td class="c">
                            <input type="checkbox" name="f_{{ message.md5hash }}" value="1" {% if message|is_fuzzy %}checked="checked"{% endif %}/>
                        </td>
                        <td class="location">
                            {% for fn,lineno in message.occurrences %}
                                <code
                                    {% if forloop.counter|gt:"3" %} class="hide"{% endif %}>{{ fn }}:{{ lineno }}</code>
                            {% endfor %}
                            {% if message.occurrences|length|gt:"3" %}
                                <a href="#">&hellip; ({% blocktrans count message.occurrences|length|minus:"3" as more_count %}{{ more_count }} more
                                    {% plural %}{{ more_count }} more{% endblocktrans %})</a>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>

            <div class="row-fluid">
                <div class="pull-right">
                    {% if query %}
                        <input type="hidden" name="query" value="{{ query }}"/>{% endif %}
                    <input type="submit" class="default btn btn-success" name="_next"
                           value="{% trans "Save and translate next block" %}" tabindex="{% increment tab_idx %}"/>
                </div>

                <div class="pagination pull-left">
                    {% if needs_pagination %}
                        <ul>
                            {% for i in page_range %}
                                {% if i == '...' %}
                                    <li class="disabled"><span>{{ i }}</span>
                                    </li>
                                {% elif i == page %}
                                    <li class="active"><span>{{ i }}</span></li>
                                {% else %}
                                    <li><a href="?page=




                                        {{ i }}{% if query %}&amp;query={{ query }}{% endif %}">{{ i }}</a>
                                    </li>
                                {% endif %}
                            {% endfor %}
                        </ul>
                    {% endif %}
                </div>

        <span class="badge pull-left">
        {% with paginator.object_list|length as hits %}
            {% blocktrans count rosetta_i18n_pofile|length as message_number %}{{ hits }}/{{ message_number }} message
                {% plural %}{{ hits }}/{{ message_number }} messages{% endblocktrans %}
        {% endwith %}
        </span>
            </div>

        </form>
    </div>
{% endblock %}
