getpelican / pelican-plugins

Collection of plugins for the Pelican static site generator
Other
1.38k stars 849 forks source link

[i18n_subsites] Allow merging the base settings with the translations settings. #1350

Open adiroiban opened 3 years ago

adiroiban commented 3 years ago

To help organize the translations any text from pelicanconf.py that is presented on the site is put in a common dictionary

The idea is that if you add a new value in the default site and that site is not translated, it will be present in the translated site using the default language....similar to gettext.


Instead of using a simple copy with overwriting of root dict keys I went with a simple dict merge code.

I have simplified the tests.

to run the tests

virtualenv venv
. venv/bin/activate
pip install pelican
python -m unittest i18n_subsites/test_i18n_subsites.py

An example

L10N = {
    'author': 'Pro:Atria Team',
    'company': 'Pro:Atria Ltd',
    'company_number': '4213930',
    'product': 'SFTPPlus',
    'email': {
        'contact': 'contact@proatria.com',
        'sales': 'sales@proatria.com',
        'support': 'support@proatria.com',
        },
    'menu': [
        # Text, URL, category.
        ('Product', '/product/', 'product'),
        ('Support', '/support/', 'support'),
        ('Contact', '/about/contact.html', 'contact'),
        ],
    }

I18N_SUBSITES = { 'de': 'L10N': {
    'company': 'Pro:Atria Ag',
    # The other emails are kept as in the main site.
    'email': {'sale': 'sales@proatria.de'},
    'menu': [
        # Text, URL, category.
        ('Produkt', '/de/product/', 'product'),
        ('Support', '/de/support/', 'support'),
        ('Kontakt', '/de/about/contact.html', 'contact'),
        ],
}}
adiroiban commented 3 years ago

I also have a patch to translate the values from pelicanconf.py using gettext.

But I think that this patch is still valid for people who don't want to use gettext

georgkrause commented 2 years ago

@adiroiban Mind filing the same against my fork at https://github.com/georgkrause/i18n_subsites ?