* @copyright 2007-2015 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\Module\WidgetInterface; class Ps_Languageselector extends Module implements WidgetInterface { private $templateFile; public function __construct() { $this->name = 'ps_languageselector'; $this->author = 'PrestaShop'; $this->version = '2.0.2'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->trans('Language selector block', array(), 'Modules.Languageselector.Admin'); $this->description = $this->trans('Adds a block allowing customers to select a language for your store\'s content.', array(), 'Modules.Languageselector.Admin'); $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_); $this->templateFile = 'module:ps_languageselector/ps_languageselector.tpl'; } public function renderWidget($hookName = null, array $configuration = []) { $languages = Language::getLanguages(true, $this->context->shop->id); if (1 < count($languages)) { $this->smarty->assign($this->getWidgetVariables($hookName, $configuration)); return $this->fetch($this->templateFile); } return false; } public function getWidgetVariables($hookName = null, array $configuration = []) { $languages = Language::getLanguages(true, $this->context->shop->id); foreach ($languages as &$lang) { $lang['name_simple'] = $this->getNameSimple($lang['name']); } return array( 'languages' => $languages, 'current_language' => array( 'id_lang' => $this->context->language->id, 'name' => $this->context->language->name, 'name_simple' => $this->getNameSimple($this->context->language->name) ) ); } private function getNameSimple($name) { return preg_replace('/\s\(.*\)$/', '', $name); } }