Skip to content

Commit

Permalink
Template: version selector
Browse files Browse the repository at this point in the history
Refs #99
  • Loading branch information
laurentj committed Sep 10, 2018
1 parent 1a21ead commit 3535727
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 71 deletions.
7 changes: 4 additions & 3 deletions Makefile
Expand Up @@ -53,9 +53,10 @@ html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) -D language=$$lang $(BUILDDIR)/html/$$lang;\
done

# $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
# @echo
# @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
htmlen:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) -D language=en $(BUILDDIR)/html/en/
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html/e,."

dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
Expand Down
20 changes: 20 additions & 0 deletions source/_static/css/custom.css
Expand Up @@ -58,5 +58,25 @@ select#languages option {
padding: 2px;
}

#versions-links {
float:right;
display:inline-block;
margin: 10px 1em 0 4px;
color: white;
}

#versions-links-list {

}
#versions-links-list a {
/*color: white;*/
}
#versions-links-list > a::before,
#versions-links-list > strong::before
{
content: " - "
}

#versions-links-list :first-child::before {
content: ""
}
91 changes: 25 additions & 66 deletions source/_template/languageswitch.html
@@ -1,76 +1,35 @@


<select id="languages">
<!-- note on the options here: the 'title' string is to be translated in your
language, but the element text is supposed to stay in native lang/txt -->
<option value="fr" title="{{ _('French') }}">Français</option>
<option value="en" title="{{ _('English') }}">English</option>
<option value="es" title="{{ _('Spanish') }}">Español</option>
<option value="it" title="{{ _('Italian') }}">Italiano</option>
<option value="pt" title="{{ _('Portuguese') }}">Português</option>
<option value="fi" title="{{ _('Finnish') }}">Suomalainen</option>
<!-- <option value="ca_ES" title="{{ _('Catalan') }}">Catalan</option>
<option value="da_DK" title="{{ _('Danish') }}">Dansk</option>
<option value="de" title="{{ _('German') }}">Deutsch</option>
<option value="fa" title="{{ _('Persian') }}">فارسی</option>
<option value="id" title="{{ _('Indonesian') }}">Bahasa Indonesia</option>
<option value="ja" title="{{ _('Japanese') }}">日本語</option>
<option value="ko_KR" title="{{ _('Korean') }}">한국어</option>
<option value="nl" title="{{ _('Dutch') }}">Nederlands</option>
<option value="ro" title="{{ _('Romanian') }}">Română</option>
<option value="ru" title="{{ _('Russian') }}">Русский</option>
<option value="zh_CN" title="{{ _('Chinese (China)') }}">中文</option>
<option value="zh_TW" title="{{ _('Chinese (Taiwan)') }}">{{ _('Chinese (Taiwan)') }}</option> -->
{% for lang in lizmap_locales %}
<option value="{{ lang }}" data-url="{{ lizmap_path_to_root }}../{{ lang }}/index.html" title="{{ lizmap_locales_name[lang] }}">{{ lizmap_locales_label[lang] }}</option>
{% endfor %}
</select>

<span id="versions-links">
Versions:
<span id="versions-links-list">
{% for liz_vers, liz_label, liz_link in lizmap_versions.list %}
{% if liz_vers == lizmap_versions.next_version%}
{% if version == lizmap_versions.next_version %}<strong class="verlink">{{ liz_label }}</strong>{% endif %}
{%else%}
{% if liz_vers == version %}
<strong class="verlink">{{ liz_label }}</strong>
{% else %}
<a class="verlink" href="{{ lizmap_path_to_root }}../../{{ liz_link }}/{{ language }}/" title="{{ liz_label }}">{{ liz_label }}</a>
{% endif %}{% endif %}
{% endfor %}
</span>
</span>

<script>
var currentPage = '{{current_page_name}}.html'; // coming from sphinx, always without starting '/'
var currentLang = 'en';
// split index.html if currentUrl is ended by '/'
var currentUrl = window.location.href;
if (currentUrl.slice(-1) == '/' && currentPage.slice(-1) != '/'){
var pages = currentPage.split('/');
pages.pop();
currentPage = pages.join('/') + '/';
}
var currentPage = '{{current_page_name}}.html'; // coming from sphinx, always without starting '/';
var currentLang = '{{ language }}';
document.addEventListener("DOMContentLoaded", function(){
var search = new RegExp('\/[a-zA-Z_]{2,8}\/'+ currentPage, 'gi');
var langPlusPage = window.location.href.match(search);
// it's possible this is the index.html page called without 'index.html', try without the currentPage
if (langPlusPage==undefined){
search = new RegExp('\/[a-zA-Z_]{2,8}\/$', 'gi');
langPlusPage = window.location.href.match(search);
}
// it's possible this is an index.html page called without 'index.html', try removing index.html
if (langPlusPage==undefined){
currentPage = currentPage.replace('index.html','')
search = new RegExp('\/[a-zA-Z_]{2,8}\/'+ currentPage, 'gi');
langPlusPage = window.location.href.match(search);
}
// still no langPlugPage: stop, because the language swicher will misbehave
if (langPlusPage == undefined || langPlusPage.length != 1){
alert('This is an documentation error, please report back to QGIS devs.');
return;
}
langPlusPage = langPlusPage[0];
currentLang = langPlusPage.replace(currentPage, '');
if (currentLang[0] != '/')
currentLang = '/'+currentLang;
// put some style around the current locale flag, we have to remove the '/' here
// this is for the flags:
//$('#flag_'+currentLang.replace(/\//g,'')).css('background-color', '#cccccc');
// set language select to current lang
var selectLanguage = document.getElementById("languages");
selectLanguage.value = currentLang.replace(/\//g,''); // currentLang is something like '/nl/'

selectLanguage.value = currentLang;
selectLanguage.addEventListener("change", function(event) {
gotoLang(event.target.value);
window.location.href = event.target.selectedOptions[0].getAttribute('data-url');
}, false);

}, false);

// load current page in a different language
function gotoLang(lang){
var currentUrl = window.location.href;
var newUrl = currentUrl.replace(currentLang, '/'+lang+'/');
window.location.href = newUrl;
}
</script>
59 changes: 58 additions & 1 deletion source/_template/layout.html
@@ -1,5 +1,63 @@
{% extends "!layout.html" %}

{% set lizmap_locales_name = {
'fr': _('French'),
'en': _('English'),
'es': _('Spanish'),
'it': _('Italian'),
'pt': _('Portuguese'),
'fi': _('Finnish'),
'ca_ES': _('Catalan'),
'da_DK': _('Danish'),
'de': _('German'),
'fa': _('Persian'),
'id': _('Indonesian'),
'ja': _('Japanese'),
'ko_KR': _('Korean'),
'nl': _('Dutch'),
'ro': _('Romanian'),
'ru': _('Russian'),
'zh_CN': _('Chinese (China)'),
'zh_TW': _('Chinese (Taiwan)')
}
%}

{% set lizmap_locales_label = {
'fr': 'Français',
'en': 'English',
'es': 'Español',
'it': 'Italiano',
'pt': 'Português',
'fi': 'Suomalainen',
'ca_ES': 'Catalan',
'da_DK': 'Dansk',
'de': 'Deutsch',
'fa': 'فارسی',
'id': 'Bahasa Indonesia',
'ja': '日本語',
'ko_KR': '한국어',
'nl': 'Nederlands',
'ro': 'Română',
'ru': 'Русский',
'zh_CN': '中文',
'zh_TW': _('Chinese (Taiwan)')
}
%}

{% set lizmap_locales = lizmap_versions.locales[version] %}
{% set lizmap_path_to_root = pathto('index')|replace('index.html','')|replace('#','') %}

{% block extrahead %}
{% for lang in lizmap_locales -%}
{% if language != lang -%}
<link href="{{ lizmap_path_to_root }}../{{ lang }}/" rel="alternate" hreflang="{{ lang }}"/>
{% endif %}
{%- endfor %}
{% if lizmap_versions.stable_version != version -%}
<link href="{{ lizmap_path_to_root }}../../{{ lizmap_versions.stable_version}}" rel="canonical"/>
{% endif %}
{% endblock %}

{% block bodyheader %}
<div class="globalnav globalhead">
<a class="siteNav" href="{{ pathto(master_doc) }}" >
Expand All @@ -21,4 +79,3 @@
</div>
{% include "searchbox.html" %}
{% endblock %}

6 changes: 5 additions & 1 deletion source/conf.py
Expand Up @@ -12,6 +12,7 @@
# serve to show the default.

import sys, os
import json

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -120,8 +121,11 @@
#html_logo = None
html_logo = 'images/logo.png'

lizmap_versions = json.load(file('lizmap_versions.json'))

html_context = {
'theme_logo_only': True
'theme_logo_only': True,
'lizmap_versions': lizmap_versions
}

html_style = 'css/custom.css'
Expand Down
14 changes: 14 additions & 0 deletions source/lizmap_versions.json
@@ -0,0 +1,14 @@
{
"list" : [
["3.2", "Lizmap 3.2", "3.2"],
["3.1", "Lizmap 3.1/3.0/2.x", "3.1"],
["3.3", "Development version", "next"]
],
"locales" : {
"3.1": [ "fr", "en", "it", "es", "pt", "fi"],
"3.2": [ "fr", "en", "it", "es", "pt", "fi"],
"3.3": [ "fr", "en", "it", "es", "pt", "fi"]
},
"stable_version" : "3.2",
"next_version" : "3.3"
}

0 comments on commit 3535727

Please sign in to comment.