{% extends "base.html" %}
{% load translations %}
{% load permissions %}
{% load crispy_forms_tags %}
{% load i18n %}
{% load humanize %}

{% block breadcrumbs %}
<li><a href="{{ object.component.project.get_absolute_url }}">{{ object.component.project }}</a></li>
<li><a href="{{ object.component.get_absolute_url }}">{{ object.component.name }}</a></li>
<li><a href="{{ object.get_absolute_url }}">{{ object.language }}</a></li>
<a class="pull-right flip" href="{{ object.get_widgets_url }}">
<img src="{% url 'widget-image' project=object.component.project.slug component=object.component.slug widget='svg' color='badge' lang=object.language.code extension='svg' %}?native=1" />
</a>
{% endblock %}

{% block content %}

{% announcements component=object.component language=object.language %}

{% include "show-component-state.html" with object=object.component %}

{% include "watch-dropdown.html" with project=object.component.project component=object.component %}

{% perm 'meta:vcs.status' object as user_can_see_repository_status %}
{% perm 'vcs.commit' object as user_can_commit_translation %}
{% perm 'upload.overwrite' object as user_can_overwrite_translation %}
{% perm 'upload.perform' object as user_can_upload_translation %}
{% perm 'unit.add' object as user_can_add_unit %}

{% get_translate_url object as translate_url %}

<ul class="nav nav-pills">
  <li class="active"><a href="#overview" data-toggle="tab">{% trans "Overview" %}</a></li>
  <li><a href="#information" data-toggle="tab">{% trans "Info" %}</a></li>
  <li><a href="#search" data-toggle="tab">{% trans "Search" %}</a></li>
  <li><a href="{% url 'show_dictionary' project=object.component.project.slug lang=object.language.code %}">{% trans "Glossary" %}</a></li>
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Insights" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      <li><a href="#history" data-toggle="tab">{% trans "History" %}</a></li>
      <li><a href="#activity" data-toggle="tab" data-load="activity" data-yearly="{% url 'yearly_activity' project=object.component.project.slug component=object.component.slug lang=object.language.code %}" data-monthly="{% url 'monthly_activity' project=object.component.project.slug component=object.component.slug lang=object.language.code %}">{% trans "Activity" %}</a></li>
      <li><a href="#stats" data-toggle="tab">{% trans "Statistics" %}</a></li>
    </ul>
  </li>
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Files" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
{% include "translation-download.html" %}
    </ul>
  </li>
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Tools" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      <li><a href="{% url 'data_project' project=object.component.project.slug  %}">{% trans "Data exports" %}</a></li>
      {% if autoform %}
      <li><a href="#auto" data-toggle="tab">{% trans "Automatic translation" %}</a></li>
      {% endif %}
      {% if replace_form %}
      <li><a href="#replace" data-toggle="tab">{% trans "Search and replace" %}</a></li>
      {% endif %}
      {% if bulk_state_form %}
      <li><a href="#bulk-edit" data-toggle="tab">{% trans "Bulk edit" %}</a></li>
      {% endif %}
      {% if user_can_add_unit %}
      <li><a href="#new" data-toggle="tab">{% trans "Add new translation string" %}</a></li>
      {% endif %}
    </ul>
  </li>
  {% if user_can_see_repository_status %}
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Manage" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      {% if user_can_commit_translation %}
      <li><a href="{{ object.get_commit_url }}" class="link-post">{% trans "Commit" %}</a></li>
      {% endif %}
      {% if user_can_see_repository_status %}
      <li><a href="#repository" data-toggle="tab" data-href="{% url 'git_status_translation' project=object.component.project.slug component=object.component.slug lang=object.language.code %}">{% trans "Repository maintenance" %}</a></li>
      {% endif %}
      {% if announcement_form %}
      <li role="separator" class="divider"></li>
      <li><a href="#announcement" data-toggle="tab">{% trans "Post announcement" %}</a></li>
      {% endif %}
      {% if delete_form %}
      <li role="separator" class="divider"></li>
      <li><a href="#delete" data-toggle="tab">{% trans "Removal" %}</a></li>
      {% endif %}
    </ul>
  </li>
  {% endif %}
{% if enable_sharing %}
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Share" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
{% with object.get_share_url as share_url and object.get_widgets_url as widgets_url %}
      <li><a href="https://www.facebook.com/sharer.php?u={{ share_url }}">{% trans "Share on Facebook" %}</a></li>
      <li><a href="https://twitter.com/share?text={% blocktrans %}Translate {{ object }} using %23Weblate at {{ share_url }}!{% endblocktrans %}">{% trans "Tweet this translation!" %}</a></li>
      <li><a href="{% url 'engage' project=object.component.project.slug %}">{% trans "Engage page" %}</a></li>
      <li><a href="{{ widgets_url }}">{% trans "Status widgets" %}</a></li>
{% endwith %}
    </ul>
  </li>
{% endif %}
</ul>


