die; } $source_folder = $argv[1]; $lang = $argv[2]; $output_folder = $argv[3]; $translation_xml_file = $argv[4]; if (!is_dir($source_folder)) { echo 'Error: source folder ' . $source_folder . ' does not exist' . PHP_EOL; die; } if (!in_array($lang, $accepted_languages)) { echo 'Error: language ' . $lang . ' not supported' . PHP_EOL; die; } template_set_errors_visible(); template_set_warnings_visible(); echo 'Translation of *all* templates in ' . $source_folder . ' will now start.' . PHP_EOL; echo 'Output language: ' . $lang . PHP_EOL . PHP_EOL; $files = template_list_files($source_folder); // // Parsing each template file // foreach ($files as $file) { //echo 'Translating ' . $file . '...' . PHP_EOL; template_parse($file, $lang, $output_folder, $translation_xml_file); //echo 'Translation complete' . PHP_EOL . PHP_EOL; } if (template_last_error() != '' || template_last_warning() != '') { echo PHP_EOL; } echo 'Translation finished, you can find your files in \'' . $output_folder . '/' . $lang . '\'' . PHP_EOL;
/** * Returns all the HTML files within the $source_folder folder * @param string $source_folder * @return array List of filenames to template files */ function template_list_files($source_folder) { if (!is_dir($source_folder)) { template_last_error("{$source_folder} is not a directory"); return false; } //get all file&dir from the source template dir $folder = glob($source_folder . '/*'); $res = array(); foreach ($folder as $entry) { if (is_dir($entry)) { $res = array_merge($res, template_list_files($entry)); } else { $res[] = $entry; } } return $res; }