internationalization for news

This commit is contained in:
ix 2021-09-07 21:13:30 +02:00
parent 2f7d96ed03
commit 9f431ac4fa
11 changed files with 131 additions and 75 deletions

View File

@ -12,7 +12,7 @@
{% if description %}
{{ description|safe }}
{% else %}
{% trans "No translation available for this challenge. Try another lang (French or English)." %}
{% trans "No translation available. Please try another language (English or French)." %}
{% endif %}
</div>
<div class="ctf-footer">

View File

@ -0,0 +1,33 @@
# Generated by Django 3.2.7 on 2021-09-07 19:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='new',
name='content_de',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='new',
name='content_en',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='new',
name='content_ru',
field=models.TextField(blank=True),
),
migrations.AlterField(
model_name='new',
name='content',
field=models.TextField(blank=True),
),
]

View File

@ -2,7 +2,10 @@ from django.db import models
class new(models.Model):
name = models.CharField(max_length=100)
content = models.TextField()
content = models.TextField(blank=True)
content_en = models.TextField(blank=True)
content_ru = models.TextField(blank=True)
content_de = models.TextField(blank=True)
slug = models.SlugField(max_length=55)
pub_date = models.DateTimeField('Date published')
def __str__(self):

View File

@ -1,6 +1,7 @@
{% extends 'base.html' %}
{% block content %}
{% load i18n %}
{% get_current_language as lang %}
<div class="row">
<div class="col-lg-9 col-sm-12 news-card">
{% if news %}
@ -8,7 +9,19 @@
<div class="card text-center news-card">
<div class="card-body">
<h5 class="card-title">{{ n.name|safe }}</h5>
<p class="card-text">{{ n.content|safe }}</p>
<p class="card-text">
{% if lang == "fr" and n.content %}
{{ n.content|safe }}
{% elif lang == "en" and n.content_en %}
{{ n.content_en|safe }}
{% elif lang == "de" and n.content_de %}
{{ n.content_de|safe }}
{% elif lang == "ru" and n.content_ru %}
{{ n.content_ru|safe }}
{% else %}
{% trans "No translation available. Please try another language (English or French)." %}
{% endif %}
</p>
</div>
<div class="card-footer text-muted">
{{ n.pub_date }}

View File

