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

{% block breadcrumbs %}
<li><a href="{% url 'languages' %}">{% trans "Languages" %}</a></li>
<li><a href="{{ object.get_absolute_url }}">{{ object }}</a></li>
{% endblock %}

{% block content %}

{% announcements language=object %}

{% perm 'language.edit' as user_can_edit_language %}

<ul class="nav nav-pills">
  <li class="active"><a href="#overview" data-toggle="tab">{% trans "Projects" %}</a></li>
  <li><a href="#information" data-toggle="tab">{% trans "Information" %}</a></li>
  <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' lang=object.code %}" data-monthly="{% url 'monthly_activity' lang=object.code %}">{% trans "Activity" %}</a></li>
  <li><a href="#dicts" data-toggle="tab">{% trans "Glossaries" %}</a></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 'checks' %}?lang={{ object.code }}">{% trans "Failing checks" %}</a></li>
      {% if user_can_edit_language %}
      <li role="separator" class="divider"></li>
      {% if not object.translation_set.exists %}
      <li><a href="{% url 'show_language' lang=object.code %}" class="link-post">{% trans "Delete" %}</a></li>
      {% endif %}
      <li><a href="{% url 'edit-language' pk=object.pk %}">{% trans "Edit" %}</a></li>
      {% endif %}
    </ul>
   </li>
</ul>

<div class="tab-content">

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

{% include "snippets/list-objects.html" with show_admin_badge=True objects=projects label=_("Project") language=object global_base="stats" stats_attr="language_stats" %}

</div>

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

<table class="table">
<tr>
<th>{% trans "Language code" %}</th>
<td colspan="2">
{% if user_can_edit_language %}
<a class="btn btn-primary btn-xs pull-right flip" href="{% url 'edit-language' pk=object.pk %}">{% trans "Edit" %}</a>
{% endif %}
{{ object.code }}
</td>
</tr>
<tr>
<th>{% trans "Text direction" %}</th>
<td colspan="2">{{ object.get_direction_display }}</td>
</tr>

{% for plural in object.plural_set.order %}
<tr class="info">
<th colspan="3">
{% if user_can_edit_language %}
<a class="btn btn-primary btn-xs pull-right flip" href="{% url 'edit-plural' pk=plural.pk %}">{% trans "Edit" %}</a>
{% endif %}
{% blocktrans with source_description=plural.get_source_display %}Plural: {{ source_description }}{% endblocktrans %}
<span class="badge">{% blocktrans count count=plural.translation_set.count %}{{ count }} translation{% plural %}{{ count }} translations{% endblocktrans %}</span>
</th>
</tr>
<tr>
<th>{% trans "Number of plurals" %}</th>
<td colspan="2">{{ plural.number }}</td>
</tr>
<tr>
<th>{% trans "Plural type" %}</th>
<td colspan="2">{{ plural.get_type_display }}</td>
</tr>
<tr>
<th rowspan="{{ plural.number }}">{% trans "Plurals" %}</th>
{% if plural.number > 1 %}
{% for item in plural.list_plurals %}
{% if item.index > 1 %}
<tr>
{% endif %}
<td>{{ item.name }}</td>
<td>{{ item.examples }}</td>
</tr>
{% endfor %}
{% else %}
<td colspan="2"></td>
</tr>
{% endif %}
<tr>
<th>{% trans "Plural formula" %}</th>
<td colspan="2"><code>{{ plural.formula }}</code></td>
</tr>
{% endfor %}
</table>

</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 language changes" %}</a>
</div>

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

<div class="tab-pane" id="dicts">
{% if dicts %}
<div class="list-group">
{% for dict in dicts %}
<a class="list-group-item" href="{% url 'show_glossary' lang=object.code project=dict.slug %}">{{ dict }}</a>
{% endfor %}
</div>
{% else %}
{% trans "There are no glossaries defined for this language." as msg %}
{% show_message "info" msg %}
{% endif %}
</div>

</div>

{% endblock %}
