Last active
December 16, 2015 11:54
-
-
Save mothsART/bad41fcdae8154a98d71 to your computer and use it in GitHub Desktop.
i18n site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLUGINS = [ | |
'i18n_subsites', | |
] | |
# i18n | |
JINJA_EXTENSIONS = ['jinja2.ext.i18n'] | |
I18N_GETTEXT_LOCALEDIR = 'themes/lab/translations' | |
DEFAULT_LANG = 'fr' | |
# define "I18N_SUBSITES" as a empty dictionary doesn't really matters : it's initialized on i18n_subsites.py on line 65 | |
# I18N_SUBSITES = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gettext | |
from pelican import signals | |
_GENERATOR_DB = {} | |
def init_generator(generator): | |
_GENERATOR_DB[generator] = [] | |
def translate(pelican_obj): | |
for generator in _GENERATOR_DB.keys(): | |
if 'jinja2.ext.i18n' in generator.settings['JINJA_EXTENSIONS']: | |
domain = generator.settings.get('I18N_GETTEXT_DOMAIN', 'messages') | |
localedir = generator.settings.get('I18N_GETTEXT_LOCALEDIR') | |
langs = [generator.settings.get('DEFAULT_LANG')] | |
try: | |
translations = gettext.translation(domain, localedir, langs) | |
except (IOError, OSError): | |
translations = gettext.NullTranslations() | |
generator.env.install_gettext_translations(translations, True) | |
def register(): | |
signals.generator_init.connect(init_generator) | |
signals.get_writer.connect(translate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment