feat: set up jinja2 i18n
This commit is contained in:
parent
9c43efc848
commit
4bb63e7a55
|
|
@ -0,0 +1,29 @@
|
|||
# French translations for PROJECT.
|
||||
# Copyright (C) 2024 ORGANIZATION
|
||||
# This file is distributed under the same license as the PROJECT project.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, 2024.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PROJECT VERSION\n"
|
||||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
|
||||
"POT-Creation-Date: 2024-05-21 15:15+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language: fr\n"
|
||||
"Language-Team: fr <LL@li.org>\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=utf-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Generated-By: Babel 2.15.0\n"
|
||||
|
||||
#: src/lib/nav.html:6
|
||||
msgid "Collective"
|
||||
msgstr "Collectif"
|
||||
|
||||
#: src/lib/nav.html:9 src/pages/index/games.html:1
|
||||
msgid "Games"
|
||||
msgstr "Jeux"
|
||||
|
||||
47
noxfile.py
47
noxfile.py
|
|
@ -1,8 +1,11 @@
|
|||
"""Nox configuration file."""
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from shutil import copytree
|
||||
|
||||
from nox import Session, session
|
||||
|
||||
_LOCALES = ["fr"]
|
||||
|
||||
@session()
|
||||
def lint(session: Session) -> None:
|
||||
|
|
@ -20,19 +23,55 @@ def mypy(session: Session) -> None:
|
|||
@session
|
||||
def build(session: Session) -> None:
|
||||
"""Run unit tests."""
|
||||
session.install("nodeenv", "git+https://git.collectivit.org/collectivit/jean-website")
|
||||
session.install(
|
||||
"nodeenv",
|
||||
"git+https://git.collectivit.org/collectivit/jean-website",
|
||||
"babel",
|
||||
"jinja2"
|
||||
)
|
||||
|
||||
session.run_always("nodeenv", "-p")
|
||||
session.run_always("npm", "install", "-g", "sass")
|
||||
|
||||
session.log("Building website...")
|
||||
session.run("jwebsite", "build")
|
||||
|
||||
session.log("Building css...")
|
||||
session.run("npx", "sass", "src/style.scss", "build/style.css", "--style=compressed")
|
||||
|
||||
session.log("Copying static files to build directory...")
|
||||
copytree("src/assets", "build", dirs_exist_ok=True)
|
||||
|
||||
with TemporaryDirectory() as locale_dir:
|
||||
for locale in _LOCALES:
|
||||
output_dir = Path(locale_dir) / locale / "LC_MESSAGES"
|
||||
output_dir.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
session.run(
|
||||
"pybabel",
|
||||
"compile",
|
||||
f"--input-file=locale/{locale}/LC_MESSAGES/site.po",
|
||||
f"--output-file={output_dir}/site.mo",
|
||||
"--use-fuzzy"
|
||||
)
|
||||
|
||||
session.log("Building website...")
|
||||
session.run(
|
||||
"jwebsite", "build",
|
||||
env={
|
||||
'FROG_LOCALE_DIR': str(locale_dir)
|
||||
}
|
||||
)
|
||||
|
||||
@session
|
||||
def extract_messages(session: Session) -> None:
|
||||
session.install("babel", "jinja2")
|
||||
|
||||
with TemporaryDirectory() as tmp_dir:
|
||||
messages_file = Path(tmp_dir) / "messages.po"
|
||||
session.run("pybabel", "extract", "--mapping", "babel.cfg", f"--output-file={messages_file}", ".")
|
||||
session.run("pybabel", "update", "--domain=site", f"--input-file={messages_file}", "--output-dir=locale")
|
||||
|
||||
@session
|
||||
def compile_messages(session: Session) -> None:
|
||||
session.install("babel", "jinja2")
|
||||
|
||||
@session()
|
||||
def devenv(session: Session) -> None:
|
||||
|
|
|
|||
5
site.py
5
site.py
|
|
@ -1 +1,6 @@
|
|||
from os import environ
|
||||
|
||||
if "FROG_LOCALE_DIR" in environ:
|
||||
site.set_translations("site", environ["FROG_LOCALE_DIR"], languages=["fr"])
|
||||
|
||||
site.render('pages/index.html', 'index.html')
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
<div class="nav-bar--menu">
|
||||
<ul class="nav-bar--menu-section">
|
||||
<li class="nav-bar--menu-item">
|
||||
<a href="#" class="nav-bar--menu-link">Collective</a>
|
||||
<a href="#" class="nav-bar--menu-link">{{ gettext('Collective') }}</a>
|
||||
</li>
|
||||
<li class="nav-bar--menu-item">
|
||||
<a href="#" class="nav-bar--menu-link">Games</a>
|
||||
<a href="#" class="nav-bar--menu-link">{{ gettext('Games') }}</a>
|
||||
</li>
|
||||
<li class="nav-bar--menu-item">
|
||||
<a href="#" class="nav-bar--menu-link">News</a>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set title = "Games" %}
|
||||
{% set title = gettext("Games") %}
|
||||
{% set title_image = "/img/section-games.png" %}
|
||||
|
||||
{% extends "lib/section.html.j2" %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue