$folderEntry, 'path' => $folder.'/'.$folderEntry); } } } return $listArray; }else{ return array(); } } function getDefenitionsFromFiles($files) { $defenitions = array(); foreach($files as $file) { $handle = @fopen($file['path'], "r"); // Go trough every line of file if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); // Is there any define language construct $defineOffset = stripos($buffer, 'define('); if ($defineOffset !== false) { // Remove define keyword from the start of language line $buffer = substr($buffer, strpos($buffer, '(')+1); // Remove define( $temp = explode(',', $buffer); // Trim translation and remove ) from the end if (count($temp > 1)) { // Concat strings if there are more then one , in string which was exploded if (count($temp) > 2) { for($i=2; $i < count($temp); $i++) { $temp[1] .= ','.$temp[$i]; } } // Add translation to array of translation for current file, remove ' ', " " from keyword $keyword = str_replace(array("'", '"'), '', $temp[0]); $translation = substr(trim($temp[1]), 0, -2); // remove ");" add the end of translation $defenitions[$file['path']][$keyword] = $translation; } } } fclose($handle); } } return $defenitions; } // Settings header('Content-Type: text/html; charset=utf-8' ); error_reporting(E_ALL | E_STRICT); $phpEnd = '?>'; $translateToEncoding = 'UTF-8'; $previousEncodings = 'ISO-8859-2,ISO-8859-1'; $languageFileExtension = '.php'; // Set new file path for files - don't overwrite previous files! - you will do that manually $newFolderPathPrefix = 'jeziki'; $primaryLanguagePath = 'includes/languages/english'; // default language from your CMS $secondaryLanguagePath = 'includes/languages/slovensko'; // language to which you are translating ... //Admin //$primaryLanguagePath = 'admin/includes/languages/english'; //$secondaryLanguagePath = 'admin/includes/languages/slovensko'; // Unlink secondary files at our own directory @unlink($newFolderPathPrefix . '/' . $secondaryLanguagePath); // Which languages are we translation (directory name) $primaryLanguage = 'english'; $secondaryLanguage = 'slovensko'; // Get language files for zen cart english and slovensko $engLanguageFiles = getFilesFrom($primaryLanguagePath, $languageFileExtension); $sloLanguageFiles = getFilesFrom($secondaryLanguagePath, $languageFileExtension); // Get defenitions from these files $engDefenitions = getDefenitionsFromFiles($engLanguageFiles); $sloDefenitions = getDefenitionsFromFiles($sloLanguageFiles); // Go trough english files which are used as a reference and check if the translation is included in slovene files foreach($engDefenitions as $file => $defenitions) { // Does the slovene file exsists? $tempFilePath = str_replace($primaryLanguage, $secondaryLanguage, $file); if (isset($sloDefenitions[$tempFilePath])) { foreach($defenitions as $keyword => $translation) { // This translation keyword is missing, add to the end of the line if (!isset($sloDefenitions[$tempFilePath][$keyword])) { $oldSloFilePath = $tempFilePath; $newSloFilePath = $newFolderPathPrefix . '/' . $oldSloFilePath; // Create new dirs rmkdir($newSloFilePath, 0777); // Get old data, remove end of php and add missing lanugage file if (file_exists($newSloFilePath)) { $oldSloFilePath = $newSloFilePath; // if there are more then one missing keyword, add to the newly created lang data at previous keyword } $sloLangData = file_get_contents($oldSloFilePath); $sloLangData = substr($sloLangData, 0, strrpos($sloLangData, $phpEnd)); $sloLangData .= "\ndefine('{$keyword}', {$translation});//Added by PHP\n?>"; // Create new file with that missing translation file_put_contents($newSloFilePath, $sloLangData); } } } } // Check if file was moved by translation above, if not file was exactly the same. Move it now .. foreach($engLanguageFiles as $file) { // Does the slovene file exsists? $tempFilePath = str_replace($primaryLanguage, $secondaryLanguage, $file['path']); if (isset($sloDefenitions[$tempFilePath])) { $sloLangData = file_get_contents($tempFilePath); } else { $sloLangData = file_get_contents($file['path']); } $newSloFilePath = $newFolderPathPrefix . '/' . $tempFilePath; if (!file_exists($newSloFilePath)) { rmkdir($newSloFilePath, 0777); file_put_contents($newSloFilePath, $sloLangData); } } // Translate files after all translations are included now $sloLanguageFiles = getFilesFrom($newFolderPathPrefix . '/' . $secondaryLanguagePath); foreach($sloLanguageFiles as $file) { // Get new lang data $sloLangData = file_get_contents($file['path']); // Check in which encoding is slovene language file. If it is in diffrent then $translateToEncoding then use iconv $oldEncoding = mb_detect_encoding($sloLangData, $previousEncodings); if ($oldEncoding !== $translateToEncoding) { $sloLangData = iconv($oldEncoding, $translateToEncoding, $sloLangData); // Create new file with right encoding file_put_contents($file['path'], $sloLangData); } } function rmkdir($path, $mode = 0777) { $folders = explode('/', $path); $path = ''; foreach($folders as $folder) { $path .= ($folder . '/'); if (!is_dir($path) && stripos($path, '.') === false) { mkdir($path, $mode); } } } function dump ($var, $withVarTypes = false) { if ($withVarTypes) { ob_start(); var_dump ($var); $var = ob_get_contents(); ob_end_clean(); } // Instead of returning empty string on boolean false and true, return (bool)true string $var = ($var === true) ? '(bool)true' : $var; $var = ($var === false) ? '(bool)false' : $var; echo '
'. htmlspecialchars ($withVarTypes ? $var : print_r ($var, true)). ''; } ?>