-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslation_problems.php
More file actions
executable file
·151 lines (136 loc) · 4.07 KB
/
translation_problems.php
File metadata and controls
executable file
·151 lines (136 loc) · 4.07 KB
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
<!doctype html><html><head>
<?php include'imports.php'?>
</head><body><center>
<!--sidebar--><?php include'sidebar.php'?>
<!--NAVBAR--><?php include"navbar.php"?>
<!--linear--><?php include'linear.php'?>
<!--TITLE--><h1 style=color:black>
Developer tool:
translation problems finder
—
Current language:
<span style=color:black;font-weight:bold>
<?php echo $lang ?>
</span>
</h1>
<?php
//solve problems if "null" is selected
if($lang=="null")$lang="en";
?>
<!--description-->
<p>
This page compares the
<a target=_blank href="languages/en.json">en.json</a> (used for development)
against the
<a target=_blank href="languages/<?php echo $lang?>.json"><?php echo $lang?>.json</a>
file (the current selected language by the user)
</p>
<ul style=max-width:50%;text-align:left>
<li>
Language tags: <b><?php echo count($lang_json)?></b>
<li>
To list not used tags: run the <a href="languages/findNotUsed.sh">findNotUsed.sh</a> bash script from the command line.
<li>
Duplicated tags:
<?php
function countLines($file){
$linecount = 0;
$handle=fopen($file,"r");
while(!feof($handle)){
$line=fgets($handle);
$linecount++;
}
fclose($handle);
return $linecount;
}
function compareFiles($file1,$file2){
global $lang;
$f1=countLines($file1);
$f2=countLines($file2);
if($f1!=$f2){
echo "<ul>
<li>$file1: $f1 lines
<li>$file2: $f2 lines
← probably has ".abs($f2-$f1)." duplicates. Paste the <a target=_blank href='languages/$lang.json'>$lang.json</a> file <a target=_blank href='https://jsonformatter.curiousconcept.com/'>here</a> to find them.
</ul>
";
}else{
echo "<span style=background:#af0>No duplicated tags found 😃</a>";
}
}
compareFiles("languages/en.json","languages/$lang.json");
?>
<li>
<span style="background:red;color:black;">
Other problems found:
<span id=problems_counter>0</span>
</span>
</ul>
<!--problems found-->
<table style=font-family:monospace>
<tr><th>Missing tags in "<?php echo "$lang.json"?>"<th>English Text
<?php
error_reporting(E_ALL^E_NOTICE);
function updateCounter($problems){
echo "<script>
document.body.onload=function(){
var pc=document.querySelector('#problems_counter');
pc.innerHTML='<b>$problems</b>';
if($problems==0){
pc.parentNode.style.background='#af0';
}
}
</script>";
}
function compareCurrentLanguage(){
global $lang_json;
$en_lang_file=file_get_contents("languages/en.json");
$en_lang_json=json_decode($en_lang_file,true);
//counter for problems
$problems=0;
//look for missing tags in current language
foreach($en_lang_json as $key=>$text){
if(!$lang_json[$key]){
echo "<tr>
<td>$key
<td><small>$text</small>
</tr>";
$problems++;
}
}
//look for existing tags that are not existing in en.json
echo '<tr><th>Not existing tags in "en.json"<th>Translated text (can be removed safely)';
foreach($lang_json as $key=>$text){
if(!$en_lang_json[$key]){
echo "<tr>
<td>$key
<td><small>$text</small>
</tr>";
$problems++;
}
}
//look for duplicated tags (removed)
//NOTE: trying to add a duplicate on purpose fails, probably because json_decode already removes duplicates
/*
echo '<tr><th>Duplicated tags<th>Number of instances';
$tags=[];
foreach($lang_json as $key=>$text){
$tags[]=$key;
}
$duplicated=array_count_values($tags);
foreach($duplicated as $tag=>$n){
if($n>1){
echo "<tr>
<td>$tag
<td>$n
</tr>";
$problems++;
}
}
*/
//update problems counter
updateCounter($problems);
}
compareCurrentLanguage();
?>
</table>