Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
92db3da
#106228 - Module traduction automatique [add menu Translation]
mohamed-larbi-jebari Jul 11, 2023
9172540
#106228 - Module traduction automatique [policy]
mohamed-larbi-jebari Jul 12, 2023
24d5d62
#106228 - Module traduction automatique [page liste]
mohamed-larbi-jebari Jul 23, 2023
4d0f4a9
#106228 - Module traduction automatique
mohamed-larbi-jebari Jul 24, 2023
f7bd584
#106228 - Module traduction automatique [Mise en place du script de t…
mohamed-larbi-jebari Jul 26, 2023
cb763d2
#106228 - Module traduction automatique
mohamed-larbi-jebari Aug 8, 2023
c0acfe7
106228 module traduction automatique
mohamed-larbi-jebari Aug 31, 2023
742bcbf
106228 module traduction automatique [alternative Text of image]
mohamed-larbi-jebari Aug 31, 2023
a7c7590
106228 module traduction automatique [alternative Text of image]
mohamed-larbi-jebari Aug 31, 2023
4945f85
#110432 - Formulaire
mohamed-larbi-jebari Sep 4, 2023
1ea7e11
#106228 - Module traduction automatique [bloc link attribute]
mohamed-larbi-jebari Sep 20, 2023
2e424c1
#106228 - Module traduction automatique [bloc link attribute]
mohamed-larbi-jebari Sep 27, 2023
1c1006a
#106228 - Module traduction automatique [ne valider les champs]
mohamed-larbi-jebari Sep 27, 2023
bfd77c1
Merge remote-tracking branch 'origin/release-ibexa4' into 106228_Modu…
mohamed-larbi-jebari Nov 13, 2023
33ccab2
#109934 - Traduction Deeple / bulles d'information
mohamed-larbi-jebari Nov 14, 2023
80b9871
#113907 - (back office) Problème d'enregistrement des contenus
mohamed-larbi-jebari Dec 8, 2023
2e78f5d
#113888 - Traduction - les traductions des langues Russes et Chinois …
mohamed-larbi-jebari Dec 18, 2023
479cd74
#114792 - Back-office - Traduction des blocs ne fonctionne plus
mohamed-larbi-jebari Dec 30, 2023
d6600b7
#116150 - [ouvrage] le champ ISBN n'est pas traduisible
mohamed-larbi-jebari Feb 6, 2024
f61c818
Exclude fields from overwrite translation
mohamed-larbi-jebari Feb 15, 2024
cfededf
Update USAGE.md
mohamed-larbi-jebari Jun 4, 2024
93d4022
#125248 - March 2025: Deprecating GET requests to /translate and auth…
mohamed-larbi-jebari Feb 3, 2025
78ccfae
#130636 - [DeepL] Modification Header Authentification HTT
mohamed-larbi-jebari Sep 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
361 changes: 335 additions & 26 deletions bundle/Command/TranslateContentCommand.php

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions bundle/Controller/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

namespace EzSystems\EzPlatformAutomatedTranslationBundle\Controller;

use Ibexa\Contracts\AdminUi\Controller\Controller;
use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface;
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Symfony\Contracts\Translation\TranslatorInterface;

abstract class BaseController extends Controller
{
/**
* @var PermissionResolver
*/
protected PermissionResolver $permissionResolver;

/**
* @var TranslatorInterface
*/
protected TranslatorInterface $translator;

/**
* @var NotificationHandlerInterface
*/
protected NotificationHandlerInterface $notificationHandler;

/**
* @required
*/
public function setPermissionResolver(PermissionResolver $permissionResolver): void
{
$this->permissionResolver = $permissionResolver;
}

/**
* @required
*/
public function setTranslator(TranslatorInterface $translator): void
{
$this->translator = $translator;
}

/**
* @required
*/
public function setNotificationHandler(NotificationHandlerInterface $notificationHandler): void
{
$this->notificationHandler = $notificationHandler;
}

/**
* @throws InvalidArgumentException
*/
protected function permissionAccess(string $module, string $function)
{
if (!$this->permissionResolver->hasAccess($module, $function)) {
$exception = $this->createAccessDeniedException($this->translator->trans(
'auto_translation.permission.failed'
));
$exception->setAttributes(null);
$exception->setSubject(null);

throw $exception;
}

return null;
}

/**
* @throws InvalidArgumentException
*/
protected function permissionManageAccess(string $module, array $functions): array
{
$access = [];
foreach ($functions as $function) {
$access[$function] = true;
if (!$this->permissionResolver->hasAccess($module, $function)) {
$access[$function] = false;
}
}

return $access;
}
}
113 changes: 113 additions & 0 deletions bundle/Controller/TranslationSubtreeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAutomatedTranslationBundle\Controller;

use Doctrine\ORM\EntityManagerInterface;
use eZ\Publish\Core\MVC\Symfony\Security\User;
use EzSystems\EzPlatformAutomatedTranslationBundle\Entity\AutoTranslationActions;
use EzSystems\EzPlatformAutomatedTranslationBundle\Form\AutoTranslationActionsSearchType;
use EzSystems\EzPlatformAutomatedTranslationBundle\Form\AutoTranslationActionsType;
use EzSystems\EzPlatformAutomatedTranslationBundle\Handler\AutoTranslationActionsHandler;
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Pagerfanta\Doctrine\DBAL\QueryAdapter;
use Pagerfanta\Pagerfanta;
use Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface;
use Ibexa\Contracts\Core\Repository\LocationService;

