Skip to content

Commit 6c6ca0d

Browse files
Translation statistics of property discussion templates
1 parent a03ecd4 commit 6c6ca0d

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed

RELEASE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# v0.4 (under progress)
1+
# v0.5 (under progress)
2+
===============================================================================
3+
4+
# v0.4
25
===============================================================================
36
* Compare translation statistics
47
* Add support to view translated labels, descriptions and aliases
8+
* Translation statistics of templates
59

610
# v0.3
711
===============================================================================

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ <h2>Compare translation statistics</h2>
3232
<ul>
3333
<li><a href="./compare.html?languages=en, fr">Compare</a></li>
3434
</ul>
35+
<h2>Wikdidata property discussion</h2>
36+
<ul>
37+
<li><a href="./templates/translated.html">Translated Templates</a></li>
38+
</ul>
3539
<h2>About</h2>
3640
<ul>
3741
<li><a href="./wdprop.html">About</a></li>

mwwdprop.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
function queryMediaWiki(queryparams, func, divId, url) {
2+
var div = document.getElementById(divId);
3+
var fetchText = document.createElement("h4");
4+
fetchText.innerHTML = "Fetching data...";
5+
div.append(fetchText);
6+
7+
const endpointUrl = 'https://www.wikidata.org/w/api.php',
8+
fullUrl = endpointUrl + '?action=' + queryparams+"&format=json";
9+
10+
fetch( fullUrl, { } ).then( body => body.json() ).then( json => {
11+
div.removeChild(fetchText);
12+
func(divId, json, url)
13+
} );
14+
}
15+
16+
function createDivLanguage(divId, json, url) {
17+
console.log(json);
18+
xml = json.parse["parsetree"]["*"];
19+
console.log(xml);
20+
var languagesDiv = document.getElementById(divId);
21+
var count = 0;
22+
var regexp = /<name>(.+?)<\/name>/g;
23+
var languages = document.createElement("div");
24+
while(true) {
25+
match = regexp.exec(xml);
26+
if(match == null) {
27+
break;
28+
}
29+
var languageText = match[1].replace(/\s/g, "")
30+
if(languageText == "lang" || languageText == "#default") {
31+
continue;
32+
}
33+
count ++;
34+
var language = document.createElement("div");
35+
language.setAttribute('class', "language");
36+
var a = document.createElement("a");
37+
a.setAttribute('href', url);
38+
var text = document.createTextNode(languageText);
39+
a.appendChild(text);
40+
language.appendChild(a);
41+
languages.appendChild(language);
42+
}
43+
var total = document.createElement("h4");
44+
total.innerHTML = "Template translated in total " + count + " languages";
45+
languagesDiv.appendChild(total);
46+
languagesDiv.appendChild(languages);
47+
}
48+
49+
function getTemplateTranslationStatistics() {
50+
var queryparams = "parse&page=Template:Support&prop=parsetree&origin=*";
51+
queryMediaWiki(queryparams, createDivLanguage,
52+
"translatedTemplateSupport",
53+
"https://www.wikidata.org/wiki/Template:Support");
54+
55+
var queryparams = "parse&page=Template:Oppose&prop=parsetree&origin=*";
56+
queryMediaWiki(queryparams, createDivLanguage,
57+
"translatedTemplateOppose",
58+
"https://www.wikidata.org/wiki/Template:Oppose");
59+
60+
var queryparams = "parse&page=Template:Neutral&prop=parsetree&origin=*";
61+
queryMediaWiki(queryparams, createDivLanguage,
62+
"translatedTemplateNeutral",
63+
"https://www.wikidata.org/wiki/Template:Neutral");
64+
65+
var queryparams = "parse&page=Template:Comment&prop=parsetree&origin=*";
66+
queryMediaWiki(queryparams, createDivLanguage,
67+
"translatedTemplateComment",
68+
"https://www.wikidata.org/wiki/Template:Comment");
69+
}

style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ h3 {
4949
font-size : 3vh;
5050
clear:both;
5151
}
52+
h4 {
53+
color: #002f6c;
54+
font-size : 2vh;
55+
clear:both;
56+
}
5257
a:link, a:visited {
5358
color: #1B80CF;
5459
}

templates/translated.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>WDProp: Everything about Wikidata Properties: John Samuel</title>
6+
<link rel="stylesheet" type="text/css" href="../style.css">
7+
<script type="text/javascript" src="../jquery-3.3.1.min.js">
8+
</script>
9+
<script type="text/javascript" src="../mwwdprop.js">
10+
</script>
11+
</head>
12+
<body onload="getTemplateTranslationStatistics()">
13+
<h1><a href="../index.html">WDProp: Everything about Wikidata properties</a></h1>
14+
<h2>Template translation statistics</h2>
15+
<h3 id="templateSupport">Template Support</h2>
16+
<div id="translatedTemplateSupport">
17+
</div>
18+
<h3 id="templateOppose">Template Oppose</h2>
19+
<div id="translatedTemplateOppose">
20+
</div>
21+
<h3 id="templateNeutral">Template Neutral</h2>
22+
<div id="translatedTemplateNeutral">
23+
</div>
24+
<h3 id="templateComment">Template Comment</h2>
25+
<div id="translatedTemplateComment">
26+
</div>
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)