Skip to content
Snippets Groups Projects
Select Git revision
  • f25e9a68d91a14fc5d7100bef6ad31544d141b02
  • master default
  • prez
3 results

README.rst

Blame
  • user avatar
    mazenovi authored
    4b8abd04
    History
    README.rst 6.49 KiB

    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.
    1. 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.
    2. When all (sub-)sites are waiting for content writing, all removed contents, translations and static files are interlinked across the (sub-)sites.
    3. 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

    PLUGINS = ['i18n_subsites', ...]
    
    # mapping: language_code -> settings_overrides_dict
    I18N_SUBSITES = {
        'cz': {
            'SITENAME': 'Hezkej blog',
            }
        }

    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. For a kickstart read this guide.