final class TranslationSubtreeController extends BaseController
{
private $defaultPaginationLimit = 25;
/**
* @Route("/", name="automated_translation_index")
*
* @throws InvalidArgumentException
*/
public function viewAction(Request $request, AutoTranslationActionsHandler $handler): Response
{
$this->permissionAccess('auto_translation', 'view');

$formSearch = $this->createForm(AutoTranslationActionsSearchType::class , null, [
'action' => $this->generateUrl('automated_translation_index'),
'method' => 'GET',
]);

$formSearch->handleRequest($request);
$page = $request->query->get('page' ,1);

$adapter = new QueryAdapter(
$handler->getAllQuery($formSearch->getData()['sort'] ?? []),
function ($queryBuilder) use ($handler) {
return $handler->countAll($queryBuilder);
});
$pagerfanta = new Pagerfanta(
$adapter
);

$pagerfanta->setMaxPerPage($this->defaultPaginationLimit);
$pagerfanta->setCurrentPage($page);

$autoTranslationActions = new AutoTranslationActions();
$form = $this->createForm(AutoTranslationActionsType::class, $autoTranslationActions, [
'action' => $this->generateUrl('automated_translation_add'),
'method' => 'POST',
]);

return $this->render( '@ibexadesign/auto_translation/view.html.twig', [
'form' => $form->createView(),
'form_search' => $formSearch->createView(),
'pager' => $pagerfanta,
'canCreate' => $this->permissionResolver->hasAccess('auto_translation', 'create'),
'canDelete' => $this->permissionResolver->hasAccess('auto_translation', 'delete'),
]);
}
/**
* @Route("/add", name="automated_translation_add")
*/
public function addAction(
Request $request,
EntityManagerInterface $em,
LocationService $locationService,
TranslatableNotificationHandlerInterface $notificationHandler
): RedirectResponse {
$this->permissionAccess('auto_translation', 'create');

$autoTranslationActions = new AutoTranslationActions();
$form = $this->createForm(AutoTranslationActionsType::class, $autoTranslationActions);
$form->handleRequest($request);
/**
* @var User $user
*/
$user = $this->getUser();

if ($form->isSubmitted() && $form->isValid()) {
$autoTranslationActions->setStatus(AutoTranslationActions::STATUS_PENDING);
$autoTranslationActions->setUserId($user->getAPIUser()->id);
$em->persist($autoTranslationActions);
$em->flush();
try {
$location = $locationService->loadLocation($autoTranslationActions->getSubtreeId());
$this->notificationHandler->success($this->translator->trans(
'auto_translation.add.success' ,['%subtree_name%' => $location->contentInfo->name ]
));
} catch (NotFoundException|UnauthorizedException $e) {
$this->notificationHandler->error($e->getMessage());
}
}

return new RedirectResponse($this->generateUrl(
'automated_translation_index'
));
}
}
6 changes: 3 additions & 3 deletions bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace EzSystems\EzPlatformAutomatedTranslationBundle\DependencyInjection;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class Configuration extends SiteAccessAware\Configuration
Expand All @@ -22,8 +22,8 @@ public function getConfigTreeBuilder(): TreeBuilder
->variableNode('configurations')->end()
->arrayNode('non_translatable_characters')->end()
->arrayNode('non_translatable_tags')->end()
->arrayNode('non_translatable_self_closed_tags')->end();

->arrayNode('non_translatable_self_closed_tags')->end()
->arrayNode('exclude_attribute')->end();
return $treeBuilder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@

namespace EzSystems\EzPlatformAutomatedTranslationBundle\DependencyInjection;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use EzSystems\EzPlatformAutomatedTranslation\Encoder\BlockAttribute\BlockAttributeEncoderInterface;
use EzSystems\EzPlatformAutomatedTranslation\Encoder\Field\FieldEncoderInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Yaml\Yaml;

class EzPlatformAutomatedTranslationExtension extends Extension
class EzPlatformAutomatedTranslationExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
Expand All @@ -27,8 +30,6 @@ public function load(array $configs, ContainerBuilder $container): void
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
// always needed because of Bundle extension.
$loader->load('services_override.yml');

$container->registerForAutoconfiguration(FieldEncoderInterface::class)
->addTag('ezplatform.automated_translation.field_encoder');
Expand All @@ -44,9 +45,10 @@ public function load(array $configs, ContainerBuilder $container): void
return;
}

$loader->load('ezadminui.yml');
$loader->load('default_settings.yml');
$loader->load('services.yml');
// always needed because of Bundle extension.
$loader->load('services_override.yml');

$processor = new ConfigurationProcessor($container, $this->getAlias());
$processor->mapSetting('configurations', $config);
Expand All @@ -66,4 +68,21 @@ private function hasConfiguredClients(array $config, ContainerBuilder $container
});
}));
}

/**
* Allow an extension to prepend the extension configurations.
*/
public function prepend(ContainerBuilder $container): void
{
$configs = [
'universal_discovery_widget.yaml' => 'ibexa',
];

foreach ($configs as $fileName => $extensionName) {
$configFile = __DIR__.'/../Resources/config/'.$fileName;
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig($extensionName, $config);
$container->addResource(new FileResource($configFile));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* EzPlatformAutomatedTranslationBundle.
*
* @package EzPlatformAutomatedTranslationBundle
*
* @author Novactive
* @copyright 2018 Novactive
* @license https://github.com/Novactive/ezplatform-automated-translation/blob/master/LICENSE
*/

namespace EzSystems\EzPlatformAutomatedTranslationBundle\DependencyInjection\Security\Provider;

use Ibexa\Bundle\Core\DependencyInjection\Security\PolicyProvider\YamlPolicyProvider;

class AutoTranslationPolicyProvider extends YamlPolicyProvider
{
public function getFiles(): array
{

return [
__DIR__.'/../../../Resources/config/policies.yaml',
];
}
}
Loading