<div class="tab-content">
<div class="tab-pane active" id="overview">

<div class="panel {% if object.is_source %}panel-warning{% else %}panel-default{% endif %}">
  <div class="panel-heading">
  <h4 class="panel-title">
  {% if object.is_source %}
  {% trans "Source strings" %}
  {% else %}
  {% trans "Translation status" %}
  {% endif %}
  </h4></div>

<table class="table table-autowidth">
<tr>
<th class="number">{{ object.stats.all|intcomma }}</th>
<td>{% trans "Strings" %}</td>
<td class="progress-cell hidden-xs">{% translation_progress object %}</td>
<td class="percent">{{ object.stats.translated_percent|percent_format }}</td>
<td rowspan="2" class="buttons-cell full-cell">
<a href="{{ translate_url }}{% if object.stats.todo > 0 %}?q=state:&lt;translated{% endif %}" class="pull-right flip btn btn-primary">{% trans "Translate" %}</a>
</td>
</tr>

<tr>
<th class="number">{{ object.stats.all_words|intcomma }}</th>
<td>{% trans "Words" %}</td>
<td class="progress-cell hidden-xs">{% words_progress object %}</td>
<td class="percent">{{ object.stats.translated_words_percent|percent_format }}</td>
</tr>
</table>

{% if object.is_source %}
  <div class="panel-footer">
    {% trans "This translation is being used as source strings within this component." %}
  </div>
{% endif %}

</div>

<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
{% documentation_icon 'user/translating' 'strings-to-check' right=True %}
{% trans "Strings status" %}
</h4>
</div>
<table class="table table-autowidth">
{% for c in object.list_translation_checks %}
<tr data-href="{{ translate_url }}?q={{ c.0 }}" class="clickable-row">
<th class="number">{{ c.2|intcomma }}</th>
<td class="legend">
<div class="progress">
  <div class="progress-bar progress-bar-{{ c.3 }}" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"></div>
</div>
</td>
<td class="full-cell">
<a href="{{ translate_url }}?q={{ c.0 }}">
{{ c.1 }} — {% blocktrans with count=c.4|intcomma count cnt=c.4 %}{{ count }} word{% plural %}{{ count }} words{% endblocktrans %}
</a>
</td>
{% endfor %}
</table>
</div>

{% if other_translations %}
<div class="panel panel-default">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Other components" %}</h4></div>
{% include "snippets/list-objects.html" with objects=other_translations name_source="component_name" label=_("Component") in_panel=True %}
</div>
{% endif %}

</div>

<div class="tab-pane" id="information">
<div class="panel panel-default">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Translation Information" %}</h4></div>

