Compare commits

...

2 Commits

Author SHA1 Message Date
Julien Palard 96e89d34c9
Also i18n on data in the DB. 2023-12-20 17:20:37 +01:00
Julien Palard 8285744dcb
i18n 2023-12-20 17:09:36 +01:00
12 changed files with 147 additions and 2 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ db.sqlite3
*.webm
.venv
.envrc
*.mo

View File

@ -12,6 +12,9 @@ https://docs.djangoproject.com/en/5.0/ref/settings/
from pathlib import Path
from django.utils.translation import gettext_lazy as _
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@ -32,6 +35,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [
'photos',
"modeltranslation",
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
@ -43,6 +47,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@ -124,6 +129,12 @@ MEDIA_URL = 'media/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LANGUAGES = [
("fr", _("French")),
("en", _("English")),
]
try:
from local_settings import *
except ImportError:

View File

@ -0,0 +1,27 @@
# 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.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-12-20 15:58+0000\n"
"PO-Revision-Date: 2023-12-20 16:59+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.4.1\n"
#: eqy_fr/settings.py:132
msgid "French"
msgstr "Français"
#: eqy_fr/settings.py:133
msgid "English"
msgstr "Anglais"

View File

@ -1,5 +1,8 @@
from django.contrib import admin
from modeltranslation.admin import TranslationAdmin
from photos.models import Media
admin.site.register(Media)
@admin.register(Media)
class MediaAdmin(TranslationAdmin):
...

View File

@ -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.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-12-20 15:58+0000\n"
"PO-Revision-Date: 2023-12-20 17:00+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.4.1\n"
#: photos/templates/photos/index.html:13
msgid "This is the subtitle."
msgstr "Ceci est un sous-titre."
#: photos/templates/photos/index.html:27
msgid ""
"\n"
" Blah blah blah blah blah blah\n"
" "
msgstr ""
"\n"
" Bouhaha Brouhaha brouhaha\n"
" "
#: photos/views.py:8
msgid "Title"
msgstr "Titre"

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0 on 2023-12-20 16:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("photos", "0001_initial"),
]
operations = [
migrations.AddField(
model_name="media",
name="title",
field=models.CharField(default="Sans titre", max_length=500),
preserve_default=False,
),
]

View File

@ -0,0 +1,22 @@
# Generated by Django 5.0 on 2023-12-20 16:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("photos", "0002_media_title"),
]
operations = [
migrations.AddField(
model_name="media",
name="title_en",
field=models.CharField(max_length=500, null=True),
),
migrations.AddField(
model_name="media",
name="title_fr",
field=models.CharField(max_length=500, null=True),
),
]

View File

@ -2,6 +2,7 @@ from django.db import models
class Media(models.Model):
title = models.CharField(max_length=500)
photo = models.FileField(upload_to="photos/%Y/", null=True, blank=True)
video = models.FileField(upload_to="videos/%Y/", null=True, blank=True)

View File

@ -1,3 +1,5 @@
{% load i18n %}
<!DOCTYPE html>
<html lang="fr">
<head>
@ -6,9 +8,14 @@
<title>photos</title>
</head>
<body>
<header>
<h1>{{title}}</h1>
<h2>{% translate "This is the subtitle." %}</h2>
</header>
<main>
{% for media in medias %}
<section>
<h3>{{media.title}}</h3>
{% if media.photo %}
<img width="100%" src="{{ media.photo.url }}"/>
{% elif media.video %}
@ -17,5 +24,10 @@
</section>
{% endfor %}
</main>
<footer>
{% blocktranslate %}
Blah blah blah blah blah blah
{% endblocktranslate %}
</footer>
</body>
</html>

10
photos/translation.py Normal file
View File

@ -0,0 +1,10 @@
from modeltranslation.translator import TranslationOptions, translator
from photos.models import Media
class MediaTranslationOptions(TranslationOptions):
fields = ("title",)
translator.register(Media, MediaTranslationOptions)

View File

@ -1,7 +1,9 @@
from django.shortcuts import render
from django.utils.translation import gettext as _
from photos.models import Media
def index(request):
return render(request, "photos/index.html", context={"medias": Media.objects.all()})
title = _("Title")
return render(request, "photos/index.html", context={"title": title, "medias": Media.objects.all()})

View File

@ -1 +1,2 @@
django
django-modeltranslation