* @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) exit; use PrestaShop\PrestaShop\Core\Addon\Theme\ThemeManagerBuilder; if (file_exists(dirname(__FILE__).'/classes/XliffFileDumper.php')) { require_once dirname(__FILE__).'/classes/XliffFileDumper.php'; } class StXlfGenerator extends Module { private $theme = 'panda'; private $light = true; public static $modules = array( array('val'=>'stbanner', 'id'=>'[]', 'name'=>'stbanner'), array('val'=>'stbestsellers', 'id'=>'[]', 'name'=>'stbestsellers'), array('val'=>'stcompare', 'id'=>'[]', 'name'=>'stcompare'), array('val'=>'stblog', 'id'=>'[]', 'name'=>'stblog'), array('val'=>'stblogarchives', 'id'=>'[]', 'name'=>'stblogarchives'), array('val'=>'stblogblockcategory', 'id'=>'[]', 'name'=>'stblogblockcategory'), array('val'=>'stblogcomments', 'id'=>'[]', 'name'=>'stblogcomments'), array('val'=>'stblogeditor', 'id'=>'[]', 'name'=>'stblogeditor'), array('val'=>'stblogfeaturedarticles', 'id'=>'[]', 'name'=>'stblogfeaturedarticles'), array('val'=>'stbloglinknav', 'id'=>'[]', 'name'=>'stbloglinknav'), array('val'=>'stblogrecentarticles', 'id'=>'[]', 'name'=>'stblogrecentarticles'), array('val'=>'stblogrelatedarticles', 'id'=>'[]', 'name'=>'stblogrelatedarticles'), array('val'=>'stblogsearch', 'id'=>'[]', 'name'=>'stblogsearch'), array('val'=>'stblogtags', 'id'=>'[]', 'name'=>'stblogtags'), array('val'=>'stbrandsslider', 'id'=>'[]', 'name'=>'stbrandsslider'), array('val'=>'stcountdown', 'id'=>'[]', 'name'=>'stcountdown'), array('val'=>'stcurrencyselector', 'id'=>'[]', 'name'=>'stcurrencyselector'), array('val'=>'stcustomersignin', 'id'=>'[]', 'name'=>'stcustomersignin'), array('val'=>'steasycontent', 'id'=>'[]', 'name'=>'steasycontent'), array('val'=>'stfblikebox', 'id'=>'[]', 'name'=>'stfblikebox'), array('val'=>'stfeaturedcategories', 'id'=>'[]', 'name'=>'stfeaturedcategories'), array('val'=>'stfeaturedslider', 'id'=>'[]', 'name'=>'stfeaturedslider'), array('val'=>'sthomenew', 'id'=>'[]', 'name'=>'sthomenew'), array('val'=>'sthoverimage', 'id'=>'[]', 'name'=>'sthoverimage'), array('val'=>'stinstagram', 'id'=>'[]', 'name'=>'stinstagram'), array('val'=>'stlanguageselector', 'id'=>'[]', 'name'=>'stlanguageselector'), array('val'=>'stlovedproduct', 'id'=>'[]', 'name'=>'stlovedproduct'), array('val'=>'stmegamenu', 'id'=>'[]', 'name'=>'stmegamenu'), array('val'=>'stmultilink', 'id'=>'[]', 'name'=>'stmultilink'), array('val'=>'stnewsletter', 'id'=>'[]', 'name'=>'stnewsletter'), array('val'=>'stnotification', 'id'=>'[]', 'name'=>'stnotification'), array('val'=>'stoverride', 'id'=>'[]', 'name'=>'stoverride'), array('val'=>'stowlcarousel', 'id'=>'[]', 'name'=>'stowlcarousel'), array('val'=>'stpagebanner', 'id'=>'[]', 'name'=>'stpagebanner'), array('val'=>'stproductcategoriesslider', 'id'=>'[]', 'name'=>'stproductcategoriesslider'), array('val'=>'stproductcomments', 'id'=>'[]', 'name'=>'stproductcomments'), array('val'=>'stproductlinknav', 'id'=>'[]', 'name'=>'stproductlinknav'), array('val'=>'stqrcode', 'id'=>'[]', 'name'=>'stqrcode'), array('val'=>'strelatedproducts', 'id'=>'[]', 'name'=>'strelatedproducts'), array('val'=>'stsearchbar', 'id'=>'[]', 'name'=>'stsearchbar'), array('val'=>'stshoppingcart', 'id'=>'[]', 'name'=>'stshoppingcart'), array('val'=>'stsidebar', 'id'=>'[]', 'name'=>'stsidebar'), array('val'=>'stsocial', 'id'=>'[]', 'name'=>'stsocial'), array('val'=>'stspecialslider', 'id'=>'[]', 'name'=>'stspecialslider'), array('val'=>'ststickers', 'id'=>'[]', 'name'=>'ststickers'), array('val'=>'stswiper', 'id'=>'[]', 'name'=>'stswiper'), array('val'=>'sttags', 'id'=>'[]', 'name'=>'sttags'), array('val'=>'stthemeeditor', 'id'=>'[]', 'name'=>'stthemeeditor'), array('val'=>'sttwitterembeddedtimelines', 'id'=>'[]', 'name'=>'sttwitterembeddedtimelines'), array('val'=>'stvideo', 'id'=>'[]', 'name'=>'stvideo'), array('val'=>'stviewedproducts', 'id'=>'[]', 'name'=>'stviewedproducts'), array('val'=>'stwishlist', 'id'=>'[]', 'name'=>'stwishlist'), array('val'=>'stxlfgenerator', 'id'=>'[]', 'name'=>'stxlfgenerator'), ); function __construct() { $this->name = 'stxlfgenerator'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'SUNNYTOO.COM'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->getTranSlator()->trans('Translation files generator', array(), 'Modules.Stxlfgenerator.Admin'); $this->description = $this->getTranSlator()->trans('Generate xlif files in order to translate the theme.', array(), 'Modules.Stxlfgenerator.Admin'); $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); } function install() { return parent::install(); } function uninstall() { return parent::uninstall(); } public function getContent() { $output = ''; $errors = array(); if (Tools::isSubmit('generatefiles')) { $locale = Tools::getValue('locale','en-US'); if ($this->light) { $modules = array(); foreach(self::$modules AS $value) { $modules[] = $value['val']; } $options = array( 'theme' => $this->theme, 'theme_module' => 0, 'locale' => $locale, 'modules' => $modules, 'type' => Tools::getValue('type'), 'check_missing' => 0, 'tpl_path' => _PS_ALL_THEMES_DIR_.$this->theme.'/templates/', ); } else { $options = array( 'theme' => Tools::getValue('theme'), 'theme_module' => Tools::getValue('theme_module'), 'locale' => $locale, 'modules' => Tools::getValue('module_'), 'type' => Tools::getValue('type', 1), 'check_missing' => Tools::getValue('check_missing', 0), 'tpl_path' => _PS_ALL_THEMES_DIR_.$this->theme.'/templates/', ); } $save_path = _PS_ALL_THEMES_DIR_.$this->theme.'/translations/'.$locale.'/'; $dumper = new XliffFileDumper($save_path); // Clear modules translation files & theme files.. $dumper->clearFiles($save_path, 'ModulesSt'); $dumper->clearFiles($save_path, ucfirst($this->theme)); if ($dumper->dump($options)) { // Copy Xliff file /app/Resources/translations/default $des = _PS_CORE_DIR_.'/app/Resources/translations/default/'; $dumper->CopyFiles($save_path, $des, 'ModulesSt', $locale); $dumper->CopyFiles($save_path, $des, 'AdminTheme'.ucfirst($this->theme), $locale); // Copy Xliff file to app/Resources/translations/locale $des = _PS_CORE_DIR_.'/app/Resources/translations/'.$locale.'/'; $dumper->CopyFiles($save_path, $des, 'ModulesSt', $locale, false); $dumper->CopyFiles($save_path, $des, 'AdminTheme'.ucfirst($this->theme), $locale, false); $output = $this->displayConfirmation('Translatoin files successfully generated, files were saved in '.$save_path.'.'); } else { $output = $this->displayError('Error occurred.'); } } return $output.$this->renderForm(); } public function renderForm() { $languages = array(); $themes_array = array(); foreach(Language::getLanguages(false) AS $value) { $language['id'] = $value['locale']; $language['name'] = $value['name']; $languages[] = $language; } if ($this->light) { $this->fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->getTranSlator()->trans('Translation file generator', array(), 'Modules.Stxlfgenerator.Admin'), 'icon' => 'icon-cogs', ), 'input' => array( array( 'type' => 'select', 'label' => $this->getTranSlator()->trans('Select language:', array(), 'Modules.Stxlfgenerator.Admin'), 'name' => 'locale', 'options' => array( 'query' => $languages, 'id' => 'id', 'name' => 'name', ), 'desc' => '