@ -9,6 +9,19 @@ from django.utils.translation import (
LANGUAGE_SESSION_KEY, check_for_language, get_language,
)
def get_content_by_lang(news):
lang = get_language()
ret = None
if lang == "fr":
ret = news.content
elif lang == "en":
ret = news.content_en
elif lang == "de":
ret = news.content_de
elif lang == "ru":
ret = news.content_ru
return ret
def home(request):
lang_code = get_language()
if hasattr(request, 'session') and LANGUAGE_SESSION_KEY in request.session:

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-07 19:50+0200\n"
"POT-Creation-Date: 2021-09-07 21:12+0200\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"
@ -166,10 +166,9 @@ msgstr ""
msgid "Published date"
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:15
#: ctfs/templates/ctfs/ctf_info.html:15 home/templates/home/home.html:22
msgid ""
"No translation available for this challenge. Try another lang (French or "
"English)."
"No translation available. Please try another language (English or French)."
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:21
@ -224,35 +223,35 @@ msgstr ""
msgid "No category available."
msgstr ""
#: home/templates/home/home.html:19
#: home/templates/home/home.html:32
msgid "No article available."
msgstr ""
#: home/templates/home/home.html:24
#: home/templates/home/home.html:37
msgid "Latest challenges added"
msgstr ""
#: home/templates/home/home.html:30
#: home/templates/home/home.html:43
msgid "No ctf available."
msgstr ""
#: home/templates/home/home.html:40
#: home/templates/home/home.html:53
msgid "Flags counter"
msgstr ""
#: project/settings.py:111
#: project/settings.py:113
msgid "English"
msgstr ""
#: project/settings.py:112
#: project/settings.py:114
msgid "German"
msgstr ""
#: project/settings.py:113
#: project/settings.py:115
msgid "French"
msgstr ""
#: project/settings.py:114
#: project/settings.py:116
msgid "Russian"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-07 19:50+0200\n"
"POT-Creation-Date: 2021-09-07 21:12+0200\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"
@ -166,10 +166,9 @@ msgstr ""
msgid "Published date"
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:15
#: ctfs/templates/ctfs/ctf_info.html:15 home/templates/home/home.html:22
msgid ""
"No translation available for this challenge. Try another lang (French or "
"English)."
"No translation available. Please try another language (English or French)."
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:21
@ -224,35 +223,35 @@ msgstr ""
msgid "No category available."
msgstr ""
#: home/templates/home/home.html:19
#: home/templates/home/home.html:32
msgid "No article available."
msgstr ""
#: home/templates/home/home.html:24
#: home/templates/home/home.html:37
msgid "Latest challenges added"
msgstr ""
#: home/templates/home/home.html:30
#: home/templates/home/home.html:43
msgid "No ctf available."
msgstr ""
#: home/templates/home/home.html:40
#: home/templates/home/home.html:53
msgid "Flags counter"
msgstr ""
#: project/settings.py:111
#: project/settings.py:113
msgid "English"
msgstr ""
#: project/settings.py:112
#: project/settings.py:114
msgid "German"
msgstr ""
#: project/settings.py:113
#: project/settings.py:115
msgid "French"
msgstr ""
#: project/settings.py:114
#: project/settings.py:116
msgid "Russian"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-07 19:50+0200\n"
"POT-Creation-Date: 2021-09-07 21:12+0200\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"
@ -166,10 +166,9 @@ msgstr ""
msgid "Published date"
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:15
#: ctfs/templates/ctfs/ctf_info.html:15 home/templates/home/home.html:22
msgid ""
"No translation available for this challenge. Try another lang (French or "
"English)."
"No translation available. Please try another language (English or French)."
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:21
@ -224,35 +223,35 @@ msgstr ""
msgid "No category available."
msgstr ""
#: home/templates/home/home.html:19
#: home/templates/home/home.html:32
msgid "No article available."
msgstr ""
#: home/templates/home/home.html:24
#: home/templates/home/home.html:37
msgid "Latest challenges added"
msgstr ""
#: home/templates/home/home.html:30
#: home/templates/home/home.html:43
msgid "No ctf available."
msgstr ""
#: home/templates/home/home.html:40
#: home/templates/home/home.html:53
msgid "Flags counter"
msgstr ""
#: project/settings.py:111
#: project/settings.py:113
msgid "English"
msgstr ""
#: project/settings.py:112
#: project/settings.py:114
msgid "German"
msgstr ""
#: project/settings.py:113
#: project/settings.py:115
msgid "French"
msgstr ""
#: project/settings.py:114
#: project/settings.py:116
msgid "Russian"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-07 19:50+0200\n"
"POT-Creation-Date: 2021-09-07 21:12+0200\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"
@ -168,10 +168,9 @@ msgstr "Mis à jour."
msgid "Published date"
msgstr "Date de publication"
#: ctfs/templates/ctfs/ctf_info.html:15
#: ctfs/templates/ctfs/ctf_info.html:15 home/templates/home/home.html:22
msgid ""
"No translation available for this challenge. Try another lang (French or "
"English)."
"No translation available. Please try another language (English or French)."
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:21
@ -226,35 +225,35 @@ msgstr "Catégories"
msgid "No category available."
msgstr "Il n'y a pas de catégorie disponible."
#: home/templates/home/home.html:19
#: home/templates/home/home.html:32
msgid "No article available."
msgstr "Il n'y a pas d'article disponible."
#: home/templates/home/home.html:24
#: home/templates/home/home.html:37
msgid "Latest challenges added"
msgstr "Derniers challenges ajoutés"
#: home/templates/home/home.html:30
#: home/templates/home/home.html:43
msgid "No ctf available."
msgstr "Pas de challenge disponible"
#: home/templates/home/home.html:40
#: home/templates/home/home.html:53
msgid "Flags counter"
msgstr "Compteur de flags"
#: project/settings.py:111
#: project/settings.py:113
msgid "English"
msgstr "Anglais"
#: project/settings.py:112
#: project/settings.py:114
msgid "German"
msgstr "Allemand"
#: project/settings.py:113
#: project/settings.py:115
msgid "French"
msgstr "Français"
#: project/settings.py:114
#: project/settings.py:116
msgid "Russian"
msgstr "Russe"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-07 19:50+0200\n"
"POT-Creation-Date: 2021-09-07 21:12+0200\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"
@ -166,10 +166,9 @@ msgstr ""
msgid "Published date"
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:15
#: ctfs/templates/ctfs/ctf_info.html:15 home/templates/home/home.html:22
msgid ""
"No translation available for this challenge. Try another lang (French or "
"English)."
"No translation available. Please try another language (English or French)."
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:21
@ -224,35 +223,35 @@ msgstr ""
msgid "No category available."
msgstr ""
#: home/templates/home/home.html:19
#: home/templates/home/home.html:32
msgid "No article available."
msgstr ""
#: home/templates/home/home.html:24
#: home/templates/home/home.html:37
msgid "Latest challenges added"
msgstr ""
#: home/templates/home/home.html:30
#: home/templates/home/home.html:43
msgid "No ctf available."
msgstr ""
#: home/templates/home/home.html:40
#: home/templates/home/home.html:53
msgid "Flags counter"
msgstr ""
#: project/settings.py:111
#: project/settings.py:113
msgid "English"
msgstr ""
#: project/settings.py:112
#: project/settings.py:114
msgid "German"
msgstr ""
#: project/settings.py:113
#: project/settings.py:115
msgid "French"
msgstr ""
#: project/settings.py:114
#: project/settings.py:116
msgid "Russian"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-07 19:50+0200\n"
"POT-Creation-Date: 2021-09-07 21:12+0200\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"
@ -168,10 +168,9 @@ msgstr ""
msgid "Published date"
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:15
#: ctfs/templates/ctfs/ctf_info.html:15 home/templates/home/home.html:22
msgid ""
"No translation available for this challenge. Try another lang (French or "
"English)."
"No translation available. Please try another language (English or French)."
msgstr ""
#: ctfs/templates/ctfs/ctf_info.html:21
@ -226,35 +225,35 @@ msgstr ""
msgid "No category available."
msgstr ""
#: home/templates/home/home.html:19
#: home/templates/home/home.html:32
msgid "No article available."
msgstr "Нет доступных статей."
#: home/templates/home/home.html:24
#: home/templates/home/home.html:37
msgid "Latest challenges added"
msgstr ""
#: home/templates/home/home.html:30
#: home/templates/home/home.html:43
msgid "No ctf available."
msgstr ""
#: home/templates/home/home.html:40
#: home/templates/home/home.html:53
msgid "Flags counter"
msgstr ""
#: project/settings.py:111
#: project/settings.py:113
msgid "English"
msgstr ""
#: project/settings.py:112
#: project/settings.py:114
msgid "German"
msgstr ""
#: project/settings.py:113
#: project/settings.py:115
msgid "French"
msgstr ""
#: project/settings.py:114
#: project/settings.py:116
msgid "Russian"
msgstr ""