Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rbbrioso28 committed Feb 3, 2020
2 parents bf07fb3 + ef33ac5 commit 365d793
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 13 deletions.
3 changes: 2 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
'MinifyAssets' => 'MelisFront\Service\Factory\MinifyAssetsServiceFactory',
'MelisSiteTranslationService' => 'MelisFront\Service\Factory\MelisSiteTranslationServiceFactory',
'MelisSiteConfigService' => 'MelisFront\Service\Factory\MelisSiteConfigServiceFactory',

'MelisTranslationService' => 'MelisFront\Service\Factory\MelisTranslationServiceFactory',
'MelisFront\Listener\MelisFront404To301Listener' => 'MelisFront\Listener\Factory\MelisFront404To301ListenerFactory',
),
),
Expand Down Expand Up @@ -216,6 +216,7 @@
'MelisPageLangLink' => 'MelisFront\View\Helper\Factory\MelisPageLangVersionLinkHelperFactory',
'MelisHomePageLink' => 'MelisFront\View\Helper\Factory\MelisHomePageLinkHelperFactory',
'siteTranslate' => 'MelisFront\View\Helper\Factory\MelisSiteTranslationHelperFactory',
'boTranslate' => 'MelisFront\View\Helper\Factory\MelisTranslationHelperFactory',
'SiteConfig' => 'MelisFront\View\Helper\Factory\SiteConfigViewHelperFactory',
'MelisGdprBannerPlugin' => 'MelisFront\View\Helper\Factory\MelisGdprBannerHelperFactory',
'MelisListFromFolderPlugin' => 'MelisFront\View\Helper\Factory\MelisListFromFolderHelperFactory',
Expand Down
26 changes: 14 additions & 12 deletions src/Controller/MelisSiteActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MelisSiteActionController extends AbstractActionController

public function onDispatch(MvcEvent $event)
{

$this->idPage = $this->params()->fromRoute('idpage');
$this->renderType = $this->params()->fromRoute('renderType');
if (empty($this->renderType))
Expand Down Expand Up @@ -79,23 +80,24 @@ public function onDispatch(MvcEvent $event)
$siteLang = $melisEnginLangService->getSiteLanguage();
$siteLangId = $siteLang['langId'];
$siteLangLocale = $siteLang['langLocale'];

$this->layout()->setVariables(array(
'idPage' => $this->idPage,
'renderType' => $this->renderType,
'renderMode' => $this->renderMode,
'pageLangId' => $this->pageLangId,
'pageLangLocale' => $this->pageLangLocale,
'pageBreadCrumb' => $pageBreadCrumb,
'mainPageId' => $mainPageId,
'pageTemplate' => $pageTemplate,
'siteLangId' => $siteLangId,
'siteLangLocale' => $siteLangLocale,
'idPage' => $this->idPage,
'renderType' => $this->renderType,
'renderMode' => $this->renderMode,
'pageLangId' => $this->pageLangId,
'pageLangLocale' => $this->pageLangLocale,
'pageBreadCrumb' => $pageBreadCrumb,
'mainPageId' => $mainPageId,
'pageTemplate' => $pageTemplate,
'siteLangId' => $siteLangId,
'siteLangLocale' => $siteLangLocale,
'preview' => $this->params()->fromRoute('preview')
));

$this->oMelisPage = $datasPage;
}

return parent::onDispatch($event);
}

