{% extends "rosetta_base.html" %}
{% load rosetta i18n %}

{% block header %}
    {{block.super}}
    <div id="user-tools">
        <p>
            <span><a href="{% url rosetta-pick-file %}">{% trans "Pick another file" %}</a> / 
            <a href="{% url rosetta-download-file %}">{% trans "Download this catalog" %}</a></span>
        </p>
    </div>
    <script type="text/javascript">
    </script>
    
{% endblock %}

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

{% block rosetta_breadcrumbs %}
    <div class="breadcrumbs">
    	<a href="{% url rosetta-pick-file %}">Rosetta</a> &rsaquo; 
        {{ rosetta_i18n_lang_name }} &rsaquo; 
        {{ rosetta_i18n_app|title }} &rsaquo; 
        {% 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 content %}
    <h1>{% blocktrans  %}Translate into {{rosetta_i18n_lang_name}}{% endblocktrans %}</h1>
    
    <ul class="object-tools">
        <li class="nobubble">{% trans "Display:" %}</li>
        <li {% ifequal rosetta_i18n_filter 'untranslated' %}class="active"{% endifequal %}><a href="?filter=untranslated">{% trans "Untranslated only" %}</a></li>
        <li {% ifequal rosetta_i18n_filter 'translated' %}class="active"{% endifequal %}><a href="?filter=translated">{% trans "Translated only" %}</a></li>
        <li {% ifequal rosetta_i18n_filter 'fuzzy' %}class="active"{% endifequal %}><a href="?filter=fuzzy">{% trans "Fuzzy only" %}</a></li>
        <li {% ifequal rosetta_i18n_filter 'all' %}class="active"{% endifequal %}><a href="?filter=all">{% trans "All" %}</a></li>
    </ul>
    <div id="changelist" class="module{% if rosetta_i18n_lang_bidi %} rtl{% endif %}">
        <div id="toolbar">
        <form id="changelist-search" action="" method="post">
            <div><!-- DIV needed for valid HTML -->
                {% rosetta_csrf_token %}
                <label for="searchbar"><img src="{{ADMIN_IMAGE_DIR}}/icon_searchbox.png" alt="{% trans "Search" %}" /></label>
                <input type="text" size="40" name="query" value="{% if query %}{{query}}{% endif %}" id="searchbar" tabindex="0" />
                <input type="submit" name="search" value="{% trans "Go" %}" />
            </div>
        </form>
        {% comment %}
        {% if ENABLE_TRANSLATION_SUGGESTIONS %}
        <form id="translate-all">
            <div>
                <input type="submit" class="googleall" value="{% trans "Suggest All Translations" %}" />
            </div>
        </form>
        {% endif %}
        {% endcomment %}
        </div>
        
        <form method="post" action="">
            <table>
                <thead>
                    <tr>
                        {% rosetta_csrf_token %}
                        <th><div class="text">{% trans "Original" %}</div></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 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="submit-row">
                <p class="paginator">
                    {% if query %}
                        <input type="hidden" name="query" value="{{query}}"  />
                    {% endif %}
                    <input type="submit" class="default" name="_next" value="{% trans "Save and translate next block" %}" tabindex="{% increment tab_idx %}"/>
                    
                    
                    {% if needs_pagination %}
                    {% trans "Skip to page:" %}
                    {% for i in page_range %}
                        {% ifequal i '...' %}
                        <span class="space">{{ i }}</span>
                        {% else %}
                        {% ifequal i page %}
                            <span class="this-page">{{i}}</span>
                        {% else %}    
                            <a href="?page={{i}}{% if query %}&amp;query={{query}}{% endif %}">{{i}}</a>
                        {% endifequal %}
                        {% endifequal %}
                    {% endfor %}
                    {% else %}
                    {% trans "Displaying:" %}
                    {% endif %}
                    
                    {% with paginator.object_list|length as hits %}
                    <strong>{% blocktrans count rosetta_i18n_pofile|length as message_number %}{{hits}}/{{message_number}} message{% plural %}{{hits}}/{{message_number}} messages{% endblocktrans %}</strong>    
                    {% endwith %}

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