Skip to content

Commit

Permalink
Theme and i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
fle committed Feb 10, 2024
1 parent d70e5ec commit 97d4c80
Show file tree
Hide file tree
Showing 259 changed files with 20,632 additions and 13 deletions.
5 changes: 3 additions & 2 deletions content/0001_en_rgoods_tech_blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Date: 2024-02-09 08:00
Id: 0001
Slug: our-tech-blog
Lang: en
Translation: true
Save_as: index.html
Summary: We help associations and NGOs by offering them innovative ways to increase their donor base and boost their resources. We see the publication of this blog as a simple, constructive and natural way of participate in the community.


# Who are we?
Expand All @@ -17,7 +18,7 @@ A major part of our business involves the development of SaaS software. To carry
best possible tools.

Our customers are associations with a very strong social, medical and environmental impact, and we have a duty to
share their values. Our team and our products are therefore designed to be : **ethical, responsible, accessible
share their values. Our team and our products are therefore designed to be : **ethical, responsible,
inclusive and open**.

# Why publish a technical blog?
Expand Down
3 changes: 2 additions & 1 deletion content/0001_fr_rgoods_tech_blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Date: 2024-02-09 08:00
Id: 0001
Slug: notre-blog-tech
Lang: fr
Summary: Nous aidons les associations et les ONG en leur proposant des moyens innovants d'accroître leur base de donateurs et leurs ressources. Nous considérons la publication de ce blog comme un moyen simple, constructif et naturel de participer à la vie de la communauté.

# Qui sommes-nous ?

Expand All @@ -15,7 +16,7 @@ Un volet majeur de notre activité induit le développement de logiciels SaaS. P
constituons **une équipe technique expérimentée, passionnée et engagée** à fournir les meilleurs outils à nos clients.

Nos clients sont des associations à très fort impact sociétal, médical, environnemental et nous nous devons de
partager leurs valeurs. Notre équipe et nos réalisations se veulent donc : **éthiques, responsables, accessibles,
partager leurs valeurs. Notre équipe et nos réalisations se veulent donc : **éthiques, responsables,
inclusives et ouvertes**.

# Pourquoi publier un blog technique ?
Expand Down
Binary file added content/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 46 additions & 10 deletions pelicanconf.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
AUTHOR = 'RGOODS Tech team'
SITENAME = 'RGOODS Engineering'
#SITEURL = "https://engineering.rgoods.com"
SITESUBTITLE = (
'We are RGOODS tech team.<br />'
'We build cool tools to help associations & NGOs raise more funds.<br />'
'On this blog, we talk about Python/Django/Wagtail & VueJS.'
)
SITEURL = 'http://localhost:8000'

PATH = "content"

TIMEZONE = 'Europe/Paris'

ARTICLE_TRANSLATION_ID = 'id'
DEFAULT_LANG = 'fr'
LOCALE = 'fr_FR'

COPYRIGHT_NAME = 'RGOODS'

# Feed generation is usually not desired when developing
FEED_ALL_ATOM = None
Expand All @@ -20,20 +22,54 @@

# Blogroll
LINKS = (
("RGOODS", "https://rgoods.com/"),
("rgoods", "https://rgoods.com/"),
)

# Social widget
SOCIAL = (
("Instagram", "https://www.instagram.com/rgoods_official/"),
("Linkedin", "https://www.linkedin.com/company/rgoods/"),
("instagram", "https://www.instagram.com/rgoods_official/"),
("linkedin", "https://www.linkedin.com/company/rgoods/"),
('rss', '/feeds/all.atom.xml'),
)

DEFAULT_PAGINATION = False

DISPLAY_CATEGORIES_ON_MENU = False
MAIN_MENU = True
MENUITEMS = (('Archives', '/archives.html'),
('Categories', '/categories.html'),)

# Uncomment following line if you want document-relative URLs when developing
# RELATIVE_URLS = True

STATIC_PATHS = ['images']
EXTRA_PATH_METADATA = {'images/favicon.ico': {'path': 'favicon.ico'},}

THEME = "themes/Flex"

SITELOGO = "/images/logo.png"
FAVICON = "/images/favicon.ico"

PLUGIN_PATHS = ["plugins"]
PLUGINS = ["i18n_subsites"]

# Internationalisation
ARTICLE_TRANSLATION_ID = 'id'
DEFAULT_LANG = "en"
I18N_TEMPLATES_LANG = "en"
I18N_SUBSITES = {
'fr': {
'SITENAME': 'RGOODS Ingénierie',
'SITESUBTITLE': (
"Nous sommes l'équipe tech RGOODS.<br />"
"Nous construisons des outils cool pour aider les associations et les ONGs à récolter plus de fonds.<br />"
"Sur ce blog, nous parlons principalement de Python/Django/Wagtail & VueJS."
),
'MENUITEMS': (
('Archives', '/archives.html'),
('Catégories', '/categories.html'),
),
'DEFAULT_LANG': "fr"
}
}
JINJA_ENVIRONMENT = {
'extensions': ['jinja2.ext.i18n']
}
165 changes: 165 additions & 0 deletions plugins/i18n_subsites/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
=======================
I18N Sub-sites Plugin
=======================

This plugin extends the translations functionality by creating
internationalized sub-sites for the default site.

This plugin is designed for Pelican 3.4 and later.

What it does
============

1. When the content of the main site is being generated, the settings
are saved and the generation stops when content is ready to be
written. While reading source files and generating content objects,
the output queue is modified in certain ways:

- translations that will appear as native in a different (sub-)site
will be removed
- untranslated articles will be transformed to drafts if
``I18N_UNTRANSLATED_ARTICLES`` is ``'hide'`` (default), removed if
``'remove'`` or kept as they are if ``'keep'``.
- untranslated pages will be transformed into hidden pages if
``I18N_UNTRANSLATED_PAGES`` is ``'hide'`` (default), removed if
``'remove'`` or kept as they are if ``'keep'``.''
- additional content manipulation similar to articles and pages can
be specified for custom generators in the ``I18N_GENERATOR_INFO``
setting.

2. For each language specified in the ``I18N_SUBSITES`` dictionary the
settings overrides are applied to the settings from the main site
and a new sub-site is generated in the same way as with the main
site until content is ready to be written.
3. When all (sub-)sites are waiting for content writing, all removed
contents, translations and static files are interlinked across the
(sub-)sites.
4. Finally, all the output is written.

Setting it up
=============

For each extra used language code, a language-specific settings overrides
dictionary must be given (but can be empty) in the ``I18N_SUBSITES`` dictionary

.. code-block:: python
PLUGINS = ['i18n_subsites', ...]
# mapping: language_code -> settings_overrides_dict
I18N_SUBSITES = {
'cz': {
'SITENAME': 'Hezkej blog',
}
}
You must also have the following in your pelican configuration

.. code-block:: python
JINJA_ENVIRONMENT = {
'extensions': ['jinja2.ext.i18n'],
}
Default and special overrides
-----------------------------
The settings overrides may contain arbitrary settings, however, there
are some that are handled in a special way:

``SITEURL``
Any overrides to this setting should ensure that there is some level
of hierarchy between all (sub-)sites, because Pelican makes all URLs
relative to ``SITEURL`` and the plugin can only cross-link between
the sites using this hierarchy. For instance, with the main site
``http://example.com`` a sub-site ``http://example.com/de`` will
work, but ``http://de.example.com`` will not. If not overridden, the
language code (the language identifier used in the ``lang``
metadata) is appended to the main ``SITEURL`` for each sub-site.
``OUTPUT_PATH``, ``CACHE_PATH``
If not overridden, the language code is appended as with ``SITEURL``.
Separate cache paths are required as parser results depend on the locale.
``STATIC_PATHS``, ``THEME_STATIC_PATHS``
If not overridden, they are set to ``[]`` and all links to static
files are cross-linked to the main site.
``THEME``, ``THEME_STATIC_DIR``
If overridden, the logic with ``THEME_STATIC_PATHS`` does not apply.
``DEFAULT_LANG``
This should not be overridden as the plugin changes it to the
language code of each sub-site to change what is perceived as translations.

Localizing templates
--------------------

Most importantly, this plugin can use localized templates for each
sub-site. There are two approaches to having the templates localized:

- You can set a different ``THEME`` override for each language in
``I18N_SUBSITES``, e.g. by making a copy of a theme ``my_theme`` to
``my_theme_lang`` and then editing the templates in the new
localized theme. This approach means you don't have to deal with
gettext ``*.po`` files, but it is harder to maintain over time.
- You use only one theme and localize the templates using the
`jinja2.ext.i18n Jinja2 extension
<http://jinja.pocoo.org/docs/templates/#i18n>`_. For a kickstart
read this `guide <./localizing_using_jinja2.rst>`_.

Additional context variables
............................

It may be convenient to add language buttons to your theme in addition
to the translation links of articles and pages. These buttons could,
for example, point to the ``SITEURL`` of each (sub-)site. For this
reason the plugin adds these variables to the template context:

``main_lang``
The language of the main site — the original ``DEFAULT_LANG``
``main_siteurl``
The ``SITEURL`` of the main site — the original ``SITEURL``
``lang_siteurls``
An ordered dictionary, mapping all used languages to their
``SITEURL``. The ``main_lang`` is the first key with ``main_siteurl``
as the value. This dictionary is useful for implementing global
language buttons that show the language of the currently viewed
(sub-)site too.
``extra_siteurls``
An ordered dictionary, subset of ``lang_siteurls``, the current
``DEFAULT_LANG`` of the rendered (sub-)site is not included, so for
each (sub-)site ``set(extra_siteurls) == set(lang_siteurls) -
set([DEFAULT_LANG])``. This dictionary is useful for implementing
global language buttons that do not show the current language.
``relpath_to_site``
A function that returns a relative path from the first (sub-)site to
the second (sub-)site where the (sub-)sites are identified by the
language codes given as two arguments.

If you don't like the default ordering of the ordered dictionaries,
use a Jinja2 filter to alter the ordering.

All the siteurls above are always absolute even in the case of
``RELATIVE_URLS == True`` (it would be to complicated to replicate the
Pelican internals for local siteurls), so you may rather use something
like ``{{ SITEURL }}/{{ relpath_to_site(DEFAULT_LANG, main_lang }}``
to link to the main site.

This short `howto <./implementing_language_buttons.rst>`_ shows two
example implementations of language buttons.

Usage notes
===========
- It is **mandatory** to specify ``lang`` metadata for each article
and page as ``DEFAULT_LANG`` is later changed for each sub-site, so
content without ``lang`` metadata would be rendered in every
(sub-)site.
- As with the original translations functionality, ``slug`` metadata
is used to group translations. It is therefore often convenient to
compensate for this by overriding the content URL (which defaults to
slug) using the ``url`` and ``save_as`` metadata. You could also
give articles e.g. ``name`` metadata and use it in ``ARTICLE_URL =
'{name}.html'``.

Development
===========

- A demo and a test site is in the ``gh-pages`` branch and can be seen
at http://smartass101.github.io/pelican-plugins/
1 change: 1 addition & 0 deletions plugins/i18n_subsites/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .i18n_subsites import *
Loading

0 comments on commit 97d4c80

Please sign in to comment.