aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/i18n_subsites/i18n_subsites.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/i18n_subsites/i18n_subsites.py')
-rw-r--r--plugins/i18n_subsites/i18n_subsites.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/plugins/i18n_subsites/i18n_subsites.py b/plugins/i18n_subsites/i18n_subsites.py
index dc27799..18481dd 100644
--- a/plugins/i18n_subsites/i18n_subsites.py
+++ b/plugins/i18n_subsites/i18n_subsites.py
@@ -32,16 +32,16 @@ except ImportError:
# Global vars
-_MAIN_SETTINGS = None # settings dict of the main Pelican instance
-_MAIN_LANG = None # lang of the main Pelican instance
-_MAIN_SITEURL = None # siteurl of the main Pelican instance
-_MAIN_STATIC_FILES = None # list of Static instances the main Pelican instance
-_SUBSITE_QUEUE = {} # map: lang -> settings overrides
-_SITE_DB = OrderedDict() # OrderedDict: lang -> siteurl
+_MAIN_SETTINGS = None # settings dict of the main Pelican instance
+_MAIN_LANG = None # lang of the main Pelican instance
+_MAIN_SITEURL = None # siteurl of the main Pelican instance
+_MAIN_STATIC_FILES = None # list of Static instances the main Pelican
+_SUBSITE_QUEUE = {} # map: lang -> settings overrides
+_SITE_DB = OrderedDict() # OrderedDict: lang -> siteurl
_SITES_RELPATH_DB = {} # map: (lang, base_lang) -> relpath
# map: generator -> list of removed contents that need interlinking
_GENERATOR_DB = {}
-_NATIVE_CONTENT_URL_DB = {} # map: source_path -> content in its native lang
+_NATIVE_CONTENT_URL_DB = {} # map: source_path -> content in its native lang
_LOGGER = logging.getLogger(__name__)
@@ -254,12 +254,16 @@ def filter_contents_translations(generator):
hiding_func = inspector.hiding_function()
untrans_policy = inspector.untranslated_policy(default='hide')
for (contents, other_contents) in inspector.contents_list_pairs():
- for content in other_contents: # save any hidden native content first
- if content.lang == current_lang: # in native lang
+ # save any hidden native content first
+ for content in other_contents:
+ # in native lang
+ if content.lang == current_lang:
# save the native URL attr formatted in the current locale
_NATIVE_CONTENT_URL_DB[content.source_path] = content.url
- for content in contents[:]: # copy for removing in loop
- if content.lang == current_lang: # in native lang
+ # copy for removing in loop
+ for content in contents[:]:
+ # in native lang
+ if content.lang == current_lang:
# save the native URL attr formatted in the current locale
_NATIVE_CONTENT_URL_DB[content.source_path] = content.url
elif content.lang in langs_with_sites and untrans_policy != 'keep':
@@ -276,7 +280,8 @@ def install_templates_translations(generator):
Only if the 'jinja2.ext.i18n' jinja2 extension is enabled
the translations for the current DEFAULT_LANG are installed.
'''
- if 'JINJA_ENVIRONMENT' in generator.settings: # pelican 3.7+
+ # pelican 3.7+
+ if 'JINJA_ENVIRONMENT' in generator.settings:
jinja_extensions = generator.settings['JINJA_ENVIRONMENT'].get(
'extensions', [])
else:
@@ -357,16 +362,19 @@ def interlink_removed_content(generator):
def interlink_static_files(generator):
'''Add links to static files in the main site if necessary'''
+ # customized STATIC_PATHS
if generator.settings['STATIC_PATHS'] != []:
- return # customized STATIC_PATHS
- try: # minimize attr lookup
+ return
+ # minimize attr lookup
+ try:
static_content = generator.context['static_content']
except KeyError:
static_content = generator.context['filenames']
relpath = relpath_to_site(generator.settings['DEFAULT_LANG'], _MAIN_LANG)
for staticfile in _MAIN_STATIC_FILES:
if staticfile.get_relative_source_path() not in static_content:
- staticfile = copy(staticfile) # prevent override in main site
+ # prevent override in main site
+ staticfile = copy(staticfile)
staticfile.override_url = posixpath.join(relpath, staticfile.url)
try:
generator.add_source_path(staticfile, static=True)