Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change language selector from select to links #89

Merged
merged 3 commits into from Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -15,6 +15,7 @@ shell:
# Need to have GNU gettext installed
transprepare:
@poetry run django-admin makemessages --add-location file
@poetry run django-admin makemessages --add-location file --domain djangojs

transcompile:
@poetry run django-admin compilemessages
Expand Down
2 changes: 2 additions & 0 deletions config/urls.py
@@ -1,10 +1,12 @@
from django.urls import include, path
from django.views.i18n import JavaScriptCatalog

from contributors.admin.custom import site

urlpatterns = [
path('admin/', site.urls),
path('i18n/', include('django.conf.urls.i18n')),
path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript_catalog'),
path('auth/', include('django.contrib.auth.urls')),
path('auth/', include('auth.urls')),
path('', include('contributors.urls')),
Expand Down
19 changes: 19 additions & 0 deletions contributors/migrations/0003_auto_20200317_0729.py
@@ -0,0 +1,19 @@
# Generated by Django 2.2.11 on 2020-03-17 04:29

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('contributors', '0002_issueinfo'),
]

operations = [
migrations.AlterField(
model_name='issueinfo',
name='issue',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='info', to='contributors.Contribution', verbose_name='issue'),
),
]
Binary file modified locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
99 changes: 62 additions & 37 deletions locale/ru/LC_MESSAGES/django.po
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-08 12:00+0500\n"
"POT-Creation-Date: 2020-03-27 17:10+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -248,14 +248,16 @@ msgstr "Рекомендованные книги"
msgid "Blog"
msgstr "Блог"

#: templates/components/navbar.html templates/organization_details.html
#: templates/organizations_list.html templates/repositories_list.html
#: templates/components/navbar.html
#: templates/components/tables/organizations_list.html
#: templates/organization_details.html templates/repositories_list.html
msgid "Repositories"
msgstr "Репозитории"

#: templates/components/navbar.html templates/contributors_list.html
#: templates/organization_details.html templates/repositories_list.html
#: templates/repository_details.html
#: templates/components/navbar.html
#: templates/components/tables/organization_details.html
#: templates/components/tables/repositories_list.html
#: templates/contributors_list.html templates/repository_details.html
msgid "Contributors"
msgstr "Контрибьюторы"

Expand All @@ -271,56 +273,75 @@ msgstr "Администрирование"
msgid "Log out"
msgstr "Выйти"

#: templates/components/navbar.html templates/registration/login.html
msgid "Log in"
msgstr "Войти"
#: templates/components/tables/contributors_list.html
#: templates/components/tables/recent_contributors.html
#: templates/components/tables/repository_details.html
msgid "Login"
msgstr "Логин"

#: templates/components/navbar.html templates/registration/registration.html
msgid "Register"
msgstr "Зарегистрироваться"
#: templates/components/tables/contributors_list.html
#: templates/components/tables/organization_details.html
#: templates/components/tables/organizations_list.html
#: templates/components/tables/recent_contributors.html
#: templates/components/tables/repositories_list.html
#: templates/components/tables/repository_details.html
msgid "Name"
msgstr "Имя"

#: templates/contributor_details.html templates/contributors_list.html
#: templates/home.html templates/repository_details.html
#: templates/components/tables/contributors_list.html
#: templates/components/tables/recent_contributors.html
#: templates/components/tables/repository_details.html
#: templates/contributor_details.html
msgid "Commits"
msgstr "Коммиты"

#: templates/contributor_details.html templates/contributors_list.html
#: templates/home.html templates/repository_details.html
#: templates/components/tables/contributors_list.html
#: templates/components/tables/recent_contributors.html
#: templates/components/tables/repository_details.html
#: templates/contributor_details.html
msgid "Additions"
msgstr "Добавления"

#: templates/contributor_details.html templates/contributors_list.html
#: templates/home.html templates/repository_details.html
#: templates/components/tables/contributors_list.html
#: templates/components/tables/recent_contributors.html
#: templates/components/tables/repository_details.html
#: templates/contributor_details.html
msgid "Deletions"
msgstr "Удаления"

#: templates/contributor_details.html templates/contributors_list.html
#: templates/home.html templates/organization_details.html
#: templates/repositories_list.html templates/repository_details.html
#: templates/components/tables/contributors_list.html
#: templates/components/tables/organization_details.html
#: templates/components/tables/recent_contributors.html
#: templates/components/tables/repositories_list.html
#: templates/components/tables/repository_details.html
#: templates/contributor_details.html
msgid "Pull requests"
msgstr "Запросы на включение"

#: templates/contributor_details.html templates/contributors_list.html
#: templates/home.html templates/organization_details.html
#: templates/repositories_list.html templates/repository_details.html
#: templates/components/tables/contributors_list.html
#: templates/components/tables/organization_details.html
#: templates/components/tables/recent_contributors.html
#: templates/components/tables/repositories_list.html
#: templates/components/tables/repository_details.html
#: templates/contributor_details.html
msgid "Issues"
msgstr "Проблемы"

#: templates/contributor_details.html templates/contributors_list.html
#: templates/home.html templates/repository_details.html
#: templates/components/tables/contributors_list.html
#: templates/components/tables/recent_contributors.html
#: templates/components/tables/repository_details.html
#: templates/contributor_details.html
msgid "Comments"
msgstr "Комментарии"

#: templates/contributors_list.html templates/home.html
#: templates/components/tables/repositories_list.html
#: templates/repository_details.html
msgid "Login"
msgstr "Логин"
msgid "Organization"
msgstr "Организация"

#: templates/contributors_list.html templates/home.html
#: templates/organization_details.html templates/organizations_list.html
#: templates/repositories_list.html templates/repository_details.html
msgid "Name"
msgstr "Имя"
#: templates/home.html
msgid "Past year activity"
msgstr "Активность за год"

#: templates/home.html
msgid "Recently active contributors"
Expand All @@ -339,10 +360,14 @@ msgctxt "logon"
msgid "Login"
msgstr "Вход"

#: templates/registration/login.html
msgid "Log in"
msgstr "Войти"

#: templates/registration/registration.html
msgid "Registration"
msgstr "Регистрация"

#: templates/repositories_list.html templates/repository_details.html
msgid "Organization"
msgstr "Организация"
#: templates/registration/registration.html
msgid "Register"
msgstr "Зарегистрироваться"
Binary file added locale/ru/LC_MESSAGES/djangojs.mo
Binary file not shown.
37 changes: 37 additions & 0 deletions locale/ru/LC_MESSAGES/djangojs.po
@@ -0,0 +1,37 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-27 19:11+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: Russian\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n"
"%100>=11 && n%100<=14)? 2 : 3);\n"

#: static/js/yearActivityChart.js
msgid "Commits"
msgstr "Коммиты"

#: static/js/yearActivityChart.js
msgid "Pull requests"
msgstr "Запросы на включение"

#: static/js/yearActivityChart.js
msgid "Issues"
msgstr "Проблемы"

#: static/js/yearActivityChart.js
msgid "Comments"
msgstr "Комментарии"
12 changes: 12 additions & 0 deletions static/js/scripts.js
Expand Up @@ -28,3 +28,15 @@ $(document).ready(function () {
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});

// Language selector
function switchLanguage(e) {
e.preventDefault();
const langForm = document.querySelector('#language-form');
const selector = langForm.querySelector('select');
selector.value = e.target.innerText.trim().toLowerCase();
langForm.submit();
}

const langLinks = document.querySelectorAll('.inactive-lang-link');
langLinks.forEach((link) => link.addEventListener('click', switchLanguage));
56 changes: 56 additions & 0 deletions static/js/yearActivityChart.js
@@ -0,0 +1,56 @@
function generateMonths() {
const months = [];
for (let i = 1; i <= 12; i += 1) {
months.push(moment().add(i,'months').format('MMM'));
}
return months;
}

const contributions = JSON.parse(document.getElementById('contributions').textContent);

const ctx = document.getElementById('yearActivityChart').getContext('2d');
const yearActivityChart = new Chart(ctx, {
type: 'bar',
data: {
labels: generateMonths(),
datasets: [
{
label: gettext('Commits'),
data: contributions.commits,
backgroundColor: 'rgba(87, 173, 219, 0.7)',
},
{
label: gettext('Pull requests'),
data: contributions.pull_requests,
backgroundColor: 'rgba(82, 206, 97, 0.7)',
},
{
label: gettext('Issues'),
data: contributions.issues,
backgroundColor: 'rgba(226, 113, 90, 0.7)',
},
{
label: gettext('Comments'),
data: contributions.comments,
backgroundColor: 'rgba(242, 232, 96, 0.7)',
},
],
},
options: {
tooltips: {
mode: 'index',
intersect: false,
},
animation: {
duration: 0,
},
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true,
}],
},
},
});
3 changes: 3 additions & 0 deletions templates/base.html
Expand Up @@ -9,6 +9,8 @@
<link rel="stylesheet" href="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.css">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<link rel="icon" type="image/png" href="{% static 'favicon.png' %}">
<script src="{% url 'javascript_catalog' %}"></script>
{% block head_scripts %}{% endblock %}
{% if GTM_ID %}
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
Expand Down Expand Up @@ -44,5 +46,6 @@ <h1>{% block header %}{% endblock %}</h1>
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
{% endif %}
{% block body_end_scripts %}{% endblock %}
</body>
</html>
10 changes: 8 additions & 2 deletions templates/components/footer.html
Expand Up @@ -4,10 +4,10 @@
<div class="col-12 col-md">
<ul class="list-unstyled my-0">
<li>
<form action="{% url 'set_language' %}" method="post">
<form action="{% url 'set_language' %}" method="post" id="language-form" style="display: none;">
{% csrf_token %}
<label for="language">{% trans "Language" %}</label>
<select id="language" name="language" onchange="this.form.submit();">
<select name="language">
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
Expand All @@ -17,6 +17,12 @@
{% endfor %}
</select>
</form>
{% trans "Language" %}:
{% for language in languages %}
<a {% if language.code != LANGUAGE_CODE %}href="#" class="inactive-lang-link"{% endif %}>
{{ language.code|upper }}
</a>
{% endfor %}
</li>
<li><a target="_blank" href="http://github.com/Hexlet/hexlet-friends">{% trans "Source code" %}</a></li>
</ul>
Expand Down