ReplaceVarInText($string);
$string = str_replace("\r", ' ', $string);
$string = str_replace("\n", ' ', $string);
$string = str_replace('\\r', ' ', $string);
$string = str_replace('\\n', ' ', $string);
$string = str_replace(' ', '', $string);
return $string;
}
function ReplaceCzText(string $string): string
{
$string = $this->Database->real_escape_string($string);
$string = str_replace('$B', '\r\n', $string);
$string = str_replace('$b', '\r\n', $string);
$string = $this->ReplaceVarInText($string,'');
return $string;
}
function NotCancel(string $string): bool
{
if (strpos($string,'') > -1) return false;
else return true;
}
function my_trim(string $string): string
{
$string = addslashes($string);
$string = str_replace("\n", '\r\\'."\n",$string);
$string = str_replace("\r", '',$string);
$string = str_replace("\\\\\\", '\\\\',$string);
$string = str_replace("\\\\\\", '\\\\',$string);
$string = str_replace("\\\\\\", '\\\\',$string);
$string = str_replace("\\\\32", '\\32',$string);
$string = str_replace('\\\\"', '\\"',$string);
$string = str_replace('\\\\n', '\\n',$string);
$string = str_replace('\\\\124', '\\124',$string);
return $string;
}
function MakeLanguageFiles(): string
{
$TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
$Output = '';
$this->LoadFilters();
$CreatedFileList = array();
$CreatedFileListCount = array();
if (!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/', 0777, true);
$DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`TablePrefix` != ""');
while ($Group = $DbResult->fetch_assoc())
{
// získání čísla verze pro export
$ID = $this->Database->query('SELECT LastVersion FROM `Group` WHERE Id = '.$Group['Id']);
$LastVersion = $ID->fetch_assoc();
if ($LastVersion['LastVersion'] < $this->ClientVersion['BuildNumber'])
$ExportVersion = $LastVersion['LastVersion'];
else $ExportVersion = '';
foreach ($TranslationTree[$Group['Id']]['Items'] as $Column)
if ($Column['AddonFileName'] != '')
{
$this->AddProgress(1);
if (!isset($CreatedFileListCount[$Column['AddonFileName']]))
$CreatedFileListCount[$Column['AddonFileName']] = 0;
$CreatedFileListCount[$Column['AddonFileName']]++;
$FileIndex = $CreatedFileListCount[$Column['AddonFileName']];
$CreatedFileList[] = $Column['AddonFileName'].'_'.$FileIndex;
$FileName = $this->TempDir.'CzWoW/'.$Column['AddonFileName'].'_'.$FileIndex.'.lua';
$Output .= $Column['AddonFileName'].': ';
$i = 0;
$Buffer = 'CZWOW_'.$Column['AddonFileName'].'_count='.$FileIndex.';CZWOW_'.$Column['AddonFileName'].'_'.$FileIndex.'={';
$TableTexts = array();
// old version
// get version before
$BuildNumber = $ExportVersion;
if ($ExportVersion == '') $BuildNumber = $this->ClientVersion['BuildNumber'];
$ID = $this->Database->query('SELECT `BuildNumber` FROM `ClientVersion` WHERE '.
' `Imported` = 1 AND `BuildNumber` < '.$BuildNumber.' ORDER BY `BuildNumber` DESC LIMIT 1');
if ($ID->num_rows > 0)
{
$ExportVersionOld = $ID->fetch_assoc();
$ExportVersionOld = $ExportVersionOld['BuildNumber'];
$DbResult2 = $this->Database->query($this->BuildQuery($Group, $ExportVersionOld));
while ($Line = $DbResult2->fetch_assoc())
{
$Text = $Line['En'.$Column['Column']];
if ($Text == null) $Text = '';
$en = trim($this->ReplaceEnText($Text));
$Text = $Line[$Column['Column']];
if ($Text == null) $Text = '';
$cz = $this->ReplaceCzText($Text);
if (($en <> '') and ($cz <> '') and ($this->NotCancel($en)))
{
$TableTexts[$en] = $cz;
}
}
}
//last version
$DbResult2 = $this->Database->query($this->BuildQuery($Group, $ExportVersion));
while ($Line = $DbResult2->fetch_assoc())
{
$Text = $Line['En'.$Column['Column']];
if ($Text == null) $Text = '';
$en = trim($this->ReplaceEnText($Text));
$Text = $Line[$Column['Column']];
if ($Text == null) $Text = '';
$cz = $this->ReplaceCzText($Text);
if (($en <> '') and ($cz <> '') and ($this->NotCancel($en)))
{
$TableTexts[$en] = $cz;
}
}
foreach ($TableTexts as $key => $value)
{
$Buffer .= "\n".'["'.$key.'"]="'.$value.'",';
$i++;
}
$Buffer = $Buffer."\n};if not CZWOW_".$Column['AddonFileName']." then CZWOW_".$Column['AddonFileName']."=0; end; CZWOW_".$Column['AddonFileName']."=CZWOW_".$Column['AddonFileName']."+".$i.";\n";
file_put_contents($FileName, $Buffer);
$Output .= 'Hotovo
';
}
}
// Generete list file of translated
$CountFiles = 'CountFiles.lua';
$Buffer = '';
foreach ($CreatedFileList as $CreatedFile)
{
$Buffer .= 'CZWOW_'.str_replace('_','_count=',$CreatedFile).';'."\n";
}
foreach ($TranslationTree as $Group)
{
foreach ($TranslationTree[$Group['Id']]['Items'] as $Column)
{
if (($Column['AddonFileName'] != '') and (!in_array($Column['AddonFileName'].'_1', $CreatedFileList)))
{
$Buffer .= 'CZWOW_'.$Column['AddonFileName'].'_count=0;'."\n";
}
}
}
file_put_contents($this->TempDir.'CzWoW/'.$CountFiles, $Buffer);
// Generate file Translates.xml
$Buffer = ''."\n";
$Buffer .= ''."\n";
foreach ($CreatedFileList as $CreatedFile)
{
$Buffer .= ''."\n";
}
$Buffer .= '';
file_put_contents($this->TempDir.'CzWoW/Translates.xml', $Buffer);
return $Output;
}
function MakeClientStrings(): void
{
$TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
$this->LoadFilters();
$Buffer = "local f=function(name, en, cz) CzWoW_interface[name]=cz;CzWoW_interface_entoname[en]=name; end; CzWoW_interface={};CzWoW_interface_entoname={ };\n";
$Group = $TranslationTree[14]; // client table
$Column['Column'] = 'Text';
$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');
if ($DbResult->num_rows == 0)
$CanGenerated = '-1';
else
$CanGenerated = '';
$DbResult = $this->Database->query($this->BuildQuery($Group,$CanGenerated));
while ($Line = $DbResult->fetch_array())
{
$OriginalText = $Line['En'.$Column['Column']];
if ($OriginalText == null) $OriginalText = '';
$TargetText = $Line[$Column['Column']];
if ($TargetText == null) $Targettext = '';
$Original = $this->my_trim($OriginalText);
$Translated = $this->my_trim($TargetText);
if ($this->ClientVersion['Version'] == '2.4.3')
{
$Original = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Original);
$Translated = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Translated);
}
$Buffer .= 'f("'.addslashes($Line['ShortCut']).'", "'.$Original.'","'.$Translated.'");'."\n";
}
if (!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/',0777, true);
file_put_contents($this->TempDir.'CzWoW/LocalizationStrings.lua', $Buffer);
}
function MakeAddon(): string
{
if (!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);
$Output = $this->MakeLanguageFiles();
$Output .= $this->MakeClientStrings();
// $Output .= MakeMainScript($Setting);
return $Output;
}
function MakeReadme(): void
{
$DbResult = $this->Database->query('SELECT * FROM `CzWoWPackageVersion` ORDER BY `Date` DESC');
$Line = $DbResult->fetch_assoc();
$Buffer = '
Čeština pro klienty:
Vytvořeno v projektu https://wowpreklad.zdechov.net/
Obsahuje Fonty pro správné zobrazování českých znaků, WoW addon překládající
texty
Instalace:
Soubory rozbalte/zkopírujte do kořenové složky s hrou. Obvikle bývá
"C:/Program Files/World of Warcraft/".
Verze:
Verze Addonu: '.$Line['Version'].'
Tato verze je pro verzi hry '.$this->ClientVersion['Version'].'
Změny ve verzích:
';
$DbResult = $this->Database->query('SELECT * FROM `CzWoWPackageVersion` ORDER BY `Date` DESC');
while ($Line = $DbResult->fetch_assoc())
{
$Buffer .='
Verze: '.$Line['Version'].'
=============
'.$Line['text'].'
';
}
file_put_contents($this->TempDir.'CZWOW-Readme.txt', $Buffer);
}
}