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.py53
1 files changed, 30 insertions, 23 deletions
diff --git a/plugins/i18n_subsites/i18n_subsites.py b/plugins/i18n_subsites/i18n_subsites.py
index dc27799..33cfaab 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
-_SITES_RELPATH_DB = {} # map: (lang, base_lang) -> relpath
+_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__)
@@ -81,30 +81,37 @@ def prepare_site_db_and_overrides():
_SITE_DB.keys() need to be ready for filter_translations
'''
+
_SITE_DB.clear()
_SITE_DB[_MAIN_LANG] = _MAIN_SITEURL
+
# make sure it works for both root-relative and absolute
- main_siteurl = '/' if _MAIN_SITEURL == '' else _MAIN_SITEURL
- for lang, overrides in _SUBSITE_QUEUE.items():
+
+ main_siteurl = ('/' if _MAIN_SITEURL == '' else _MAIN_SITEURL)
+ for (lang, overrides) in _SUBSITE_QUEUE.items():
if 'SITEURL' not in overrides:
overrides['SITEURL'] = posixpath.join(main_siteurl, lang)
_SITE_DB[lang] = overrides['SITEURL']
+
# default subsite hierarchy
+
if 'OUTPUT_PATH' not in overrides:
- overrides['OUTPUT_PATH'] = os.path.join(
- _MAIN_SETTINGS['OUTPUT_PATH'], lang)
+ overrides['OUTPUT_PATH'] = \
+ os.path.join(_MAIN_SETTINGS['OUTPUT_PATH'], lang)
if 'CACHE_PATH' not in overrides:
- overrides['CACHE_PATH'] = os.path.join(
- _MAIN_SETTINGS['CACHE_PATH'], lang)
+ overrides['CACHE_PATH'] = \
+ os.path.join(_MAIN_SETTINGS['CACHE_PATH'], lang)
if 'STATIC_PATHS' not in overrides:
overrides['STATIC_PATHS'] = []
- if ('THEME' not in overrides and 'THEME_STATIC_DIR' not in overrides and
- 'THEME_STATIC_PATHS' not in overrides):
+ if 'THEME' not in overrides and 'THEME_STATIC_DIR' \
+ not in overrides and 'THEME_STATIC_PATHS' not in overrides:
relpath = relpath_to_site(lang, _MAIN_LANG)
overrides['THEME_STATIC_DIR'] = posixpath.join(
relpath, _MAIN_SETTINGS['THEME_STATIC_DIR'])
overrides['THEME_STATIC_PATHS'] = []
+
# to change what is perceived as translations
+
overrides['DEFAULT_LANG'] = lang
@@ -254,12 +261,12 @@ 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
+ for content in other_contents: # save any hidden native content first
+ if content.lang == current_lang: # in native 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
+ for content in contents[:]: # copy for removing in loop
+ if content.lang == current_lang: # in native 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 +283,7 @@ 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+
+ if 'JINJA_ENVIRONMENT' in generator.settings: # pelican 3.7+
jinja_extensions = generator.settings['JINJA_ENVIRONMENT'].get(
'extensions', [])
else:
@@ -359,14 +366,14 @@ def interlink_static_files(generator):
'''Add links to static files in the main site if necessary'''
if generator.settings['STATIC_PATHS'] != []:
return # customized STATIC_PATHS
- try: # minimize attr lookup
+ try: # minimize attr lookup
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
+ staticfile = copy(staticfile) # prevent override in main site
staticfile.override_url = posixpath.join(relpath, staticfile.url)
try:
generator.add_source_path(staticfile, static=True)