<table class="table">
{% include "component_info.html" with object=object.component %}
<tr>
<th>{% trans "Translation file" %}</th>
<td>
<div class="dropdown pull-right flip">
  <button class="btn btn-primary btn-xs dropdown-toggle" type="button" id="dropdownMenuDownload" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
    {% trans "Download" %}
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" aria-labelledby="dropdownMenuDownload">
    {% include "translation-download.html" %}
  </ul>
</div>
{% if object.filename %}
<code>{{ object.filename }}</code>
{% else %}
{% trans "Not available" %}
{% endif %}
</td>
</tr>
</table>
</div>
</div>


<div class="tab-pane" id="history">
{% include "last-changes-content.html" %}
<a class="btn btn-primary" href="{% url 'changes' %}?{{ last_changes_url }}">{% trans "Browse all translation changes" %}</a>
</div>


{% if autoform %}
<div class="tab-pane" id="auto">
<form action="{% url 'auto_translation' project=object.component.project.slug component=object.component.slug lang=object.language.code %}" method="post" enctype="multipart/form-data" data-persist="auto-translation">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
{% documentation_icon 'user/translating' 'auto-translation' right=True %}
{% trans "Automatic translation" %}
</h4>
</div>
<div class="panel-body">
<p>{% trans "Automatic translation takes existing translations in this project and applies them to the current component. It can be used to push translations to a different branch, to fix inconsistent translations or to translate a new component using translation memory." %}</p>
<p>{% trans "Automatic translation via machine translation uses active machine translation engines to get the best possible translations and applies them in this project." %}</p>
{% crispy autoform %}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Apply" %}" class="btn btn-primary" />
</div>
</div>
</form>
</div>
{% endif %}

{% if replace_form %}
<div class="tab-pane" id="replace">

<form action="{% url 'replace' project=object.component.project.slug component=object.component.slug lang=object.language.code %}" method="post" enctype="multipart/form-data">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Search and replace" %}</h4></div>
<div class="panel-body">
<p>{% trans "You can substitute all instances of a string. The search is a simple substring case sensitive search." %}</p>
{% csrf_token %}
{{ replace_form|crispy }}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Replace" %}" class="btn btn-primary" />
</div>
</div>
</form>
</div>
{% endif %}

{% if bulk_state_form %}
<div class="tab-pane" id="bulk-edit">
<form action="{% url 'bulk-edit' project=object.component.project.slug component=object.component.slug lang=object.language.code %}" method="post" enctype="multipart/form-data">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Bulk edit" %}</h4></div>
<div class="panel-body">
<p>{% trans "You can change the state of all strings matching given type at once." %}</p>
{% csrf_token %}
{{ bulk_state_form|crispy }}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Apply" %}" class="btn btn-primary" />
</div>
</div>
</form>
</div>
{% endif %}

{% if user_can_add_unit %}
<div class="tab-pane" id="new">
<form action="{% url 'new-unit' project=object.component.project.slug component=object.component.slug lang=object.language.code %}" method="post">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Add new translation string" %}</h4></div>
<div class="panel-body">
<p>{% trans "You can add a new translation string here, it will automatically appear in all translations." %}</p>
{% csrf_token %}
{{ new_unit_form|crispy }}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Add" %}" class="btn btn-primary" />
</div>
</div>
</form>
</div>
{% endif %}

<div class="tab-pane" id="download">
<form action="{% url 'download_translation' project=object.component.project.slug component=object.component.slug lang=object.language.code %}" method="get" data-persist="download-translation">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Customize download" %}</h4></div>
<div class="panel-body">
{% csrf_token %}
{{ download_form|crispy }}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Download" %}" class="btn btn-primary" />
</div>
</form>

</div>
</div>
{% if user_can_upload_translation %}
<div class="tab-pane" id="upload">
<form action="{% url 'upload_translation' project=object.component.project.slug component=object.component.slug lang=object.language.code %}" method="post" enctype="multipart/form-data" data-persist="upload-translation">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Upload" %}</h4></div>
<div class="panel-body">
{% if user_can_overwrite_translation %}
<p>{% trans "The uploaded file will be merged with the current translation. In case you want to overwrite already translated strings, don't forget to turn it on." %}</p>
{% else %}
<p>{% trans "The uploaded file will be merged with the current translation." %}</p>
{% endif %}
{% csrf_token %}
{{ form|crispy }}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Upload" %}" class="btn btn-primary" />
</div>
</form>

