Skip to content

Commit

Permalink
Merge pull request #9 from NicolasBarbey/main
Browse files Browse the repository at this point in the history
Thelia 2.5 compatibility
  • Loading branch information
julescournut authored Oct 7, 2021
2 parents d7711e3 + 697b905 commit 41385f8
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<form name="translation-extension-form" class="Translation\Form\ExtensionForm" />
</forms>

<services>
<!--<services>
<service id="translation.boot.listener" class="Translation\EventListeners\BootListener">
<argument type="service" id="thelia.translator" />
<tag name="kernel.event_subscriber"/>
</service>
</services>
</services>-->

<hooks>
<hook id="translation.hook" class="Translation\Hook\AdminHook">
Expand Down
4 changes: 2 additions & 2 deletions Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.0.5</version>
<version>2.0.0</version>
<authors>
<author>
<name>Vincent Lopes-Vicente, Nicolas Barbey</name>
Expand All @@ -34,7 +34,7 @@
</author>
</authors>
<type>classic</type>
<thelia>2.3.0</thelia>
<thelia>2.5.0</thelia>
<stability>other</stability>
<mandatory>0</mandatory>
<hidden>0</hidden>
Expand Down
4 changes: 2 additions & 2 deletions Config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="admin.translation.menu" path="/admin/module/translation">
<!--<route id="admin.translation.menu" path="/admin/module/translation">
<default key="_controller">Translation\Controller\AdminController::showPage</default>
</route>
Expand All @@ -22,5 +22,5 @@
<route id="translation.extension" path="/admin/module/translation/extension">
<default key="_controller">Translation\Controller\AdminController::setExtensionAction</default>
</route>
</route>-->
</routes>
16 changes: 15 additions & 1 deletion Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
use Thelia\Tools\URL;
use Translation\Form\ExtensionForm;
use Translation\Translation;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/admin/module/translation", name="admin_translation")
*/

