-
Notifications
You must be signed in to change notification settings - Fork 2
/
builder.php
213 lines (195 loc) · 9.14 KB
/
builder.php
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
<?php
/**
* Free Android strings.xml builder and translator
*
* @author Leonardo Rignanese (rignaneseleo) <[email protected]>
*
* @link http://rignaneseleo.github.io/
*
* @license GNU GENERAL PUBLIC LICENSE Version 2, June 1991
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0" />
<title>StringsXml Builder & Translator | rignaneseleo</title>
<!-- facebook -->
<meta property="og:title" content="StringsXmlBuilder And Translator" />
<meta property="og:image" content="http://stringsxmlbuilder.netsons.org/sxb.png"/>
<meta property="og:site_name" content="StringsXmlBuilder" />
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<link href="css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection" />
<link href="css/style.css" type="text/css" rel="stylesheet" media="screen,projection" />
<!-- favicon -->
<link rel="apple-touch-icon" sizes="57x57" href="favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
<link rel="manifest" href="favicon/manifest.json">
</head>
<body>
<div class="section no-pad-bot" id="index-banner">
<div class="container">
<?php include_once("partials/header.php"); ?>
<div class="row center">
<form method="post" action="downloadXml.php">
<?php
//add library to translate the strings
require 'vendor/autoload.php';
use Stichoza\GoogleTranslate\TranslateClient;
//echo TranslateClient::translate('en', 'ka', 'Hello again');//debug
$translationError=false;
if (!empty($_GET["originalXmlURL"])){
$originalXmlURL =rawurldecode($_GET["originalXmlURL"]);//get the url of the strings.xml file
//todo validateXmlURL
//initialize the translation Language
$translationLang="";
if(!empty($_GET["translationLang"])){//if there is
$translationLang=$_GET["translationLang"];//get the translation language
$translator = new TranslateClient('en', $translationLang);
}
//create the list of already translated strings
$stringsAlreadyTranslated = array();
//check if there is a file altready partially translated
if(!empty($_GET["translatedXmlURL"])){
$translatedXmlURL =rawurldecode($_GET["translatedXmlURL"]);//get the url of the strings.xml file altready partially translated
$translatedXml = simplexml_load_file($translatedXmlURL);//read the XML
foreach($translatedXml->children() as $alreadyTranslatedString) {
$stringName=(string)$alreadyTranslatedString['name'];
$stringValue=str_replace("\'", "'", (string)$alreadyTranslatedString);//normalize string
$stringsAlreadyTranslated[$stringName]=$stringValue;
}
}
//start building the table
echo "<table style='width: 100%' class='highlight centered'><thead><tr> <th> Value </th> <th> Translation </th></tr></thead><tbody>";//start table
$originalXml = simplexml_load_file($originalXmlURL);//read the XML
foreach($originalXml->children() as $rowString) {//foreach string
if((string)$rowString['translatable']!="false"){//only translatable strings
//initialize variables
$disabled=false;
$stringName=(string)$rowString['name'];
$stringValue=str_replace("\'", "'", (string)$rowString);//normalize string
$translatedValue="";
//check if there are already translated strings
if(!empty($stringsAlreadyTranslated)){
//there are strings to avoid
if (array_key_exists($stringName, $stringsAlreadyTranslated)) {
//it was already translated
$translatedValue=$stringsAlreadyTranslated[$stringName];
$disabled=true;
}
}
if(!empty($translationLang) && empty($translatedValue))//if you know the translation language and there isn't altready a translation
{
try {//try because sometimes the translator has issues
$translatedValue=str_replace("'", "'",$translator->translate(str_replace("\'", "'", (string)$rowString)));//translate removing the '
}
catch(Exception $e){
$translationError=true; //with this flag, after will show the toast error message
}
}
//start building the row
echo "<tr ";
if($disabled)echo "class='disabled hide'";
echo ">";
echo "<td style='max-width:700px'>". $stringValue . "</td>";
echo "<td>";
//echo "<input type='hidden' name='stringValueIds[". $stringName ."]' value='".$stringValue."'>"; to print the english value
echo "<textarea ";
if($disabled) echo "readonly";
echo " style='width: 100%' class='materialize-textarea' type='text' name='translatedValueIds[". $stringName ."]'>". $translatedValue ."</textarea></td>";
echo "</tr>";
}
}
echo "</tbody></table>";//end table
}
else{
header("Location: index.php");//return at home
}
?>
<div class="divider"></div>
<div class="row center">
<div id="progressbar" class="progress hide">
<div class="indeterminate"></div>
</div>
<div class="input-field col s6">
<input class="validate" type="text" name="username" />
<label for="username">Your name or username</label>
</div>
<div class="col s6" style="margin-top: 1rem;">
<!--<button class="btn waves-effect waves-light orange" type="submit" value="" name="save" id="generateStringsXml">
Save the strings.xml translated
<i class="material-icons right">attach_file</i>
</button>-->
<input type="submit" class="waves-effect waves-light btn orange" name="save" id="generateStringsXml" value="Generate Translated Strings.xml" />
</div>
</div>
</form>
<!--FAB Button-->
<div class="fixed-action-btn <?php if(empty($_GET["translatedXmlURL"])){echo "hide";} ?>" style="bottom: 85px; right: 24px;">
<a id="FAB" class="btn-floating tooltipped waves-light btn-large red" showstrings="true" data-position="left" data-delay="50" data-tooltip="Show\Hide strings altready translated">
<i id="FAB-icon" class="large material-icons">view_stream</i>
</a>
</div>
</div>
</div>
</div>
<?php include_once("partials/footer.php"); ?>
<!-- Scripts-->
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/colResizable.min.js"></script>
<script src="js/materialize.min.js"></script>
<script src="js/analytics.js"></script>
<script>
$(function () {
$("table").colResizable();
});
$('#generateStringsXml').click(function() {
$('#progressbar').removeClass( "hide" );
setTimeout(function(){$('#progressbar').addClass( "hide" );
}, 3000);
});
$('#FAB').click(function () {
if ($("#FAB").attr("showStrings") == "true") {
$("tr.disabled").removeClass("hide");
$("#FAB-icon").html("reorder");
$("#FAB").attr("showStrings", "false");
}
else {
$("tr.disabled").addClass("hide");
$("#FAB-icon").html("view_stream");
$("#FAB").attr("showStrings", "true");
}
});
var editedForms = false;
$(function(){
// Cambio lo stato della variabile se si accede ad un elemento del form
$('form input, form select, form textarea').focus(function(){
editedForms = true;
});
});
window.onbeforeunload = function() {
if (editedForms){
return 'Attenction!'+'\n'+
'Seems that you are losing your work!';
}
}
<?php
if($translationError)
echo "$(function () {Materialize.toast('There was an error during the translation!', 10000);})";
?>
</script>
</body>
</html>