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

Amélioration de l’internationalisation #115

Merged
merged 4 commits into from
Apr 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ coverage.xml
.pytest_cache/

# Translations
*.mo
# *.mo
*.pot

# Django stuff:
Expand Down
Binary file added blog/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
16 changes: 14 additions & 2 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "127.0.0.1, localhost").replace(" ", "").split(",")

HOST_URL = os.getenv("HOST_URL", "localhost")

# Application definition

INSTALLED_APPS = [
Expand All @@ -55,6 +57,8 @@
"wagtail",
"wagtailmarkdown",
"wagtailmenus",
"wagtail_localize",
"wagtail_localize.locales",
"taggit",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand All @@ -68,7 +72,8 @@
"blog",
]

if DEBUG:
# Only add these on a dev machine
if DEBUG and "localhost" in HOST_URL:
INSTALLED_APPS += [
"django_extensions",
"wagtail.contrib.styleguide",
Expand All @@ -79,6 +84,7 @@
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
Expand Down Expand Up @@ -162,6 +168,12 @@

USE_TZ = True

WAGTAIL_I18N_ENABLED = True

WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [
("en", "English"),
("fr", "French"),
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
Expand Down Expand Up @@ -224,7 +236,7 @@

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
WAGTAILADMIN_BASE_URL = f"{os.getenv('HOST_PROTO', 'https')}://{os.getenv('HOST_URL', 'localhost')}"
WAGTAILADMIN_BASE_URL = f"{os.getenv('HOST_PROTO', 'https')}://{HOST_URL}"

HOST_PORT = os.getenv("HOST_PORT", "")
if HOST_PORT != "":
Expand Down
28 changes: 11 additions & 17 deletions config/urls.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
"""content_manager URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.conf import settings
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.urls import include, path
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls


urlpatterns = [
path("", include("content_manager.urls")),
path("cms-admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += i18n_patterns(
path("", include("blog.urls", namespace="blog")),
path("", include("content_manager.urls")),
prefix_default_language=False,
)
Binary file added content_manager/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
8 changes: 6 additions & 2 deletions content_manager/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-24 16:31+0200\n"
"PO-Revision-Date: 2024-04-24 16:36+0200\n"
"POT-Creation-Date: 2024-04-26 12:07+0200\n"
"PO-Revision-Date: 2024-04-26 12:08+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
Expand Down Expand Up @@ -611,6 +611,10 @@ msgstr "Maximum 4 catégories, chacune contenant maximum 8 liens."
msgid "Mega menu"
msgstr "Méga menu"

#: content_manager/urls.py:18
msgid "search/"
msgstr "recherche/"

#: content_manager/views.py:46 content_manager/views.py:77
msgid "Tags"
msgstr "Étiquettes"
Expand Down
3 changes: 1 addition & 2 deletions content_manager/management/commands/create_starter_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ def create_homepage(self) -> None:
"image": image,
"image_ratio": "3",
"text": RichText(text_raw),
"link_url": admin_url,
"link_label": "Gérer le site",
"link": {"external_url": admin_url, "text": "Gérer le site"},
}

body.append(("imageandtext", image_and_text_block))
Expand Down
8 changes: 7 additions & 1 deletion content_manager/management/commands/set_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from os.path import isfile

from django.conf import settings
from django.core.management.base import BaseCommand
from wagtail.models import Site

Expand All @@ -9,10 +10,15 @@

class Command(BaseCommand):
def handle(self, *args, **kwargs):
"""Sets the site hostname, and imports contents from the config.json file if present"""
site = Site.objects.filter(is_default_site=True).first()
site.hostname = settings.HOST_URL
site.save()

if isfile("config.json"):
with open("config.json") as config_file:
config_data = json.load(config_file)
site = Site.objects.filter(is_default_site=True).first()

config_data["site_id"] = site.id

_config, created = CmsDsfrConfig.objects.get_or_create(id=1, defaults=config_data)
Expand Down
8 changes: 2 additions & 6 deletions content_manager/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from django.urls import include, path
from django.utils.translation import gettext_lazy as _
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls

from content_manager.views import SearchResultsView, TagsListView, TagView


urlpatterns = [
path("cms-admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path("recherche/", SearchResultsView.as_view(), name="cms_search"),
path("", include("blog.urls", namespace="blog")),
path(_("search/"), SearchResultsView.as_view(), name="cms_search"),
path("tags/<str:tag>/", TagView.as_view(), name="global_tag"),
path("tags/", TagsListView.as_view(), name="global_tags_list"),
path("", include(wagtail_urls)),
Expand Down
36 changes: 35 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ django-storages = {extras = ["s3"], version = "^1.14.2"}
boto3 = "^1.34.56"
beautifulsoup4 = "^4.12.3"
django-taggit = "^5.0.1"
wagtail-localize = "^1.9"


[tool.poetry.group.dev.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load static dsfr_tags wagtailuserbar wagtailsettings_tags sass_tags %}
{% load i18n static dsfr_tags wagtailuserbar wagtailsettings_tags sass_tags %}
{% get_settings %}
<!DOCTYPE html>
<html lang="fr"
<html lang="{% get_current_language as LANGUAGE_CODE %}{{ LANGUAGE_CODE }}"
data-fr-scheme="system"
{% if settings.content_manager.CmsDsfrConfig.mourning %}data-fr-mourning{% endif %}>

Expand Down
2 changes: 1 addition & 1 deletion templates/blocks/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
aria-controls="fr-theme-modal"
data-fr-opened="false"
class="fr-icon-theme-fill fr-link--icon-left fr-footer__bottom-link"
data-fr-js-modal-button="true">Paramètres d’affichage</button>
data-fr-js-modal-button="true">{% translate "Display settings" %}</button>
</li>
{% endif %}
{% endblock footer_links %}
24 changes: 15 additions & 9 deletions templates/blocks/header.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{% extends "dsfr/header.html" %}
{% load static wagtailcore_tags wagtailimages_tags menu_tags %}
{% load i18n static wagtailcore_tags wagtailimages_tags menu_tags %}

{% block brand %}
{% translate "Home page" as home_page %}
<a href="/"
title="Accueil — {{ settings.content_manager.CmsDsfrConfig.header_brand }}">
title="{{ home_page }} — {{ settings.content_manager.CmsDsfrConfig.header_brand }}">
<p class="fr-logo">{{ settings.content_manager.CmsDsfrConfig.header_brand_html|safe }}</p>
</a>
{% endblock brand %}

{% block service_title %}
{% translate "Home page" as home_page %}
<a href="/"
title="Accueil — {{ settings.content_manager.CmsDsfrConfig.site_title }}">
title="{{ home_page }} — {{ settings.content_manager.CmsDsfrConfig.site_title }}">

<p class="fr-header__service-title">
{% if settings.content_manager.CmsDsfrConfig.site_title|slice:"-2:" == "fr" %}
Expand Down Expand Up @@ -48,21 +50,23 @@
{% endblock header_tools %}

{% block header_search %}
{% translate "Search" as search_label %}
{% if settings.content_manager.CmsDsfrConfig.search_bar %}
<div class="fr-header__search fr-modal" id="modal-search">
<div class="fr-container fr-container-lg--fluid">
{% translate "Close" as close_label %}
<button class="fr-btn--close fr-btn"
aria-controls="modal-search"
title="Fermer">Fermer</button>
title="{{ close_label }}">{{ close_label }}</button>
<form action="{% url 'cms_search' %}" method="get">
<div class="fr-search-bar" id="search-bar" role="search">
<label class="fr-label" for="search-bar-input">Rechercher</label>
<label class="fr-label" for="search-bar-input">{{ search_label }}</label>
<input class="fr-input"
placeholder="Rechercher"
placeholder="{{ search_label }}"
type="search"
id="query"
name="q">
<button class="fr-btn" title="Rechercher">Rechercher</button>
<button class="fr-btn" title="{{ search_label }}">{{ search_label }}</button>
</div>
</form>
</div>
Expand All @@ -79,11 +83,13 @@
id="fr-menu-mobile"
aria-labelledby="fr-btn-menu-mobile">
<div class="fr-container">
{% translate "Close" as close_label %}
<button type="button"
class="fr-btn--close fr-btn"
aria-controls="fr-menu-mobile">Fermer</button>
aria-controls="fr-menu-mobile">{{ close_label }}</button>
<div class="fr-header__menu-links"></div>
<nav class="fr-nav" id="fr-navigation" aria-label="Menu principal">
{% translate "Main menu" as main_menu_label %}
<nav class="fr-nav" id="fr-navigation" aria-label="{{ main_menu_label }}">
{% main_menu max_levels=2 template="menus/custom_main_menu.html" sub_menu_template="menus/custom_sub_menu.html" %}
</nav>
</div>
Expand Down
Loading