Browse Source

add multi language

master
Schoenberger, Philipp 6 years ago
parent
commit
4f13a20f5b
  1. 2
      Makefile
  2. 1
      content/blog/01_new_page_de.md
  3. BIN
      content/images_org/de.jpg
  4. BIN
      content/images_org/en.jpg
  5. 0
      content/pages/about_de.md
  6. 27
      content/pages/gallery/index_de.md
  7. 15
      content/pages/gallery/index_en.md
  8. 1
      content/pages/impressum_de.md
  9. 3
      content/pages/index_de.md
  10. 20
      content/pages/index_en.md
  11. 1
      content/pages/projects/01_3d_printer.md
  12. 3
      content/pages/projects/projects.md
  13. 49
      pelicanconf.py
  14. 8
      plugins/i18n_subsites/i18n_subsites.py
  15. 43
      plugins/lightgallery/lightgallery.py
  16. 33
      themes/minimal/static/css/lang.css
  17. 13
      themes/minimal/templates/base.html

2
Makefile

@ -99,8 +99,6 @@ $(IMAGE_DIR)%.jpg: $(IMAGE_ORG_DIR)%.jpg
mkdir -p $(dir $@)
cp $< $@
#$(call convert-img-rule, $(IMAGE_ORG_DIR)/gallery/IMG_3184.jpg )
img-clean:
rm $(IMAGE_DIR) -rf

1
content/blog/01_new_page_de.md

@ -3,6 +3,7 @@ date: 2019-05-22
tags: pelican, html, lightbox
category: web
lang: de
slug: web
author: Philipp Schönberer
summary: I didched wordpress and moved on.

BIN
content/images_org/de.jpg

After

Width: 34  |  Height: 20  |  Size: 539 B

BIN
content/images_org/en.jpg

After

Width: 34  |  Height: 20  |  Size: 1.4 KiB

0
content/pages/about.md → content/pages/about_de.md

27
content/pages/gallery/index_de.md

@ -0,0 +1,27 @@
title: Gallery
author: Philipp Schönberger
url: gallery/index.html
save_as: gallery/index.html
lang: en
template: page
Here you find latest pictures i am willing to share. Enjoy the views.
[lightgallery
/images/gallery/IMG_3184.jpg, neighbour cat ;
/images/gallery/IMG_3364.jpg, red-tailed bumblebee at a cornflower ;
/images/gallery/IMG_3386.jpg, garden bumblebee at a cornflower ;
/images/gallery/IMG_3414.jpg, garden bumblebee at a cornflower ;
/images/gallery/IMG_3477.jpg ;
/images/gallery/IMG_3483.jpg, thistle ;
/images/gallery/IMG_3559.jpg, carolina rose ;
/images/gallery/IMG_8722.jpg, hotel in south denmark ;
/images/gallery/IMG_9037.jpg, sailingboat of the fisherman ;
/images/gallery/IMG_9097.jpg, sailingboat ;
/images/gallery/IMG_9136.jpg, sunrise in Denmark ;
/images/gallery/IMG_9137.jpg, sunrise in Denmark ;
/images/gallery/IMG_9393.jpg, harbour of grömitz at night;
lightgalleryend]
this is some gallery:

15
content/pages/gallery/index.md → content/pages/gallery/index_en.md

@ -2,25 +2,26 @@ title: Gallery
author: Philipp Schönberger
url: gallery/index.html
save_as: gallery/index.html
lang: de
template: page
Here you find latest pictures i am willing to share. Enjoy the views.
[lightgallery
/images/gallery/IMG_3184.jpg, Neighbour cat ;
/images/gallery/IMG_3184.jpg, Nachbarskatze ;
/images/gallery/IMG_3364.jpg, Steinhummel an der Kornblume ;
/images/gallery/IMG_3386.jpg, Gartenhummel an der Kornblume ;
/images/gallery/IMG_3414.jpg, Gartenhummel an der Kornblume ;
/images/gallery/IMG_3477.jpg ;
/images/gallery/IMG_3483.jpg, Distel ;
/images/gallery/IMG_3559.jpg, Windrose in Blüte ;
/images/gallery/IMG_3559.jpg, Wiesenrose in Blüte ;
/images/gallery/IMG_8722.jpg, Dänische Südseehaus ;
/images/gallery/IMG_9037.jpg, Fisherman Sailingboat ;
/images/gallery/IMG_9097.jpg, Sailingboat ;
/images/gallery/IMG_9136.jpg, Sunrise in Denmark ;
/images/gallery/IMG_9137.jpg, Sunrise in Denmark ;
/images/gallery/IMG_9393.jpg, Harbour Grömitz at night;
/images/gallery/IMG_9037.jpg, Segelboot vom Fischer ;
/images/gallery/IMG_9097.jpg, Segelboot ;
/images/gallery/IMG_9136.jpg, Sonnenaufgang in Dänemark ;
/images/gallery/IMG_9137.jpg, Sonnenaufgang in Dänemark ;
/images/gallery/IMG_9393.jpg, Grömitzer Hafen bei Nacht ;
lightgalleryend]
this is some gallery:

1
content/pages/impressum.md → content/pages/impressum_de.md

@ -1,6 +1,7 @@
title: Impressum
authors: Philipp Schönberger
url: impressum.html
lang: de
save_as: impressum.html
Haftungsausschluss (Disclaimer)

3
content/pages/index.md → content/pages/index_de.md

@ -1,7 +1,6 @@
title: home
author: Philipp Schönberger
url: index.html
save_as: index.html
lang: de
template: page
Welcome to my webpage.

20
content/pages/index_en.md

@ -0,0 +1,20 @@
title: home
author: Philipp Schönberger
lang: en
template: page
Welcome to my webpage.
It contains things I work or worked on and lot of other things I had fun with.
I’m Philipp Schönberger born in in Zeitz(Germany) within the 1988.
In Constance I made my bachelor degree within ‘computer engineering‘.
Afterwards I absolved my master degree within the ‘robotics and intelligent embedded systems‘ in Lübeck.
Currently I am employed as software engineer/architect for a satellite aided router in Germany near the Lake Constance.
Enjoy your stay.
## Contact ##
* Email: mail@phschoen.de
* Address: Check the WHOIS record.

1
content/pages/projects/01_3d_printer.md

@ -1,7 +1,6 @@
title: Projects
date: 2019-05-20
author: Philipp Schönberger
slug: 3d_printer_en
template: page
category: projects
url: projects/01_3d_printer.html

3
content/pages/projects/projects.md

@ -1,11 +1,12 @@
title: Projects
date: 2019-05-20
author: Philipp Schönberger
slug: projects
template: projects
category: projects
url: projects/index.html
save_as: projects/index.html
Here you can view the latest projects i've started.
This page contains tutorials, rough drafts I work on. The articles in here aren't necessarily finished and some of them aren't open to discussion, because they are work in progress (or chaos). Some of them <em>might</em> be turned into self-contained blog posts, some of them will never get out of this dungeon.

49
pelicanconf.py

@ -8,7 +8,7 @@ from operator import itemgetter, methodcaller
AUTHOR = 'Philipp Schönberger'
EMAIL = 'mail AT phschoen.de'
SITENAME = 'https://phschoen.de'
OUTPUT_PATH = 'output/DEV/'
OUTPUT_PATH = 'output/'
# Base URL this page is hosted at:
SITENAME = 'phschoen.de'
@ -27,11 +27,21 @@ DATE_FORMATS = {
LOCALE = ('usa', 'de', # On Windows
'en_US', 'de_DE' # On Unix/Linux
)
ARTICLE_URL = 'blog/{slug}'
ARTICLE_SAVE_AS = 'blog/{slug}/index.html'
ARTICLE_LANG_URL = '{lang}/blog/{slug}'
ARTICLE_LANG_SAVE_AS = '{lang}/blog/{slug}.html'
PAGE_URL = '{slug}'
PAGE_SAVE_AS = '{slug}/index.html'
PAGE_LANG_URL = '{lang}/{slug}'
PAGE_LANG_SAVE_AS = '{lang}/{slug}/index.html'
LOCALE = 'en_US'
# We are using the custom minimal theme:
THEME = 'themes/minimal'
# THEME = 'themes/pelican-chunk'
#THEME = 'themes/pelican-themes/bootstrap4-standard'
THEME_STATIC_DIR = 'theme'
DELETE_OUTPUT_DIRECTORY = True
# MARKUP = ('md',)
@ -118,29 +128,35 @@ DEFAULT_CATEGORY = 'uncategorized'
PLUGIN_PATHS = ['plugins', ]
PLUGINS = ['lightgallery', 'i18n_subsites']
# PLUGIN_PATHS = ['./pelican-plugins/', ]
# PLUGINS = ['i18n_subsites', ]
# JINJA_ENVIRONMENT = {
# 'extensions': ['jinja2.ext.i18n'],
# }
GITHUB_SOURCE_PATH = "wooot"
I18N_SUBSITES = {'en': {'SITENAME': 'phschoen.com',
},
I18N_SUBSITES = {
'de': {'SITENAME': 'phschoen.de',
'THEME_STATIC_DIR': 'theme',
'OUTPUT_PATH': './output/de',
},
'en': {'SITENAME': 'phschoen.com',
'SITEURL': SITEURL,
'THEME_STATIC_DIR': 'theme',
'OUTPUT_PATH': './output/',
},
}
languages_lookup = {'en': 'English',
'de': 'Deutsch',
languages_lookup = {'en': {'name': 'English',
'icon': SITEURL+'/images/en.jpg'
},
'de': {'name': 'Deutsch',
'icon': SITEURL+'/images/de.jpg'
},
}
def lookup_lang_ico(lang_code):
return languages_lookup[lang_code]['icon']
def lookup_lang_name(lang_code):
return languages_lookup[lang_code]
return languages_lookup[lang_code]['name']
def getGitHubPage(source_file):
@ -149,11 +165,11 @@ def getGitHubPage(source_file):
def getBasename(path):
return "name "
return ntpath.basename(path)
def month_name(month_number):
return "month_name"
return calendar.month_name[month_number]
def sortTupleByIndex(items, index=0, reverse=True):
@ -172,4 +188,5 @@ JINJA_FILTERS = {'month_name': month_name,
'basename': getBasename,
'asGitHubPage': getGitHubPage,
'lookup_lang_name': lookup_lang_name,
'lookup_lang_ico': lookup_lang_ico,
}

8
plugins/i18n_subsites/i18n_subsites.py

@ -35,7 +35,7 @@ except ImportError:
_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
_MAIN_STATIC_FILES = [] # 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
@ -372,6 +372,10 @@ def interlink_static_files(generator):
generator.add_source_path(staticfile, static=True)
except TypeError:
generator.add_source_path(staticfile)
else:
generator.add_source_path(staticfile, static=True)
staticfile.override_url = posixpath.join(relpath, staticfile.url)
print (staticfile.get_relative_source_path())
def save_main_static_files(static_generator):
@ -379,7 +383,7 @@ def save_main_static_files(static_generator):
global _MAIN_STATIC_FILES
# test just for current lang as settings change in autoreload mode
if static_generator.settings['DEFAULT_LANG'] == _MAIN_LANG:
_MAIN_STATIC_FILES = static_generator.staticfiles
_MAIN_STATIC_FILES.extend(static_generator.staticfiles)
def update_generators():

43
plugins/lightgallery/lightgallery.py

@ -8,8 +8,7 @@ from pathlib import Path
logger = logging.getLogger(__name__)
IMAGE_PATH = './content/'
IMAGE_SIZES = [200, 375, 480, 800, 1600]
_MAIN_SETTINGS = None # settings dict of the main Pelican instance
def process_content(article):
@ -39,6 +38,7 @@ def process_content(article):
img_url = cont[0].strip()
if img_url == "":
continue
img_url = img_url
img_text = ""
if (len(cont) > 1):
@ -51,22 +51,21 @@ def process_content(article):
imgs_text += "class=\"col-xs-6 col-sm-4 col-md-3\" "
imgs_text += "data-responsive=\""
for i in IMAGE_SIZES[1:-1]:
new_url = "" + str(Path(img_url).parent) + "/" + str(i) + "/" + str(Path(img_url).name)
logger.info("t\'" + new_url + "\n")
# create_scaled_image(IMAGE_PATH + img_url, IMAGE_PATH + new_url, i)
imgs_text += "" + new_url + ", "
for i in [375, 480, 800, 1600]:
imgs_text += "" + _MAIN_SETTINGS['SITEURL'] + str(Path(img_url).parent)
imgs_text += "/" + str(i) + "/" + str(Path(img_url).name)
imgs_text += " " + str(i) + ", "
imgs_text += "\" "
imgs_text += "data-src=\""
imgs_text += img_url
imgs_text += _MAIN_SETTINGS['SITEURL'] + img_url
imgs_text += "\" "
imgs_text += "data-sub-html=\""
imgs_text += img_text
imgs_text += "<p>"
imgs_text += create_exif_print(IMAGE_PATH + img_url)
imgs_text += create_exif_print("./content/" + img_url)
imgs_text += "</p>"
imgs_text += "\"> "
@ -200,8 +199,8 @@ def create_exif_print(img_path):
ret += "/" + str(exif[33434][1])
ret += "sec "
if 34850 in exif:
ret += " <bolt>" + programm_dic[exif[34850]] + "</bolt>"
# if 34850 in exif:
# ret += " <bolt>" + programm_dic[exif[34850]] + "</bolt>"
if 315 in exif:
ret += " " + exif[315]
@ -211,7 +210,27 @@ def create_exif_print(img_path):
return ret
except ValueError:
return ""
def initialize_plugin(pelican_obj):
'''Initialize plugin variables and Pelican settings'''
global _MAIN_SETTINGS
if _MAIN_SETTINGS is None:
_MAIN_SETTINGS = pelican_obj.settings
_SIGNAL_HANDLERS_DB = {
'get_generators': initialize_plugin,
'all_generators_finalized': add_gallery,
}
def register():
signals.all_generators_finalized.connect(add_gallery)
for sig_name in _SIGNAL_HANDLERS_DB.keys():
if not hasattr(signals, sig_name):
logger.error((
'The i18n_subsites plugin requires the {} '
'signal available for sure in Pelican 3.4.0 and later, '
'plugin will not be used.').format(sig_name))
return
for sig_name, handler in _SIGNAL_HANDLERS_DB.items():
sig = getattr(signals, sig_name)
sig.connect(handler)

33
themes/minimal/static/css/lang.css

@ -0,0 +1,33 @@
.langmenu > .active {
opacity: 1;
}
.langmenu > .passive {
opacity: 0.5;
}
.langmenu > a:hover {
opacity: 1;
}
.langmenu > a > img {
height:25px;
width: 30px;
}
.langmenu > a {
height:25px;
width: 100px;
}
.langmenu {
width: 120px;
height: 40px;
/* margin-top: 10px; */
/* text-align: left; */
/* position: absolute; */
/* left: 100%; */
/* top: 0; */
/* left: 0%; */
/* margin-left: -10px; */
/* margin-top: -10px; */
}

13
themes/minimal/templates/base.html

@ -18,6 +18,7 @@
<script src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/js/lg-share.js"></script>
<script src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/js/jquery.mousewheel.min.js"></script>
<link href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/css/lang.css" rel="stylesheet" >
<link href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/css/bootstrap.min.css" rel="stylesheet" >
<link href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/css/bitter.css" rel="stylesheet" >
<link href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/css/minimal.css" rel="stylesheet" type="text/css">
@ -27,7 +28,7 @@
<link href="{{ FEED_DOMAIN }}/{{ FEED_RSS }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} RSS Feed" />
{% endif %}
<title>asdf {% block title %}{{ SITENAME }}{% endblock title %}</title>
<title>{% block title %}{{ SITENAME }}{% endblock title %}</title>
</head>
<body>
@ -41,6 +42,15 @@
{% endfor %}
<li class="navigation-item">
<div class="langmenu navigation-link blocklink">
{% if lang_siteurls %}
{% for lang, url in lang_siteurls.items() %}
<a {% if lang == DEFAULT_LANG %} class="active" {% else %} class="passive" {% endif %} href="{{ url }}/{{ output_file }}"><img src="{{ lang | lookup_lang_ico }}"></a>
{% endfor %}
{% endif %}
</div>
</li>
</ul>
</div>
</div>
@ -51,6 +61,7 @@
<div class="clearer"></div>
</div>
</body>
<!-- SNIP -->
<script type="text/javascript">
<!-- lightGallery(document.getElementById('lightgallery'), { -->
<!-- thumbnail:true, -->

Loading…
Cancel
Save