class AdminController extends BaseAdminController
{

/**
* @Route("", name="_menu", methods="GET")
*/
public function showPage()
{
// Is the module active ?
Expand All @@ -26,9 +34,12 @@ public function showPage()
return $this->render('Translation/translation', ['in_use' => $translationInUse]);
}

/**
* @Route("/extension", name="_extension", methods="POST")
*/
public function setExtensionAction()
{
$form = new ExtensionForm($this->getRequest());
$form = $this->createForm(ExtensionForm::getName());

$extensionForm = $this->validateForm($form);

Expand All @@ -39,6 +50,9 @@ public function setExtensionAction()
return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/translation'));
}

/**
* @Route("/revert", name="_revert", methods="GET")
*/
public function revertAction()
{
$fs = new Filesystem();
Expand Down
36 changes: 22 additions & 14 deletions Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Translation\Controller;


use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Translation\Dumper\PhpFileDumper;
use Symfony\Component\Translation\Dumper\XliffFileDumper;
Expand All @@ -11,6 +14,7 @@
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\Translation\TranslationEvent;
use Thelia\Core\Template\TemplateDefinition;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;
use Thelia\Model\Module;
Expand All @@ -19,32 +23,38 @@
use Translation\Dumper\PoFileDumperWithComments;
use Translation\Form\ExportForm;
use Translation\Translation;
use Symfony\Component\Routing\Annotation\Route;


/**
* @Route("/admin/module/translation/export", name="admin_translation_export")
*/
class ExportController extends BaseAdminController
{
/**
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Exception
* @Route("", name="", methods="POST")
*/
public function exportAction()
public function exportAction(RequestStack $requestStack, EventDispatcherInterface $dispatcher)
{
$translationsArchiveDir = Translation::TRANSLATIONS_DIR . 'archives';
$translationsTempDir = Translation::TRANSLATIONS_DIR . 'tmp';

if (! file_exists($translationsArchiveDir)){
mkdir($translationsArchiveDir, 0777, true);
$fs = new Filesystem();

if (!file_exists($translationsArchiveDir)){
$fs->mkdir($translationsArchiveDir);
}

if (! file_exists($translationsTempDir)){
mkdir($translationsTempDir, 0777, true);
$fs->mkdir($translationsTempDir);
}

$form = new ExportForm($this->getRequest());
$form = $this->createForm(ExportForm::getName());

$exportForm = $this->validateForm($form);

$lang = LangQuery::create()->filterById($this->getRequest()->get('lang_id'))->findOne();
$lang = LangQuery::create()->filterById($requestStack->getCurrentRequest()->get('lang_id'))->findOne();

$dirs = $exportForm->get('directories')->getData();
$ext = Translation::getConfigValue('extension');
Expand All @@ -60,7 +70,7 @@ public function exportAction()
];
}
foreach ($dirs as $dir) {
$this->exportTranslations($dir, $ext, $lang, $translationsTempDir);
$this->exportTranslations($dir, $ext, $lang, $translationsTempDir, $requestStack, $dispatcher);
}

if (file_exists($translationsTempDir.DS.$ext)){
Expand Down Expand Up @@ -100,7 +110,7 @@ public function exportAction()
} else {
$this->setupFormErrorContext(
'No translation' ,
$this->getTranslator()->trans('No translation found'),
Translator::getInstance()->trans('No translation found'),
$form
);

Expand All @@ -120,7 +130,7 @@ public function exportAction()
* @param $tmpDir
* @throws \Exception
*/
protected function exportTranslations($dir, $ext, Lang $lang, $tmpDir)
protected function exportTranslations($dir, $ext, Lang $lang, $tmpDir, RequestStack $requestStack, EventDispatcherInterface $dispatcher)
{
$items = [];

Expand All @@ -136,7 +146,7 @@ protected function exportTranslations($dir, $ext, Lang $lang, $tmpDir)
case 'backOffice':
case 'email':
case 'pdf' :
$templateDir = $this->getRequest()->get($dir.'_directory_select');
$templateDir = $requestStack->getCurrentRequest()->get($dir.'_directory_select');
$templateName = $this->camelCaseToUpperSnakeCase($dir);
$template = new TemplateDefinition(
$templateDir,
Expand Down Expand Up @@ -188,7 +198,7 @@ protected function exportTranslations($dir, $ext, Lang $lang, $tmpDir)

$keyMetaData = [];

$this->getDispatcher()->dispatch(TheliaEvents::TRANSLATION_GET_STRINGS, $event);
$dispatcher->dispatch($event, TheliaEvents::TRANSLATION_GET_STRINGS);
if (null !== $translatableStrings = $event->getTranslatableStrings()) {
$catalogue = new MessageCatalogue($lang->getLocale());

Expand Down Expand Up @@ -261,8 +271,6 @@ protected function getModulesDirectories()
'pdf' => 'Pdf'
];

$domain = null;

foreach ($modulesNames as $moduleName){
if ($moduleName[0] !== '.'){
/** @var Module $module */
Expand Down
14 changes: 12 additions & 2 deletions Controller/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,35 @@
namespace Translation\Controller;


use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Tools\URL;
use Translation\Translation;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/admin/module/translation/import", name="admin_translation_import")
*/
class ImportController extends BaseAdminController
{
/**
* @Route("", name="", methods="POST")
*/
public function importAction()
{
$path = Translation::TRANSLATIONS_DIR . 'tmp';

$fs = new Filesystem();

if (!file_exists($path)) {
mkdir($path, 0777 , true);
$fs->mkdir($path);
}

$ext = Translation::getConfigValue('extension');

if (!file_exists(Translation::TRANSLATIONS_DIR . $ext)) {
mkdir(Translation::TRANSLATIONS_DIR . $ext, 0777 , true);
$fs->mkdir(Translation::TRANSLATIONS_DIR . $ext);
}

/** @var UploadedFile $importFile */
Expand Down
16 changes: 8 additions & 8 deletions Form/ExportForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ protected function buildForm()
'required' => true,
'multiple' => true,
'choices' => [
"all" => Translator::getInstance()->trans('Every translations', [], Translation::DOMAIN_NAME),
"core" => Translator::getInstance()->trans('Core Thelia', [], Translation::DOMAIN_NAME),
'frontOffice' => Translator::getInstance()->trans('Front-office templates', [], Translation::DOMAIN_NAME),
"backOffice" => Translator::getInstance()->trans('Back-office templates', [], Translation::DOMAIN_NAME),
"pdf" => Translator::getInstance()->trans('PDF templates', [], Translation::DOMAIN_NAME),
"email" => Translator::getInstance()->trans('E-mail templates', [], Translation::DOMAIN_NAME),
"modules" => Translator::getInstance()->trans('Modules', [], Translation::DOMAIN_NAME)
Translator::getInstance()->trans('Every translations', [], Translation::DOMAIN_NAME) => "all",
Translator::getInstance()->trans('Core Thelia', [], Translation::DOMAIN_NAME) => "core",
Translator::getInstance()->trans('Front-office templates', [], Translation::DOMAIN_NAME) => "frontOffice",
Translator::getInstance()->trans('Back-office templates', [], Translation::DOMAIN_NAME) => "backOffice",
Translator::getInstance()->trans('PDF templates', [], Translation::DOMAIN_NAME) => "pdf",
Translator::getInstance()->trans('E-mail templates', [], Translation::DOMAIN_NAME) => "email",
Translator::getInstance()->trans('Modules', [], Translation::DOMAIN_NAME) => "modules"
]
]
);
}

public function getName()
public static function getName()
{
return 'translation-export-form';
}
Expand Down
6 changes: 3 additions & 3 deletions Form/ExtensionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ protected function buildForm()
[
'data' => Translation::getConfigValue("extension"),
'choices' => [
'po' => '.po',
"xlf" => '.xlf'
'.po' => 'po',
".xlf" => 'xlf'
]
]
);
}

public function getName()
public static function getName()
{
return "translation-config-form";
}
Expand Down
11 changes: 10 additions & 1 deletion Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Translation;

use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Symfony\Component\Filesystem\Filesystem;
use Thelia\Module\BaseModule;

Expand All @@ -23,7 +24,7 @@ class Translation extends BaseModule

const TRANSLATIONS_DIR = THELIA_LOCAL_DIR . 'translations' . DS;

public function postActivation(ConnectionInterface $con = null)
public function postActivation(ConnectionInterface $con = null): void
{
if (null === self::getConfigValue('extension')){
self::setConfigValue('extension' , 'po');
Expand All @@ -34,4 +35,12 @@ public static function deleteTmp()
{
(new Filesystem())->remove(self::TRANSLATIONS_DIR . 'tmp');
}

public static function configureServices(ServicesConfigurator $servicesConfigurator): void
{
$servicesConfigurator->load(self::getModuleCode().'\\', __DIR__)
->exclude([THELIA_MODULE_DIR . ucfirst(self::getModuleCode()). "/I18n/*"])
->autowire(true)
->autoconfigure(true);
}
}
4 changes: 2 additions & 2 deletions templates/backOffice/default/Translation/translation.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
</div>
{/if}

<div class="row inner-toolbar{if $page_bottom} inner-toolbar-bottom{/if}">
<div class="row inner-toolbar{if $page_bottom|default:null} inner-toolbar-bottom{/if}">
<div class="col-md-12 inner-actions">
<ul class="nav nav-pills">
{loop name="lang_list" type="lang" backend_context="1"}
<li {if $ID == $edit_language_id}class="active"{/if}>
{if $current_tab}
{if $current_tab|default:null}
{$lang_url = {url path={$page_url|default:$current_url nofilter} edit_language_id=$ID current_tab=$current_tab}}
{else}
{$lang_url = {url path={$page_url|default:$current_url nofilter} edit_language_id=$ID}}
Expand Down

0 comments on commit 41385f8

Please sign in to comment.