Skip to content

Commit

Permalink
Add xliff for property name and description
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed Mar 13, 2024
1 parent 403905d commit 3e2c050
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 51 deletions.
47 changes: 28 additions & 19 deletions src/Contao/View/Contao2BackendView/ContaoWidgetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2023 Contao Community Alliance.
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -19,14 +19,15 @@
* @author Ingolf Steinhardt <[email protected]>
* @author Sven Baumann <[email protected]>
* @author Richard Henkenjohann <[email protected]>
* @copyright 2013-2023 Contao Community Alliance.
* @copyright 2013-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

namespace ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView;

use Contao\Backend;
use Contao\Config;
use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
use Contao\Date;
use Contao\Input;
Expand All @@ -48,8 +49,8 @@
use ContaoCommunityAlliance\DcGeneral\Exception\DcGeneralRuntimeException;
use ContaoCommunityAlliance\DcGeneral\InputProviderInterface;
use ContaoCommunityAlliance\DcGeneral\SessionStorageInterface;
use ContaoCommunityAlliance\Translator\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Class ContaoWidgetManager.
Expand Down Expand Up @@ -85,6 +86,13 @@ class ContaoWidgetManager
*/
protected $model;

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

/**
* Create a new instance.
*
Expand All @@ -97,8 +105,11 @@ public function __construct(EnvironmentInterface $environment, ModelInterface $m
$this->model = $model;
$framework = System::getContainer()->get('contao.framework');
assert($framework instanceof ContaoFrameworkInterface);
$translator = System::getContainer()->get('translator');
assert($translator instanceof TranslatorInterface);

$this->framework = $framework;
$this->framework = $framework;
$this->translator = $translator;
}

/**
Expand Down Expand Up @@ -318,8 +329,8 @@ public function getWidget($property, PropertyValueBagInterface $inputValues = nu
*/
protected function buildDatePicker($objWidget)
{
$translator = $this->getEnvironment()->getTranslator();
assert($translator instanceof TranslatorInterface);
$definition = $this->getEnvironment()->getDataDefinition();
assert($definition instanceof ContainerInterface);

$strFormat = $GLOBALS['TL_CONFIG'][$objWidget->rgxp . 'Format'];

Expand All @@ -342,8 +353,8 @@ protected function buildDatePicker($objWidget)
positionOffset:{x:-197,y:-182}' . $time . ',
pickerClass:"datepicker_bootstrap",
useFadeInOut:!Browser.ie,
startDay:' . $translator->translate('weekOffset', 'dc-general') . ',
titleFormat:"' . $translator->translate('titleFormat', 'dc-general') . '"
startDay:' . $this->translator->trans('weekOffset', [], $definition->getName()) . ',
titleFormat:"' . $this->translator->trans('titleFormat', [], $definition->getName()) . '"
});';
}

