Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Classes/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
use DeepL\TextResult;
use DeepL\TranslateTextOptions;
use DeepL\Usage;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use WebVision\Deepltranslate\Core\Exception\ApiKeyNotSetException;

/**
* @internal No public usage
*/
#[AsAlias(id: ClientInterface::class, public: true)]
final class Client extends AbstractClient
{
/**
Expand Down
10 changes: 9 additions & 1 deletion Classes/Controller/Backend/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@

use Psr\Http\Message\ServerRequestInterface;

use TYPO3\CMS\Backend\Attribute\Controller;
use TYPO3\CMS\Core\Http\JsonResponse;
use WebVision\Deepltranslate\Core\Configuration;

// @todo use #[Controller] if 12.4+ only support is established, see: TYPO3\CMS\Backend\Attribute\Controller;
/**
* Controller for fetching the DeepL settings via Ajax route for usage in JavaScript inside the backend
*
* Configured backend ajax route: deepl_check_configuration
*
* @internal No public API
*/
#[Controller]
final class AjaxController
{
private Configuration $configuration;
Expand Down
4 changes: 3 additions & 1 deletion Classes/Domain/Dto/CurrentPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WebVision\Deepltranslate\Core\Domain\Dto;

use Symfony\Component\DependencyInjection\Attribute\Exclude;
use WebVision\Deepltranslate\Core\Event\DeepLGlossaryIdEvent;

/**
Expand All @@ -14,8 +15,9 @@
* detecting the right page,
* for example, while detecting a glossary.
*
* @see DeepLGlossaryIdEvent for an usage example
* @see DeepLGlossaryIdEvent for a usage example
*/
#[Exclude]
final class CurrentPage
{
public function __construct(
Expand Down
8 changes: 7 additions & 1 deletion Classes/Domain/Dto/TranslateContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

namespace WebVision\Deepltranslate\Core\Domain\Dto;

class TranslateContext
use Symfony\Component\DependencyInjection\Attribute\Exclude;

/**
* DTO providing the data shipped to DeepL translation.
*/
#[Exclude]
final class TranslateContext
{
protected string $content = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
namespace WebVision\Deepltranslate\Core\Form\Item;

use DeepL\Language;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use WebVision\Deepltranslate\Core\Service\DeeplService;

class SiteConfigSupportedLanguageItemsProcFunc
/**
* Adds DeepL related fields to the Site configuration
*/
#[Autoconfigure(public: true)]
final class SiteConfigSupportedLanguageItemsProcFunc
{
private DeeplService $deeplService;

Expand Down
4 changes: 0 additions & 4 deletions Classes/Form/TranslationDropdownGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
*/
final class TranslationDropdownGenerator
{
public function __construct()
{
}

/**
* @param iterable<SiteLanguage> $siteLanguages
* @throws \Doctrine\DBAL\Exception
Expand Down
7 changes: 6 additions & 1 deletion Classes/Form/User/HasFormalitySupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

namespace WebVision\Deepltranslate\Core\Form\User;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Backend\Form\FormDataProvider\EvaluateDisplayConditions;
use WebVision\Deepltranslate\Core\Service\DeeplService;

class HasFormalitySupport
/**
* Checks a language having support for formality or not.
*/
#[Autoconfigure(public: true)]
final class HasFormalitySupport
{
private DeeplService $deeplService;

Expand Down
14 changes: 8 additions & 6 deletions Classes/Hooks/AllowLanguageSynchronizationHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

namespace WebVision\Deepltranslate\Core\Hooks;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\MathUtility;

class AllowLanguageSynchronizationHook
/**
* Changes the `l10n_state` for fields with allowLanguageSynchronisation enabled to custom.
* This is required to allow overriding the translation.
*/
#[Autoconfigure(public: true)]
final class AllowLanguageSynchronizationHook
{
public function processDatamap_beforeStart(DataHandler $dataHandler): void
{
Expand All @@ -25,11 +31,7 @@ public function processDatamap_beforeStart(DataHandler $dataHandler): void

$columnConfig = $GLOBALS['TCA'][$table]['columns'][$column];

if (isset($columnConfig['config']['behaviour'])
&& is_array($columnConfig['config']['behaviour'])
&& isset($columnConfig['config']['behaviour']['allowLanguageSynchronization'])
&& (bool)$columnConfig['config']['behaviour']['allowLanguageSynchronization'] === true
) {
if ((bool)($columnConfig['config']['behaviour']['allowLanguageSynchronization'] ?? false) === true) {
$l10nState[$column] = (($columnConfig['l10n_mode'] ?? '') === 'prefixLangTitle')
? 'custom'
: 'parent';
Expand Down
6 changes: 6 additions & 0 deletions Classes/Hooks/PageRendererHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace WebVision\Deepltranslate\Core\Hooks;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Page\PageRenderer;

/**
* Adds the labels from deepltranslate_core to the backend, so they are available, as the default core functionality
* is not working
*/
#[Autoconfigure(public: true)]
final class PageRendererHook
{
/**
Expand Down
7 changes: 6 additions & 1 deletion Classes/Hooks/TranslateHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WebVision\Deepltranslate\Core\Hooks;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Site\SiteFinder;
Expand All @@ -12,7 +13,11 @@
use WebVision\Deepltranslate\Core\Exception\LanguageIsoCodeNotFoundException;
use WebVision\Deepltranslate\Core\Exception\LanguageRecordNotFoundException;

class TranslateHook extends AbstractTranslateHook
/**
* The main translation rendering on localization.
*/
#[Autoconfigure(public: true)]
final class TranslateHook extends AbstractTranslateHook
{
/**
* @param array{uid: int} $languageRecord
Expand Down
12 changes: 8 additions & 4 deletions Classes/Hooks/UsageProcessAfterFinishHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WebVision\Deepltranslate\Core\Hooks;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Localization\LanguageService;
Expand All @@ -13,7 +14,12 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\Deepltranslate\Core\Service\UsageService;

class UsageProcessAfterFinishHook
/**
* This hook adds a FlashMessage, if the usage quota is reaching a critical level, so editors can take care
* on and ensure to either increase their quota in DeepL or stop translating to keep the hard limit untouched.
*/
#[Autoconfigure(public: true)]
final class UsageProcessAfterFinishHook
{
private UsageService $usageService;

Expand All @@ -25,9 +31,7 @@ public function __construct(

public function processCmdmap_afterFinish(DataHandler $dataHandler): void
{
if (!isset($dataHandler->cmdmap['localization']['custom']['mode'])
|| $dataHandler->cmdmap['localization']['custom']['mode'] !== 'deepl'
) {
if (!isset($dataHandler->cmdmap['deepltranslate'])) {
return;
}

Expand Down
7 changes: 7 additions & 0 deletions Classes/Service/DeeplService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use DeepL\Language;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
use WebVision\Deepltranslate\Core\ClientInterface;
Expand All @@ -15,6 +17,10 @@
use WebVision\Deepltranslate\Core\Exception\ApiKeyNotSetException;
use WebVision\Deepltranslate\Core\Utility\DeeplBackendUtility;

/**
* Main entry point for connecting TYPO3 backend to the DeepL API
*/
#[Autoconfigure(public: true)]
final class DeeplService implements LoggerAwareInterface
{
use LoggerAwareTrait;
Expand All @@ -25,6 +31,7 @@ final class DeeplService implements LoggerAwareInterface
private ProcessingInstruction $processingInstruction;

public function __construct(
#[Autowire(service: 'cache.deepltranslateCore')]
FrontendInterface $cache,
ClientInterface $client,
ProcessingInstruction $processingInstruction,
Expand Down
2 changes: 2 additions & 0 deletions Classes/Service/IconOverlayGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace WebVision\Deepltranslate\Core\Service;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;

/**
* @internal not part of public deepl extension api
*/
#[Autoconfigure(public: true)]
final class IconOverlayGenerator
{
private IconFactory $iconFactory;
Expand Down
7 changes: 7 additions & 0 deletions Classes/Service/LanguageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

namespace WebVision\Deepltranslate\Core\Service;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Site\Entity\Site;
use WebVision\Deepltranslate\Core\Exception\InvalidArgumentException;
use WebVision\Deepltranslate\Core\Exception\LanguageRecordNotFoundException;

/**
* Service for detecting correct target and source languages from DeepL
*
* @internal No public API
*/
#[Autoconfigure(public: true)]
final class LanguageService
{
protected DeeplService $deeplService;
Expand Down
8 changes: 8 additions & 0 deletions Classes/Service/ProcessingInstruction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@

namespace WebVision\Deepltranslate\Core\Service;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;

/**
* This class defines instructions, how to work within DeepL translations
* @internal No public API
*/
#[Autoconfigure(public: true)]
final class ProcessingInstruction
{
protected const PROCESSING_CACHE_IDENTIFIER = 'deepl-processing-cache';
private FrontendInterface $runtimeCache;

public function __construct(
#[Autowire(service: 'cache.runtime')]
FrontendInterface $runtimeCache
) {
$this->runtimeCache = $runtimeCache;
Expand Down
5 changes: 5 additions & 0 deletions Classes/Service/UsageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace WebVision\Deepltranslate\Core\Service;

use DeepL\Usage;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Localization\Locales;
Expand All @@ -13,6 +14,10 @@
use WebVision\Deepltranslate\Core\Event\Listener\UsageToolBarEventListener;
use WebVision\Deepltranslate\Core\Hooks\UsageProcessAfterFinishHook;

/**
* Service for getting the current count and limit of DeepL API
*/
#[Autoconfigure(public: true)]
final class UsageService implements UsageServiceInterface
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions Classes/Widgets/UsageWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
/**
* `EXT:dashboard` widget compatible with TYPO3 v12 to display deepl api usage.
*
* Cannot be autoconfigured, as this class depends on EXT:dashboard, which is not installed in every system.
* Registration and configuring is done in Configuration/Services.php
*
* @internal implementation only and not part of public API.
*/
final class UsageWidget implements RequestAwareWidgetInterface, WidgetInterface
Expand Down
21 changes: 0 additions & 21 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,14 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use TYPO3\CMS\Backend\View\BackendViewFactory;
use TYPO3\CMS\Core\DependencyInjection\SingletonPass;
use TYPO3\CMS\Dashboard\WidgetRegistry;
use WebVision\Deepltranslate\Core\Form\Item\SiteConfigSupportedLanguageItemsProcFunc;
use WebVision\Deepltranslate\Core\Form\User\HasFormalitySupport;
use WebVision\Deepltranslate\Core\Hooks\TranslateHook;
use WebVision\Deepltranslate\Core\Service\UsageService;
use WebVision\Deepltranslate\Core\Widgets\UsageWidget;

return function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder) {
$services = $containerConfigurator
->services();

$containerBuilder
->registerForAutoconfiguration(TranslateHook::class)
->addTag('deepl.TranslateHook');
$containerBuilder
->registerForAutoconfiguration(SiteConfigSupportedLanguageItemsProcFunc::class)
->addTag('deepl.SiteConfigSupportedLanguageItemsProcFunc');
$containerBuilder
->registerForAutoconfiguration(HasFormalitySupport::class)
->addTag('deepl.HasFormalitySupport');

$containerBuilder
->addCompilerPass(new SingletonPass('deepl.TranslateHook'));
$containerBuilder
->addCompilerPass(new SingletonPass('deepl.SiteConfigSupportedLanguageItemsProcFunc'));
$containerBuilder
->addCompilerPass(new SingletonPass('deepl.HasFormalitySupport'));

/**
* Check if WidgetRegistry is defined, which means that EXT:dashboard is available.
* Registration directly in Services.yaml will break without EXT:dashboard installed!
Expand Down
23 changes: 0 additions & 23 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@ services:
factory: ['@TYPO3\CMS\Core\Cache\CacheManager', 'getCache']
arguments: ['deepltranslate_core']

WebVision\Deepltranslate\Core\Service\:
resource: '../Classes/Service/*'
public: true

WebVision\Deepltranslate\Core\Hooks\:
resource: '../Classes/Hooks/*'
public: true

WebVision\Deepltranslate\Core\Service\ProcessingInstruction:
arguments:
$runtimeCache: '@cache.runtime'

WebVision\Deepltranslate\Core\Service\DeeplService:
public: true
arguments:
$cache: '@cache.deepltranslateCore'

WebVision\Deepltranslate\Core\Controller\Backend\AjaxController:
public: true

WebVision\Deepltranslate\Core\ClientInterface:
class: WebVision\Deepltranslate\Core\Client

WebVision\Deepltranslate\Core\Event\Listener\RenderLocalizationSelect:
tags:
- name: 'event.listener'
Expand Down