1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/Export.php');
|
---|
4 |
|
---|
5 | class ExportAddon extends Export
|
---|
6 | {
|
---|
7 | // Replace special codes by lua functions
|
---|
8 | function ReplaceVarInText(string $string, string $strlower = 'strlower'): string
|
---|
9 | {
|
---|
10 | $string = str_replace('$N', '"..'.$strlower.'(UnitName("player")).."', $string);
|
---|
11 | $string = str_replace('$n', '"..'.$strlower.'(UnitName("player")).."', $string);
|
---|
12 | $string = str_replace('$C', '"..'.$strlower.'(UnitClass("player")).."', $string);
|
---|
13 | $string = str_replace('$c', '"..'.$strlower.'(UnitClass("player")).."', $string);
|
---|
14 | $string = str_replace('$R', '"..'.$strlower.'(UnitRace("player")).."', $string);
|
---|
15 | $string = str_replace('$r', '"..'.$strlower.'(UnitRace("player")).."', $string);
|
---|
16 | $Gender = '$G';
|
---|
17 | while (strpos($string, $Gender) !== false)
|
---|
18 | {
|
---|
19 | $Before = substr($string, 0, strpos($string, $Gender));
|
---|
20 | $Man = substr($string, strpos($string, $Gender) + 2);
|
---|
21 | $Woman = substr($Man, strpos($Man, ':') + 1);
|
---|
22 | $After = substr($Woman, strpos($Woman, ';') + 1);
|
---|
23 | $Man = substr($Man, 0, strpos($Man, ':'));
|
---|
24 | $Woman = substr($Woman, 0, strpos($Woman, ';'));
|
---|
25 | $Man = str_replace(' ', '', $Man);
|
---|
26 | $Woman = str_replace(' ', '', $Woman);
|
---|
27 | $string = $Before.'"..gsub(gsub(UnitSex("player"), "^2$", "'.$Man.'"), "^3$", "'.$Woman.'").."'.$After;
|
---|
28 | }
|
---|
29 | $Gender = '$g';
|
---|
30 | while (strpos($string, $Gender) !== false)
|
---|
31 | {
|
---|
32 | $Before = substr($string, 0, strpos($string, $Gender));
|
---|
33 | $Man = substr($string, strpos($string, $Gender) + 2);
|
---|
34 | $Woman = substr($Man, strpos($Man, ':') + 1);
|
---|
35 | $After = substr($Woman, strpos($Woman, ';') + 1);
|
---|
36 | $Man = substr($Man, 0, strpos($Man, ':'));
|
---|
37 | $Woman = substr($Woman, 0, strpos($Woman, ';'));
|
---|
38 | $Man = str_replace(' ', '', $Man);
|
---|
39 | $Woman = str_replace(' ', '', $Woman);
|
---|
40 | $string = $Before.'"..gsub(gsub(UnitSex("player"), "^2$", "'.$Man.'"),"^3$", "'.$Woman.'").."'.$After;
|
---|
41 | }
|
---|
42 |
|
---|
43 | $string = str_replace('$', '', $string);
|
---|
44 | $string = str_replace("\r", '', $string);
|
---|
45 | $string = str_replace("\n", '\r\n', $string);
|
---|
46 | return $string;
|
---|
47 | }
|
---|
48 |
|
---|
49 | function ReplaceEnText(string $string): string
|
---|
50 | {
|
---|
51 | $string = strtolower($string);
|
---|
52 | $string = str_replace('"', '\"', $string);
|
---|
53 | $string = str_replace('$b$b', ' ', $string);
|
---|
54 | $string = str_replace('$b $b', ' ', $string);
|
---|
55 | $string = str_replace('$b', ' ', $string);
|
---|
56 | $string = $this->ReplaceVarInText($string);
|
---|
57 | $string = str_replace("\r", ' ', $string);
|
---|
58 | $string = str_replace("\n", ' ', $string);
|
---|
59 | $string = str_replace('\\r', ' ', $string);
|
---|
60 | $string = str_replace('\\n', ' ', $string);
|
---|
61 | $string = str_replace(' ', '', $string);
|
---|
62 | return $string;
|
---|
63 | }
|
---|
64 |
|
---|
65 | function ReplaceCzText(string $string): string
|
---|
66 | {
|
---|
67 | $string = $this->Database->real_escape_string($string);
|
---|
68 | $string = str_replace('$B', '\r\n', $string);
|
---|
69 | $string = str_replace('$b', '\r\n', $string);
|
---|
70 | $string = $this->ReplaceVarInText($string,'');
|
---|
71 | return $string;
|
---|
72 | }
|
---|
73 |
|
---|
74 | function NotCancel(string $string): bool
|
---|
75 | {
|
---|
76 | if (strpos($string,'<html>') > -1) return false;
|
---|
77 | else return true;
|
---|
78 | }
|
---|
79 |
|
---|
80 | function my_trim(string $string): string
|
---|
81 | {
|
---|
82 | $string = addslashes($string);
|
---|
83 | $string = str_replace("\n", '\r\\'."\n",$string);
|
---|
84 | $string = str_replace("\r", '',$string);
|
---|
85 | $string = str_replace("\\\\\\", '\\\\',$string);
|
---|
86 | $string = str_replace("\\\\\\", '\\\\',$string);
|
---|
87 | $string = str_replace("\\\\\\", '\\\\',$string);
|
---|
88 | $string = str_replace("\\\\32", '\\32',$string);
|
---|
89 | $string = str_replace('\\\\"', '\\"',$string);
|
---|
90 | $string = str_replace('\\\\n', '\\n',$string);
|
---|
91 | $string = str_replace('\\\\124', '\\124',$string);
|
---|
92 |
|
---|
93 | return $string;
|
---|
94 | }
|
---|
95 |
|
---|
96 | function MakeLanguageFiles(): string
|
---|
97 | {
|
---|
98 | $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
|
---|
99 |
|
---|
100 | $Output = '';
|
---|
101 | $this->LoadFilters();
|
---|
102 |
|
---|
103 | $CreatedFileList = array();
|
---|
104 | $CreatedFileListCount = array();
|
---|
105 |
|
---|
106 | if (!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/', 0777, true);
|
---|
107 |
|
---|
108 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`TablePrefix` != ""');
|
---|
109 | while ($Group = $DbResult->fetch_assoc())
|
---|
110 | {
|
---|
111 | // získání čísla verze pro export
|
---|
112 | $ID = $this->Database->query('SELECT LastVersion FROM `Group` WHERE Id = '.$Group['Id']);
|
---|
113 | $LastVersion = $ID->fetch_assoc();
|
---|
114 |
|
---|
115 | if ($LastVersion['LastVersion'] < $this->ClientVersion['BuildNumber'])
|
---|
116 | $ExportVersion = $LastVersion['LastVersion'];
|
---|
117 | else $ExportVersion = '';
|
---|
118 |
|
---|
119 | foreach ($TranslationTree[$Group['Id']]['Items'] as $Column)
|
---|
120 | if ($Column['AddonFileName'] != '')
|
---|
121 | {
|
---|
122 | $this->AddProgress(1);
|
---|
123 | if (!isset($CreatedFileListCount[$Column['AddonFileName']]))
|
---|
124 | $CreatedFileListCount[$Column['AddonFileName']] = 0;
|
---|
125 | $CreatedFileListCount[$Column['AddonFileName']]++;
|
---|
126 | $FileIndex = $CreatedFileListCount[$Column['AddonFileName']];
|
---|
127 |
|
---|
128 | $CreatedFileList[] = $Column['AddonFileName'].'_'.$FileIndex;
|
---|
129 | $FileName = $this->TempDir.'CzWoW/'.$Column['AddonFileName'].'_'.$FileIndex.'.lua';
|
---|
130 | $Output .= $Column['AddonFileName'].': ';
|
---|
131 | $i = 0;
|
---|
132 |
|
---|
133 | $Buffer = 'CZWOW_'.$Column['AddonFileName'].'_count='.$FileIndex.';CZWOW_'.$Column['AddonFileName'].'_'.$FileIndex.'={';
|
---|
134 | $TableTexts = array();
|
---|
135 |
|
---|
136 | // old version
|
---|
137 | // get version before
|
---|
138 | $BuildNumber = $ExportVersion;
|
---|
139 | if ($ExportVersion == '') $BuildNumber = $this->ClientVersion['BuildNumber'];
|
---|
140 | $ID = $this->Database->query('SELECT `BuildNumber` FROM `ClientVersion` WHERE '.
|
---|
141 | ' `Imported` = 1 AND `BuildNumber` < '.$BuildNumber.' ORDER BY `BuildNumber` DESC LIMIT 1');
|
---|
142 | if ($ID->num_rows > 0)
|
---|
143 | {
|
---|
144 | $ExportVersionOld = $ID->fetch_assoc();
|
---|
145 | $ExportVersionOld = $ExportVersionOld['BuildNumber'];
|
---|
146 |
|
---|
147 | $DbResult2 = $this->Database->query($this->BuildQuery($Group, $ExportVersionOld));
|
---|
148 | while ($Line = $DbResult2->fetch_assoc())
|
---|
149 | {
|
---|
150 | $Text = $Line['En'.$Column['Column']];
|
---|
151 | if ($Text == null) $Text = '';
|
---|
152 | $en = trim($this->ReplaceEnText($Text));
|
---|
153 | $Text = $Line[$Column['Column']];
|
---|
154 | if ($Text == null) $Text = '';
|
---|
155 | $cz = $this->ReplaceCzText($Text);
|
---|
156 | if (($en <> '') and ($cz <> '') and ($this->NotCancel($en)))
|
---|
157 | {
|
---|
158 | $TableTexts[$en] = $cz;
|
---|
159 | }
|
---|
160 | }
|
---|
161 | }
|
---|
162 | //last version
|
---|
163 |
|
---|
164 | $DbResult2 = $this->Database->query($this->BuildQuery($Group, $ExportVersion));
|
---|
165 | while ($Line = $DbResult2->fetch_assoc())
|
---|
166 | {
|
---|
167 | $Text = $Line['En'.$Column['Column']];
|
---|
168 | if ($Text == null) $Text = '';
|
---|
169 | $en = trim($this->ReplaceEnText($Text));
|
---|
170 | $Text = $Line[$Column['Column']];
|
---|
171 | if ($Text == null) $Text = '';
|
---|
172 | $cz = $this->ReplaceCzText($Text);
|
---|
173 | if (($en <> '') and ($cz <> '') and ($this->NotCancel($en)))
|
---|
174 | {
|
---|
175 | $TableTexts[$en] = $cz;
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | foreach ($TableTexts as $key => $value)
|
---|
180 | {
|
---|
181 | $Buffer .= "\n".'["'.$key.'"]="'.$value.'",';
|
---|
182 | $i++;
|
---|
183 | }
|
---|
184 |
|
---|
185 | $Buffer = $Buffer."\n};if not CZWOW_".$Column['AddonFileName']." then CZWOW_".$Column['AddonFileName']."=0; end; CZWOW_".$Column['AddonFileName']."=CZWOW_".$Column['AddonFileName']."+".$i.";\n";
|
---|
186 |
|
---|
187 | file_put_contents($FileName, $Buffer);
|
---|
188 | $Output .= '<b>Hotovo</b><br />';
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | // Generete list file of translated
|
---|
193 | $CountFiles = 'CountFiles.lua';
|
---|
194 | $Buffer = '';
|
---|
195 | foreach ($CreatedFileList as $CreatedFile)
|
---|
196 | {
|
---|
197 | $Buffer .= 'CZWOW_'.str_replace('_','_count=',$CreatedFile).';'."\n";
|
---|
198 | }
|
---|
199 | foreach ($TranslationTree as $Group)
|
---|
200 | {
|
---|
201 | foreach ($TranslationTree[$Group['Id']]['Items'] as $Column)
|
---|
202 | {
|
---|
203 | if (($Column['AddonFileName'] != '') and (!in_array($Column['AddonFileName'].'_1', $CreatedFileList)))
|
---|
204 | {
|
---|
205 | $Buffer .= 'CZWOW_'.$Column['AddonFileName'].'_count=0;'."\n";
|
---|
206 | }
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | file_put_contents($this->TempDir.'CzWoW/'.$CountFiles, $Buffer);
|
---|
211 |
|
---|
212 | // Generate file Translates.xml
|
---|
213 | $Buffer = '<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/.\FrameXML\UI.xsd">'."\n";
|
---|
214 | $Buffer .= '<script file="'.$CountFiles.'"/>'."\n";
|
---|
215 | foreach ($CreatedFileList as $CreatedFile)
|
---|
216 | {
|
---|
217 | $Buffer .= '<script file="'.$CreatedFile.'.lua"/>'."\n";
|
---|
218 | }
|
---|
219 | $Buffer .= '</Ui>';
|
---|
220 | file_put_contents($this->TempDir.'CzWoW/Translates.xml', $Buffer);
|
---|
221 | return $Output;
|
---|
222 | }
|
---|
223 |
|
---|
224 | function MakeClientStrings(): void
|
---|
225 | {
|
---|
226 | $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
|
---|
227 |
|
---|
228 | $this->LoadFilters();
|
---|
229 |
|
---|
230 | $Buffer = "local f=function(name, en, cz) CzWoW_interface[name]=cz;CzWoW_interface_entoname[en]=name; end; CzWoW_interface={};CzWoW_interface_entoname={ };\n";
|
---|
231 | $Group = $TranslationTree[14]; // client table
|
---|
232 | $Column['Column'] = 'Text';
|
---|
233 |
|
---|
234 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`TablePrefix` != "" AND `Group`.`Id` = 14');
|
---|
235 | if ($DbResult->num_rows == 0)
|
---|
236 | $CanGenerated = '-1';
|
---|
237 | else
|
---|
238 | $CanGenerated = '';
|
---|
239 |
|
---|
240 | $DbResult = $this->Database->query($this->BuildQuery($Group,$CanGenerated));
|
---|
241 | while ($Line = $DbResult->fetch_array())
|
---|
242 | {
|
---|
243 | $OriginalText = $Line['En'.$Column['Column']];
|
---|
244 | if ($OriginalText == null) $OriginalText = '';
|
---|
245 | $TargetText = $Line[$Column['Column']];
|
---|
246 | if ($TargetText == null) $Targettext = '';
|
---|
247 | $Original = $this->my_trim($OriginalText);
|
---|
248 | $Translated = $this->my_trim($TargetText);
|
---|
249 | if ($this->ClientVersion['Version'] == '2.4.3')
|
---|
250 | {
|
---|
251 | $Original = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Original);
|
---|
252 | $Translated = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Translated);
|
---|
253 | }
|
---|
254 | $Buffer .= 'f("'.addslashes($Line['ShortCut']).'", "'.$Original.'","'.$Translated.'");'."\n";
|
---|
255 | }
|
---|
256 |
|
---|
257 | if (!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/',0777, true);
|
---|
258 | file_put_contents($this->TempDir.'CzWoW/LocalizationStrings.lua', $Buffer);
|
---|
259 | }
|
---|
260 |
|
---|
261 | function MakeAddon(): string
|
---|
262 | {
|
---|
263 | if (!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);
|
---|
264 | $Output = $this->MakeLanguageFiles();
|
---|
265 | $Output .= $this->MakeClientStrings();
|
---|
266 | // $Output .= MakeMainScript($Setting);
|
---|
267 | return $Output;
|
---|
268 | }
|
---|
269 |
|
---|
270 | function MakeReadme(): void
|
---|
271 | {
|
---|
272 | $DbResult = $this->Database->query('SELECT * FROM `CzWoWPackageVersion` ORDER BY `Date` DESC');
|
---|
273 | $Line = $DbResult->fetch_assoc();
|
---|
274 |
|
---|
275 | $Buffer = '
|
---|
276 | Čeština pro klienty:
|
---|
277 | Vytvořeno v projektu https://wowpreklad.zdechov.net/
|
---|
278 | Obsahuje Fonty pro správné zobrazování českých znaků, WoW addon překládající
|
---|
279 | texty
|
---|
280 |
|
---|
281 | Instalace:
|
---|
282 | Soubory rozbalte/zkopírujte do kořenové složky s hrou. Obvikle bývá
|
---|
283 | "C:/Program Files/World of Warcraft/".
|
---|
284 |
|
---|
285 | Verze:
|
---|
286 | Verze Addonu: '.$Line['Version'].'
|
---|
287 | Tato verze je pro verzi hry '.$this->ClientVersion['Version'].'
|
---|
288 |
|
---|
289 | Změny ve verzích:
|
---|
290 |
|
---|
291 | ';
|
---|
292 | $DbResult = $this->Database->query('SELECT * FROM `CzWoWPackageVersion` ORDER BY `Date` DESC');
|
---|
293 | while ($Line = $DbResult->fetch_assoc())
|
---|
294 | {
|
---|
295 | $Buffer .='
|
---|
296 | Verze: '.$Line['Version'].'
|
---|
297 | =============
|
---|
298 | '.$Line['text'].'
|
---|
299 |
|
---|
300 | ';
|
---|
301 | }
|
---|
302 | file_put_contents($this->TempDir.'CZWOW-Readme.txt', $Buffer);
|
---|
303 | }
|
---|
304 | }
|
---|