Expand All @@ -357,21 +368,19 @@ protected function buildDatePicker($objWidget)
* @SuppressWarnings(PHPMD.Superglobals)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/
protected function generateHelpText($property)
protected function generateHelpText($property, Widget $widget)
{
$definition = $this->getEnvironment()->getDataDefinition();
assert($definition instanceof ContainerInterface);

$propInfo = $definition->getPropertiesDefinition()->getProperty($property);
$label = $propInfo->getDescription();
$widgetType = $propInfo->getWidgetType();

if (
('password' === $widgetType)
|| !$GLOBALS['TL_CONFIG']['showHelp']
) {
$widgetType = $definition->getPropertiesDefinition()->getProperty($property)->getWidgetType();
if (('password' === $widgetType) || !Config::get('showHelp')) {
return '';
}
$label = (string) ($widget->description
// see vendor/contao/core-bundle/src/Resources/contao/classes/DataContainer.php:817; method help();

Check warning on line 381 in src/Contao/View/Contao2BackendView/ContaoWidgetManager.php

View workflow job for this annotation

GitHub Actions / PHP: 8.1 Contao: ~4.13.0

Line exceeds 120 characters; contains 126 characters (reported by phpcs: Generic.Files.LineLength.TooLong)

Check warning on line 381 in src/Contao/View/Contao2BackendView/ContaoWidgetManager.php

View workflow job for this annotation

GitHub Actions / PHP: 8.2 Contao: ~4.13.0

Line exceeds 120 characters; contains 126 characters (reported by phpcs: Generic.Files.LineLength.TooLong)

Check warning on line 381 in src/Contao/View/Contao2BackendView/ContaoWidgetManager.php

View workflow job for this annotation

GitHub Actions / PHP: 8.1 Contao: ~4.13.0

Line exceeds 120 characters; contains 126 characters (reported by phpcs: Generic.Files.LineLength.TooLong)

Check warning on line 381 in src/Contao/View/Contao2BackendView/ContaoWidgetManager.php

View workflow job for this annotation

GitHub Actions / PHP: 8.2 Contao: ~4.13.0

Line exceeds 120 characters; contains 126 characters (reported by phpcs: Generic.Files.LineLength.TooLong)
?? $this->translator->trans($property . '.label.1', [], $definition->getName())
);

return '<p class="tl_help tl_tip">' . $label . '</p>';
}
Expand Down Expand Up @@ -415,7 +424,7 @@ public function renderWidget($property, $ignoreErrors = false, PropertyValueBagI
->set('strDatepicker', $isHideInput ? null : $this->getDatePicker($propInfo->getExtra(), $widget))
// We used the var blnUpdate before.
->set('blnUpdate', false)
->set('strHelp', $isHideInput ? null : $this->generateHelpText($property))
->set('strHelp', $isHideInput ? null : $this->generateHelpText($property, $widget))
->set('strId', $widget->id)
->set('isHideInput', $isHideInput)
->set('hiddenName', $widget->name)
Expand Down Expand Up @@ -573,7 +582,7 @@ protected function widgetAddError(
) {
if (
!(!$ignoreErrors && $inputValues && $inputValues->hasPropertyValue($property)
&& $inputValues->isPropertyValueInvalid($property))
&& $inputValues->isPropertyValueInvalid($property))
) {
return;
}
Expand Down
76 changes: 44 additions & 32 deletions src/Contao/View/Contao2BackendView/Subscriber/WidgetBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2023 Contao Community Alliance.
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -17,7 +17,7 @@
* @author Sven Baumann <[email protected]>
* @author Richard Henkenjohann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2023 Contao Community Alliance.
* @copyright 2013-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down Expand Up @@ -47,8 +47,9 @@
use ContaoCommunityAlliance\DcGeneral\EnvironmentAwareInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface;
use ContaoCommunityAlliance\DcGeneral\Exception\DcGeneralRuntimeException;
use ContaoCommunityAlliance\Translator\TranslatorInterface;
use ContaoCommunityAlliance\Translator\TranslatorInterface as CcaTranslator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Widget Builder build Contao backend widgets.
Expand All @@ -74,6 +75,13 @@ class WidgetBuilder implements EnvironmentAwareInterface
*/
private EnvironmentInterface $environment;

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

/**
* Mapping list of widget types where the DC General has it own widgets.
*
Expand All @@ -93,12 +101,16 @@ class WidgetBuilder implements EnvironmentAwareInterface
* Construct.
*
* @param EnvironmentInterface $environment The environment.
*
* @param TranslatorInterface $translator The translator.
* @param RequestScopeDeterminator|null $scopeDeterminator The request mode determinator.
*/
public function __construct(EnvironmentInterface $environment, RequestScopeDeterminator $scopeDeterminator = null)
{
public function __construct(
EnvironmentInterface $environment,
TranslatorInterface $translator,
RequestScopeDeterminator $scopeDeterminator = null
) {
$this->environment = $environment;
$this->translator = $translator;

if (null !== $scopeDeterminator) {
static::$scopeDeterminator = $scopeDeterminator;
Expand Down Expand Up @@ -237,36 +249,36 @@ protected function getTableWizard()

$defName = $definition->getName();

$translator = $environment->getTranslator();
assert($translator instanceof TranslatorInterface);
$ccaTranslator = $environment->getTranslator();
assert($ccaTranslator instanceof CcaTranslator);

$urlEvent = new AddToUrlEvent('key=table');

$importTableEvent = new GenerateHtmlEvent(
'tablewizard.svg',
$translator->translate('importTable.0', $defName),
$ccaTranslator->translate('importTable.0', $defName),
'style="vertical-align:text-bottom;"'
);

$shrinkEvent = new GenerateHtmlEvent(
'demagnify.svg',
$translator->translate('shrink.0', $defName),
$ccaTranslator->translate('shrink.0', $defName),
\sprintf(
'title="%s" ' .
'style="vertical-align:text-bottom; cursor:pointer;" ' .
'onclick="Backend.tableWizardResize(0.9);"',
StringUtil::specialchars($translator->translate('shrink.1', $defName))
StringUtil::specialchars($ccaTranslator->translate('shrink.1', $defName))
)
);

$expandEvent = new GenerateHtmlEvent(
'magnify.svg',
$translator->translate('expand.0', $defName),
$ccaTranslator->translate('expand.0', $defName),
\sprintf(
'title="%s" ' .
'style="vertical-align:text-bottom; cursor:pointer;" ' .
'onclick="Backend.tableWizardResize(1.1);"',
StringUtil::specialchars($translator->translate('expand.1', $defName))
StringUtil::specialchars($ccaTranslator->translate('expand.1', $defName))
)
);

Expand All @@ -278,7 +290,7 @@ protected function getTableWizard()
return \sprintf(
' <a href="%s" title="%s" onclick="Backend.getScrollOffset();">%s</a> %s%s',
StringUtil::ampersand($urlEvent->getUrl()),
StringUtil::specialchars($translator->translate('importTable.1', $defName)),
StringUtil::specialchars($ccaTranslator->translate('importTable.1', $defName)),
$importTableEvent->getHtml() ?? '',
$shrinkEvent->getHtml() ?? '',
$expandEvent->getHtml() ?? ''
Expand All @@ -302,14 +314,14 @@ protected function getListWizard()

$defName = $definition->getName();

$translator = $environment->getTranslator();
assert($translator instanceof TranslatorInterface);
$ccaTranslator = $environment->getTranslator();
assert($ccaTranslator instanceof CcaTranslator);

$urlEvent = new AddToUrlEvent('key=list');

$importListEvent = new GenerateHtmlEvent(
'tablewizard.svg',
$translator->translate('importList.0', $defName),
$ccaTranslator->translate('importList.0', $defName),
'style="vertical-align:text-bottom;"'
);

Expand All @@ -319,7 +331,7 @@ protected function getListWizard()
return \sprintf(
' <a href="%s" title="%s" onclick="Backend.getScrollOffset();">%s</a>',
StringUtil::ampersand($urlEvent->getUrl()),
StringUtil::specialchars($translator->translate('importList.1', $defName)),
StringUtil::specialchars($ccaTranslator->translate('importList.1', $defName)),
$importListEvent->getHtml() ?? ''
);
}
Expand All @@ -333,19 +345,19 @@ protected function getListWizard()
*/
protected function getXLabel($propInfo)
{
$xLabel = '';
$environment = $this->getEnvironment();
$translator = $environment->getTranslator();
assert($translator instanceof TranslatorInterface);
$xLabel = '';
$environment = $this->getEnvironment();
$ccaTranslator = $environment->getTranslator();
assert($ccaTranslator instanceof CcaTranslator);

// Toggle line wrap (textarea).
if (('textarea' === $propInfo->getWidgetType()) && !\array_key_exists('rte', $propInfo->getExtra())) {
$event = new GenerateHtmlEvent(
'wrap.svg',
$translator->translate('wordWrap', 'dc-general'),
$ccaTranslator->translate('wordWrap', 'dc-general'),
\sprintf(
'title="%s" class="toggleWrap" onclick="Backend.toggleWrap(\'ctrl_%s\');"',
StringUtil::specialchars($translator->translate('wordWrap', 'dc-general')),
StringUtil::specialchars($ccaTranslator->translate('wordWrap', 'dc-general')),
$propInfo->getName()
)
);
Expand Down Expand Up @@ -382,16 +394,16 @@ protected function getXLabel($propInfo)
*/
protected function getHelpWizard($propInfo)
{
$helpWizard = '';
$environment = $this->getEnvironment();
$translator = $environment->getTranslator();
assert($translator instanceof TranslatorInterface);
$helpWizard = '';
$environment = $this->getEnvironment();
$ccaTranslator = $environment->getTranslator();
assert($ccaTranslator instanceof CcaTranslator);

// Add the help wizard.
if ($propInfo->getExtra() && \array_key_exists('helpwizard', $propInfo->getExtra())) {
$event = new GenerateHtmlEvent(
'about.svg',
$translator->translate('helpWizard', 'dc-general'),
$ccaTranslator->translate('helpWizard', 'dc-general'),
'style="vertical-align:text-bottom;"'
);

Expand All @@ -409,7 +421,7 @@ protected function getHelpWizard($propInfo)
'onclick="Backend.openWindow(this, 600, 500); return false;">%s</a>',
$definition->getName(),
$propInfo->getName(),
StringUtil::specialchars($translator->translate('helpWizard', 'dc-general')),
StringUtil::specialchars($ccaTranslator->translate('helpWizard', 'dc-general')),
$event->getHtml() ?? ''
);
}
Expand Down Expand Up @@ -532,8 +544,8 @@ private function prepareWidgetAttributes(ModelInterface $model, PropertyInterfac
$widgetConfig = [
'inputType' => $property->getWidgetType(),
'label' => [
$property->getLabel(),
$property->getDescription()
$this->translator->trans($property->getLabel(), [], $defName),
$this->translator->trans($property->getDescription(), [], $defName),
],
'options' => $this->getOptionsForWidget($property, $model),
'eval' => $propExtra,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/contao/widget_backend_listeners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
public: true
arguments:
- "@cca.dc-general.environment"
- "@translator"
- "@cca.dc-general.scope-matcher"
tags:
- name: kernel.event_listener
Expand Down

0 comments on commit 3e2c050

Please sign in to comment.