Expand Down
19 changes: 19 additions & 0 deletions src/Listener/MelisFrontMiniTemplateConfigListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,31 @@ public function onLoadModulesPost(ModuleEvent $e)
*/
public function prepareMiniTemplateConfig($miniTplPath)
{
$image_ext = ['PNG', 'png', 'JPG', 'jpg', 'JPEG', 'jpeg'];
$pluginsFormat = array();
foreach($miniTplPath as $siteName => $path) {
if (file_exists($path) && is_dir($path)) {
$tplImgList = [];
//get the plugin config format
$pluginsConfig = include __DIR__ . '/../../config/plugins/MiniTemplatePlugin.config.php';
if (!empty($pluginsConfig)) {
//get all the mini template
$tpls = array_diff(scandir($path), array('..', '.'));
/**
* Remove all the images
*/
foreach ($tpls as $key => $tpl){
foreach($image_ext as $ext){
//if image found, store the image path with the template name as the key
if(strpos($tpl, $ext) !== false) {
$fName = pathinfo($tpl, PATHINFO_FILENAME);
$tplImgList[$fName] = '/'.$siteName.'/miniTemplatesTinyMce/'.$fName.'.'.$ext;
//remove the image
unset($tpls[$key]);
}
}
}

if (!empty($tpls)) {
//set the site name as sub category title
$pluginsConfig['melis']['subcategory']['title'] = $siteName;
Expand All @@ -135,6 +152,8 @@ public function prepareMiniTemplateConfig($miniTplPath)
$pluginsConfig['front']['default'] = file_get_contents($content);
//set the plugin name using the template name
$pluginsConfig['melis']['name'] = $name;
//apply minitemplate thumbnail
$pluginsConfig['melis']['thumbnail'] = $tplImgList[$name] ?? '/MelisFront/plugins/images/default.jpg';
//include the mini tpl plugin config
$pluginsFormat['plugins']['MelisMiniTemplate']['plugins']['MiniTemplatePlugin_' . $postName] = $pluginsConfig;
}
Expand Down
27 changes: 27 additions & 0 deletions src/Service/Factory/MelisTranslationServiceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* Melis Technology (http://www.melistechnology.com)
*
* @copyright Copyright (c) 2018 Melis Technology (http://www.melistechnology.com)
*
*/

namespace MelisFront\Service\Factory;

use MelisFront\Service\MelisTranslationService;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;

class MelisTranslationServiceFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $sl)
{
$moduleSvc = $sl->get('MelisAssetManagerModulesService');
$melisTranslationService = new MelisTranslationService($moduleSvc);
$melisTranslationService->setServiceLocator($sl);

return $melisTranslationService;
}

}
154 changes: 154 additions & 0 deletions src/Service/MelisTranslationService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php

/**
* Melis Technology (http://www.melistechnology.com)
*
* @copyright Copyright (c) 2020 Melis Technology (http://www.melistechnology.com)
*
*/

namespace MelisFront\Service;

use MelisAssetManager\Service\MelisModulesService;
use MelisEngine\Service\MelisEngineGeneralService;
use Zend\Session\Container;

class MelisTranslationService extends MelisEngineGeneralService
{
/** @var MelisModulesService */
private $moduleSvc;

public function __construct(MelisModulesService $moduleService)
{
$this->moduleSvc = $moduleService;
}

/**
*
* get all module translations by locale
*
* @param string $locale
* @return array
*/
public function getTranslationsByLocale($locale = "en_EN")
{
// Event parameters prepare
$arrayParameters = $this->makeArrayFromParameters(__METHOD__, func_get_args());
// Sending service start event
$arrayParameters = $this->sendEvent('melis_translation_get_trans_by_locale_start', $arrayParameters);
$transMessages = [];
$tmpTrans = [];
$modules = $this->moduleSvc->getAllModules();
$locale = $arrayParameters['locale'];
$moduleFolders = [];
// get modules path
foreach ($modules as $module)
{
array_push($moduleFolders, $this->moduleSvc->getModulePath($module));
}

$transFiles = array(
$locale.'.interface.php',
$locale.'.forms.php',
);
$insideDirTrans = [];
set_time_limit(0);
foreach($moduleFolders as $module) {
if(file_exists($module.'/language')) {
foreach($transFiles as $file) {
if(file_exists($module.'/language/'.$file)) {
$tmpTrans[] = include($module.'/language/'.$file);
}
}
// get the directory
$iterator = new \RecursiveDirectoryIterator($module . "/language", \RecursiveDirectoryIterator::SKIP_DOTS);
$files = new \RecursiveIteratorIterator($iterator,\RecursiveIteratorIterator::CHILD_FIRST);
/** @var \SplFileInfo $file */
// get the files under the directory
foreach($files as $file) {
if (stristr($file->getBasename(),$locale)){
// get the translation based on locale
$tmpTrans[]= include $file->getFileInfo()->getPathname();
} else if (stristr($file->getBasename(),"en_EN")){
// fall back locale
$tmpTrans[] = include $file->getFileInfo()->getPathname();
}
}

}
}

if($tmpTrans) {
foreach($tmpTrans as $tmpIdx => $transKey) {
foreach($transKey as $key => $value) {
$transMessages[$key] = $value;
}
}
}
// results
$arrayParameters['results'] = $transMessages;
// send event
$arrayParameters = $this->sendEvent('melis_translation_get_trans_by_locale_end', $arrayParameters);

return $arrayParameters['results'];

}

/**+
*
*
* get translations by key and locale
*
* @param $translationKey
* @param string $locale
* @return mixed
*/
public function translateByLocale($translationKey, $locale = "en_EN")
{
// Event parameters prepare
$arrayParameters = $this->makeArrayFromParameters(__METHOD__, func_get_args());
// Sending service start event
$arrayParameters = $this->sendEvent('trans_by_locale_start', $arrayParameters);
$text = $translationKey;
// check translation key in the translations
$translations = $this->getTranslationsByLocale($locale);
if (array_key_exists($translationKey, $translations)) {
$text = $translations[$translationKey];
}

// results
$arrayParameters['results'] = $text;
// send event
$arrayParameters = $this->sendEvent('trans_by_locale_end', $arrayParameters);

return $arrayParameters['results'];
}

/**
* translate translationkey based from Back-office locale
* @param $translationKey
* @return mixed
*/
public function boTranslate($translationKey)
{
// Event parameters prepare
$arrayParameters = $this->makeArrayFromParameters(__METHOD__, func_get_args());
// Sending service start event
$arrayParameters = $this->sendEvent('bo_translate_start', $arrayParameters);
$text = $translationKey;
// get bo locale
$melisBoContainer = new Container('meliscore');
// check translation key in the translations
$translations = $this->getTranslationsByLocale($melisBoContainer['melis-lang-locale']);
if (array_key_exists($translationKey, $translations)) {
$text = $translations[$translationKey];
}

// results
$arrayParameters['results'] = $text;
// send event
$arrayParameters = $this->sendEvent('bo_translate_end', $arrayParameters);

return $arrayParameters['results'];
}
}
27 changes: 27 additions & 0 deletions src/View/Helper/Factory/MelisTranslationHelperFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* Melis Technology (http://www.melistechnology.com)
*
* @copyright Copyright (c) 2019 Melis Technology (http://www.melistechnology.com)
*
*/

namespace MelisFront\View\Helper\Factory;

use MelisFront\View\Helper\MelisTranslationHelper;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;

class MelisTranslationHelperFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $sl
* @return MelisTranslationHelper|mixed
*/
public function createService(ServiceLocatorInterface $sl)
{
return new MelisTranslationHelper($sl->getServiceLocator());
}

}
37 changes: 37 additions & 0 deletions src/View/Helper/MelisTranslationHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace MelisFront\View\Helper;

use MelisEngine\Service\MelisPageService;
use MelisFront\Service\MelisTranslationService;
use Zend\Session\Container;
use Zend\View\Helper\AbstractHelper;

class MelisTranslationHelper extends AbstractHelper
{
public $serviceManager;

public function __construct($sm)
{
$this->serviceManager = $sm;
}

public function __invoke($translationKey , $locale = null)
{
$text = "";
// melis translation view helper
/** @var MelisTranslationService $melisTrans */
$melisTrans = $this->serviceManager->get('MelisTranslationService');
if (! empty($locale)) {
$text = $melisTrans->translateByLocale($translationKey,$locale);
} else {
// get melis back office locale
$melisCoreLang = new Container('meliscore');
// get translation
$text = $melisTrans->translateByLocale($translationKey,$melisCoreLang['melis-lang-locale']);
}

return $text;
}

}

0 comments on commit 365d793

Please sign in to comment.