diff --git a/Classes/Widgets/UsageWidget.php b/Classes/Widgets/UsageWidget.php new file mode 100644 index 00000000..0fafe75b --- /dev/null +++ b/Classes/Widgets/UsageWidget.php @@ -0,0 +1,76 @@ + + */ + private array $options; + + /** + * @param array $options + */ + public function __construct( + WidgetConfigurationInterface $configuration, + StandaloneView $view, + array $options = [] + ) { + $this->configuration = $configuration; + $this->view = $view; + $this->options = $options; + } + + public function renderWidgetContent(): string + { + /** @var UsageService $usageService */ + $usageService = GeneralUtility::makeInstance(UsageService::class); + + // Workaround to make the widget template available in two TYPO3 versions + $templateRootPaths = $this->view->getTemplateRootPaths(); + $templateRootPaths[1718368476557] = 'EXT:wv_deepltranslate/Resources/Private/Backend/Templates/'; + $this->view->setTemplateRootPaths($templateRootPaths); + + $currentUsage = $usageService->getCurrentUsage(); + + $this->view->assignMultiple([ + 'usages' => [ + [ + 'label' => $this->getLanguageService()->sL('LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.character'), + 'usage' => $currentUsage !== null ? $currentUsage->character : [], + ], + ], + 'options' => $this->options, + 'configuration' => $this->configuration, + ]); + + return $this->view->render('Widget/UsageWidget'); + } + + /** + * @return array + */ + public function getOptions(): array + { + return $this->options; + } + + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } +} diff --git a/Configuration/Backend/DashboardWidgetGroups.php b/Configuration/Backend/DashboardWidgetGroups.php new file mode 100644 index 00000000..13140bb5 --- /dev/null +++ b/Configuration/Backend/DashboardWidgetGroups.php @@ -0,0 +1,13 @@ + [ + 'title' => 'DeepL Widget', + ], + ]; + } + + return []; +})(); diff --git a/Configuration/Services.php b/Configuration/Services.php index 7f23e1e2..6d43c03e 100644 --- a/Configuration/Services.php +++ b/Configuration/Services.php @@ -3,6 +3,7 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; use TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent; use TYPO3\CMS\Backend\Template\Components\ModifyButtonBarEvent; use TYPO3\CMS\Core\Cache\CacheManager; @@ -27,6 +28,7 @@ use WebVision\WvDeepltranslate\Service\IconOverlayGenerator; use WebVision\WvDeepltranslate\Service\LanguageService; use WebVision\WvDeepltranslate\Service\UsageService; +use WebVision\WvDeepltranslate\Widgets\UsageWidget; return function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder) { $typo3version = new Typo3Version(); @@ -149,4 +151,19 @@ 'event' => SystemInformationToolbarCollectorEvent::class, ] ); + + $services->set('widgets.deepltranslate.widget.useswidget') + ->class(UsageWidget::class) + ->arg('$view', new Reference('dashboard.views.widget')) + ->arg('$options', []) + ->tag('dashboard.widget', [ + 'identifier' => 'widgets-deepl-uses', + 'groupNames' => 'deepl', + 'title' => 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.title', + 'description' => 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.description', + 'iconIdentifier' => 'content-widget-list', + 'height' => 'medium', + 'width' => 'small', + ]) + ; }; diff --git a/Resources/Private/Backend/Templates/Widget/UsageWidget.html b/Resources/Private/Backend/Templates/Widget/UsageWidget.html new file mode 100644 index 00000000..8261de58 --- /dev/null +++ b/Resources/Private/Backend/Templates/Widget/UsageWidget.html @@ -0,0 +1,28 @@ + + + + + +
+

{item.label}

+

+ {f:translate(key: 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.count')}: {item.usage.count -> f:format.number(thousandsSeparator: '.', decimalSeparator: '', decimals: 0)} +
+ {f:translate(key: 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.limit')}: {item.usage.limit -> f:format.number(thousandsSeparator: '.', decimalSeparator: '', decimals: 0)} +

+ {item.usage.count / item.usage.limit * 100} +
+
{item.usage.count -> f:format.number(thousandsSeparator: '.', decimalSeparator: '', decimals: 0)}
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 5d319551..4e340db1 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -164,6 +164,28 @@ Information not available Information nicht verfügbar + + + + DeepL Usage + DeepL Verwendung + + + + + + + Character + Zeichen + + + Count + Zähler + + + Limit + Begrenzung + diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 903ea2f1..e3e7d0d6 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -163,6 +163,23 @@ DeepL Translate Limit %s / %s + + + + DeepL Usage + + + + + + Character + + + Count + + + Limit + diff --git a/composer.json b/composer.json index 2ec9db5c..df76e59c 100644 --- a/composer.json +++ b/composer.json @@ -92,6 +92,7 @@ "ramsey/uuid": "^4.2", "saschaegerer/phpstan-typo3": "^1.9", "typo3/cms-belog": "^11.5 || ^12.4", + "typo3/cms-dashboard": "^11.5 || ^12.4", "typo3/cms-extensionmanager": "^11.5 || ^12.4", "typo3/cms-filelist": "^11.5 || ^12.4", "typo3/cms-fluid-styled-content": "^11.5 || ^12.4",