Важное изменение в настройках для переводов

This commit is contained in:
Andrei Astafev 2020-04-12 17:08:45 +03:00
parent ac5e2dd88e
commit 002213aa87
3 changed files with 14 additions and 64 deletions

View File

@ -1,8 +1,8 @@
build: build:
pelican --ignore-cache -s pelicanconf.py pelican -s pelicanconf.py
web: web:
pelican --ignore-cache -s pelicanconf-web.py pelican -s pelicanconf-web.py
clean: clean:
rm -rf cache __pycache__ rm -rf cache __pycache__

View File

@ -2,33 +2,6 @@
# -*- coding: utf-8 -*- # # -*- coding: utf-8 -*- #
import os import os
class i18n(object):
# looks for translations in
# {LOCALE_DIR}/{LANGUAGE}/LC_MESSAGES/{DOMAIN}.mo
# if not present, falls back to default
DOMAIN = 'messages'
LOCALE_DIR = '{THEME}/translations'
LANGUAGES = ['ru']
NEWSTYLE = True
__name__ = 'i18n'
def register(self):
from pelican.signals import generator_init
generator_init.connect(self.install_translator)
def install_translator(self, generator):
import gettext
try:
translator = gettext.translation(
self.DOMAIN,
self.LOCALE_DIR.format(THEME=THEME),
self.LANGUAGES)
except (OSError, IOError):
translator = gettext.NullTranslations()
generator.env.install_gettext_translations(translator, self.NEWSTYLE)
# ABOUT_ME = ' ' # ABOUT_ME = ' '
AUTHOR = 'Андрей Астафьев' AUTHOR = 'Андрей Астафьев'
SITENAME = 'ДСП' SITENAME = 'ДСП'
@ -67,14 +40,16 @@ DISPLAY_TAGS_ON_SIDEBAR = True
THEME = 'themes/bootstrap4' THEME = 'themes/bootstrap4'
BOOTSTRAP_THEME = 'litera' BOOTSTRAP_THEME = 'litera'
I18N_TEMPLATES_LANG = 'ru' # I18N_GETTEXT_LOCALEDIR = 'translations'
# I18N_GETTEXT_DOMAIN = 'messages'
# Обязательно в виде массива
I18N_TEMPLATES_LANG = ['ru']
I18N_GETTEXT_NEWSTYLE = True I18N_GETTEXT_NEWSTYLE = True
I18N_GETTEXT_LOCALEDIR = 'themes/bootstrap4/translations'
I18N_GETTEXT_DOMAIN = 'messages'
JINJA_ENVIRONMENT = {'extensions': ['jinja2.ext.i18n']} JINJA_ENVIRONMENT = {'extensions': ['jinja2.ext.i18n']}
PLUGIN_PATHS = ["plugins/official", "plugins/thirdparty"] PLUGIN_PATHS = ["plugins/official", "plugins/thirdparty"]
PLUGINS = [i18n(), "pelican-css", "series", "subcategory", "tag_cloud", "tipue_search", "replacer", "asciidoctor"] PLUGINS = ["i18n_subsites", "pelican-css", "series", "subcategory", "tag_cloud", "tipue_search", "replacer", "asciidoctor"]
ASCIIDOCTOR_CMD = "asciidoctor" ASCIIDOCTOR_CMD = "asciidoctor"

View File

@ -2,33 +2,6 @@
# -*- coding: utf-8 -*- # # -*- coding: utf-8 -*- #
import os import os
class i18n(object):
# looks for translations in
# {LOCALE_DIR}/{LANGUAGE}/LC_MESSAGES/{DOMAIN}.mo
# if not present, falls back to default
DOMAIN = 'messages'
LOCALE_DIR = '{THEME}/translations'
LANGUAGES = ['ru']
NEWSTYLE = True
__name__ = 'pelicanconf.i18n'
def register(self):
from pelican.signals import generator_init
generator_init.connect(self.install_translator)
def install_translator(self, generator):
import gettext
try:
translator = gettext.translation(
self.DOMAIN,
self.LOCALE_DIR.format(THEME=THEME),
self.LANGUAGES)
except (OSError, IOError):
translator = gettext.NullTranslations()
generator.env.install_gettext_translations(translator, self.NEWSTYLE)
# ABOUT_ME = ' ' # ABOUT_ME = ' '
AUTHOR = 'Андрей Астафьев' AUTHOR = 'Андрей Астафьев'
SITENAME = 'ДСП' SITENAME = 'ДСП'
@ -67,14 +40,16 @@ DISPLAY_TAGS_ON_SIDEBAR = True
THEME = 'themes/bootstrap4' THEME = 'themes/bootstrap4'
BOOTSTRAP_THEME = 'litera' BOOTSTRAP_THEME = 'litera'
I18N_TEMPLATES_LANG = 'ru' # I18N_GETTEXT_LOCALEDIR = 'translations'
# I18N_GETTEXT_DOMAIN = 'messages'
# Обязательно в виде массива
I18N_TEMPLATES_LANG = ['ru']
I18N_GETTEXT_NEWSTYLE = True I18N_GETTEXT_NEWSTYLE = True
I18N_GETTEXT_LOCALEDIR = 'themes/bootstrap4/translations'
I18N_GETTEXT_DOMAIN = 'messages'
JINJA_ENVIRONMENT = {'extensions': ['jinja2.ext.i18n']} JINJA_ENVIRONMENT = {'extensions': ['jinja2.ext.i18n']}
PLUGIN_PATHS = ["plugins/official", "plugins/thirdparty"] PLUGIN_PATHS = ["plugins/official", "plugins/thirdparty"]
PLUGINS = [i18n(), "pelican-css", "series", "subcategory", "tag_cloud", "tipue_search", "replacer", "asciidoctor"] PLUGINS = ["i18n_subsites", "pelican-css", "series", "subcategory", "tag_cloud", "tipue_search", "replacer", "asciidoctor"]
ASCIIDOCTOR_CMD = "asciidoctor" ASCIIDOCTOR_CMD = "asciidoctor"