/
languageswitch.html
239 lines (231 loc) · 13.4 KB
/
languageswitch.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<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="en" title="{{ _('English') }}">English</option>
<option value="ca" title="{{ _('Catalan') }}">Català</option>
<option value="da" title="{{ _('Danish') }}">Dansk</option>
<option value="de" title="{{ _('German') }}">Deutsch</option>
<option value="es" title="{{ _('Spanish') }}">Español</option>
<option value="fa" title="{{ _('Persian') }}">فارسی</option>
<option value="fi" title="{{ _('Finnish') }}">Suomi</option>
<option value="fr" title="{{ _('French') }}">Français</option>
<option value="gl" title="{{ _('Galician') }}">Galego</option>
<option value="id" title="{{ _('Indonesian') }}">Bahasa Indonesia</option>
<option value="it" title="{{ _('Italian') }}">Italiano</option>
<option value="hu" title="{{ _('Hungarian') }}">Magyar</option>
<option value="ja" title="{{ _('Japanese') }}">日本語</option>
<option value="km_KH" title="{{ _('Khmer') }}">ភាសាខ្មែរ </option>
<option value="ko" title="{{ _('Korean') }}">한국어</option>
<option value="lt" title="{{ _('Lithuanian') }}">Lietuvių</option>
<option value="nl" title="{{ _('Dutch') }}">Nederlands</option>
<option value="pl" title="{{ _('Polish') }}">Polski</option>
<option value="pt_BR" title="{{ _('Portuguesei (Brazil)') }}">Português (Brasil)</option>
<option value="pt_PT" title="{{ _('Portuguese') }}">Português</option>
<option value="ro" title="{{ _('Romanian') }}">Română</option>
<option value="tr" title="{{ _('Turkish') }}">Türkçe</option>
<option value="ru" title="{{ _('Russian') }}">Русский</option>
<option value="uk" title="{{ _('Ukrainian') }}">Українська</option>
<option value="zh-Hans" title="{{ _('Chinese (Simplified)') }}">簡体中文</option>
<option value="zh-Hant" title="{{ _('Chinese (Traditional)') }}">正體中文</option>
</select>
<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('/') + '/';
}
$(document).ready(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, '');
// TODO: links should come from conf.py
// TODO: all template pages have the actual translation in sphinc.conf
// IMPORTANT: space, -, _ etc replacing below must be 100% inline with
// code in scripts/create_transifex_resources.sh !!
// https://github.com/qgis/QGIS-Website/blob/master/scripts/create_transifex_resources.sh
fix_translation_link = 'https://www.transifex.com/projects/p/qgis-website/translate/#' +
currentLang.slice(1) + currentPage.replace(/_/g, "-").replace(/ /g, "-").replace(/\//g, "_").replace(/\.html/g, "").replace(/\./g, "-")
if ('/en/' != currentLang) {
$('#fix_translation_link').attr('href', fix_translation_link);
}
fix_text_link = 'https://github.com/qgis/QGIS-Website/edit/master/source/' +
currentPage.replace(/.html/g, ".rst")
// TODO: only on rst pages, here a list of pages which are actual templates?
if (true){
$('#fix_text_link').attr('href', fix_text_link);
}
$("#languages").val(currentLang.replace(/\//g,'')); // currentLang is something like '/nl/'
$("#languages").change(function() {
gotoLang($(this).val());
});
if (currentPage == "site/about/screenshots.html"){
atom('/feeds/qgisflickrscreenshots.atom', '#qgisflickrscreenshotsatom', 30, false, 'span3');
atom('/feeds/qgisflickrmaps.atom', '#qgisflickrmapsatom', 30, false, 'span3');
}
else if (currentPage == "site/about/sponsorship.html"){
// http://changelog.qgis.org/en/qgis/sponsors/atom/
// http://changelog.qgis.org/en/qgis/pastsponsors/atom/
// function atom(url, holder, count, showcont, spanclass){
atom('/feeds/qgissponsors.atom', '#qgissponsorsatom', 1000, true, 'span3');
atom('/feeds/qgispastsponsors.atom', '#qgispastsponsorsatom', 1000, true, 'span3');
}
else if (currentPage == "site/forusers/download.html" || currentPage == "site/forusers/alldownloads.html"){
$($('section.content')[0]).append('<div id="thankyou"> <div id="thankyoucontent">'+
'<h2>{{ _("Thank you!") }}</h2> <p/>'+
'<div class="container"><div class="span8">'+
'<p>{{ _("Your freshly baked copy of QGIS is downloading. QGIS is free of charge, and will always be free of charge if downloaded from QGIS.org. If you can afford to support the project and people making this software, please consider making <a href=\"http://qgis.org/en/site/getinvolved/donations.html\">a small donation to support</a> our efforts. Whether you choose to donate or not, we hope that you enjoy using our labour of love and encourage you to share and spread your downloaded copy far and wide so that others may enjoy it too. Our very best regards!") }}</p>'+
'<p>{{ _("The QGIS Team") }}</p>'+
'</div><div class="container">'+
'<div class="span4"><p><a class="btn btn-large btn-success btn-flat" href="../getinvolved/donations.html">{{ _("Donate Now") }}</a></p><p class="muted"></p></div>'+
'<div class="span5"><p><a id="closethankyou"class="btn btn-large btn-success btn-flat" href="#">{{ _("Close this message") }}</a></p><p class="muted"></p></div>'+
'</div>'+
'<br/><p><img src="{{pathto('_static/images/splash.png', 1)}}"/></p></div>');
$('#thankyou').click(function(){ $('#thankyou').hide(); });
$('#closethankyou').click(function(){ $('#thankyou').hide(); });
$('a.reference').click(function(){
$('#thankyou').show();
return true;
});
}
else if (currentPage == "site/getinvolved/donations.html"){
// inject the stripeform into this page
$.get( "{{ stripeformurl }}", function( data ) { $( "#stripe" ).html( data ); });
// create thankyou and error page
$($('div.container')[0]).append('<div id="thankyou"> <div id="thankyoucontent">'+
'<h2>{{ _("Thank you for your donation!") }}</h2> <p/>'+
'<div class="container"><div class="span8">'+
'<p id="stripemsg">{{ _("QGIS is free of charge and we hope that you enjoy using our labour of love and encourage you to share and spread your downloaded copy far and wide so that others may enjoy it too. Our very best regards!") }}</p>'+
'<p id="stripeerr" style="display:none;">{{ _("Unfortunately there was an error processing your Donation. Please try again later, or contact us via finance@qgis.org") }}</p>'+
'<p>{{ _("The QGIS Team") }}</p>'+
'</div><div class="container">'+
'<div class="span5"><p><a id="closethankyou"class="btn btn-large btn-success btn-flat" href="#">{{ _("Close this message") }}</a></p><p class="muted"></p></div>'+
'</div>'+
'<br/><p><img src="{{pathto('_static/images/splash.png', 1)}}"/></p></div>');
$('#thankyou').click(function(){ $('#thankyou').hide(); });
$('#closethankyou').click(function(){ $('#thankyou').hide(); });
}
});
//
// 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;
}
//
// function to load an atom feed, an put it in an element
//
function atom(url, holder, count, showcont, spanclass){
$.get(url, function (data) {
var html = "";
if (spanclass == undefined){
spanclass = "span2"
}
var maxitems = 7;
if(count)maxitems=count;
var showcontent = false;
if(showcont)showcontent=showcont;
var counter = 0;
$(data).find("entry").each(function () {
var el = $(this);
var title = el.find('title').text();
var author = el.find('name').text();
var content = el.find('content').text();
if (content.length==0){
// try summary
content = el.find('summary').text();
}
var imglink='#';
var link='#';
el.find('link').each(
function(){
// flickr image for maps and qgis screenshots
if ($(this).attr('rel') == 'enclosure'){
// s - Specifies the small square size of 75x75 pixels.
// t - Specifies the thumbnail size with 100 pixels on the longest side.
// m - Specifies the medium size with 240 pixels on the longest side.
// z - Specifies the medium size with 640 pixels on the longest side.
// b - Specifies the large size with 1024 pixels on the longest side.
// q - square
imglink = $(this).attr('href').replace('_b.jpg','_q.jpg');
}
// links
else if ($(this).attr('rel') == 'alternate'){
link = $(this).attr('href');
}
}
)
counter++;
if (counter<=maxitems &&
(holder == '#qgisflickrmapsatom' || holder == '#qgisflickrscreenshotsatom') ){
// html for flickr maps
html+='<div class="'+spanclass+'"><p><a class="external" href="'+link+'">';
if(imglink!='#'){ html+='<img class="flickrimg" src="'+imglink+'"/>'; }
html+='</a></p></div>\n';
}
else if (counter<=maxitems){
// visual changelogs, qugs feed and planet feed
var addit = true;
if (holder == '#qgisplanetatom'){
var s = title.split(':');
title = s[0];
content = s[1];
// skip blog.qgis.org posts
if (link.indexOf('blog.qgis.org')>=0){
addit = false;
counter --;
}
}
else if (holder == '#qgissponsorsatom' || holder == '#qgispastsponsorsatom'){
html+='<div class="clearfix"><a class="clearfix" href="'+link+'">';
html+='<div class="sponsordiv"><h4>'+title+'</h4>';
html+=content;
html+='</div></a></div>';
addit = false; // we are building html ourselves!!
}
else if (holder == '#qgisblogatom'){
var s = title.split(':');
if (s[0] != 'QGIS Project blog'){
addit = false;
counter--;
}
// trying to extract date from link
// http://blog.qgis.org/2017/09/02/do-you-want-to-host-a-qgis-developer-meeting/
d = link.split('/').slice(3,6); // 2017,09,02
title = '<img src="../_static/logo.png" style="width:30px;"/> - ' + d[0] + '/' + d[1] + '/' + d[2] + ' - ' + s[1];
content = '';
}
if (addit){
html+='<a class="external" href="'+link+'">';
html+='<div class="info-box" style="padding:10px;color:#666;"><b>'+title+'</b><br/>';
if (showcontent) { html+=content; };
html+='</div></a>\n';
}
}
});
$(holder).append(html);
});
}
</script>