</div>
</div>
{% endif %}

{% if announcement_form %}
<div class="tab-pane" id="announcement">
<form action="{% url 'announcement_translation' project=object.component.project.slug component=object.component.slug lang=object.language.code %}" method="post">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">
    {% documentation_icon 'admin/announcements' right=True %}
    {% trans "Post announcement" %}
</h4></div>
<div class="panel-body">
{% csrf_token %}
{{ announcement_form|crispy }}
<p class="help-block">{% trans "The message is shown on the translation page, until its given expiry, or permanently until it is deleted." %}</p>
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Add" %}" class="btn btn-primary" />
</div>
</form>

</div>
</div>
{% endif %}

{% if delete_form %}
{% include "trans/delete-form.html" %}
{% endif %}

{% if user_can_see_repository_status %}
<div class="tab-pane" id="repository">
<p>{% trans "Loading…" %}</p>
</div>
{% endif %}

<div class="tab-pane" id="search">

<form action="{{ translate_url }}" method="GET" data-persist="search-translation">
{% include "snippets/search-form.html" %}
</form>

</div>

<div class="tab-pane" id="stats">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Statistics" %}</h4></div>
<table class="table">
<thead>
<tr>
<td></td>
<th>{% trans "Percent" %}</th>
<th>{% trans "Strings" %}</th>
<th>{% trans "Words" %}</th>
<th>{% trans "Chars" %}</th>
</tr>
</thead>
<tbody>
<tr>
<th>{% trans "Total" %}</th>
<td class="percent"></td>
<td class="number">{{ object.stats.all|intcomma }}</td>
<td class="number">{{ object.stats.all_words|intcomma }}</td>
<td class="number">{{ object.stats.all_chars|intcomma }}</td>
</tr>
<tr>
<th>{% trans "Translated" %}</th>
<td class="percent">{{ object.stats.translated_percent|percent_format }}</td>
<td class="number">{{ object.stats.translated|intcomma }}</td>
<td class="number">{{ object.stats.translated_words|intcomma }}</td>
<td class="number">{{ object.stats.translated_chars|intcomma }}</td>
</tr>
<tr>
<th>{% trans "Needs editing" %}</th>
<td class="percent">{{ object.stats.fuzzy_percent|percent_format }}</td>
<td class="number">{{ object.stats.fuzzy|intcomma }}</td>
<td class="number">{{ object.stats.fuzzy_words|intcomma }}</td>
<td class="number">{{ object.stats.fuzzy_chars|intcomma }}</td>
<td class="number"></td>
</tr>
<tr>
<th>{% trans "Failing check" %}</th>
<td class="percent">{{ object.stats.allchecks_percent|percent_format }}</td>
<td class="number">{{ object.stats.allchecks|intcomma }}</td>
<td class="number">{{ object.stats.allchecks_words|intcomma }}</td>
<td class="number">{{ object.stats.allchecks_chars|intcomma }}</td>
<td class="number"></td>
</tr>
</tbody>
</table>

</div>

</div>


<div class="col-lg-6">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Last activity" %}</h4></div>
<table class="table">
<tbody>
<tr>
<th>{% trans "Last change" %}<th>
<td class="number" colspan="3">{{ object.stats.last_changed }}</td>
</tr>
<tr>
<th>{% trans "Last author" %}<th>
<td class="number" colspan="3">{{ object.get_last_author }}</td>
</tr>
</tbody>
</table>
</div>
</div>

</div>

</div>

{% include "activity-tab.html" %}

</div>

{% endblock %}
