-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add xliff for property name and description
- Loading branch information
Showing
3 changed files
with
73 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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; | ||
|
@@ -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. | ||
|
@@ -85,6 +86,13 @@ class ContaoWidgetManager | |
*/ | ||
protected $model; | ||
|
||
/** | ||
* The translator. | ||
* | ||
* @var TranslatorInterface | ||
*/ | ||
protected TranslatorInterface $translator; | ||
|
||
/** | ||
* Create a new instance. | ||
* | ||
|
@@ -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; | ||
} | ||
|
||
/** | ||
|
@@ -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']; | ||
|
||
|
@@ -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()) . '" | ||
});'; | ||
} | ||
|
||
|
@@ -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 GitHub Actions / PHP: 8.1 Contao: ~4.13.0
Check warning on line 381 in src/Contao/View/Contao2BackendView/ContaoWidgetManager.php GitHub Actions / PHP: 8.2 Contao: ~4.13.0
Check warning on line 381 in src/Contao/View/Contao2BackendView/ContaoWidgetManager.php GitHub Actions / PHP: 8.1 Contao: ~4.13.0
|
||
?? $this->translator->trans($property . '.label.1', [], $definition->getName()) | ||
); | ||
|
||
return '<p class="tl_help tl_tip">' . $label . '</p>'; | ||
} | ||
|
@@ -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) | ||
|
@@ -573,7 +582,7 @@ protected function widgetAddError( | |
) { | ||
if ( | ||
!(!$ignoreErrors && $inputValues && $inputValues->hasPropertyValue($property) | ||
&& $inputValues->isPropertyValueInvalid($property)) | ||
&& $inputValues->isPropertyValueInvalid($property)) | ||
) { | ||
return; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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 | ||
*/ | ||
|
@@ -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. | ||
|
@@ -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. | ||
* | ||
|
@@ -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; | ||
|
@@ -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)) | ||
) | ||
); | ||
|
||
|
@@ -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() ?? '' | ||
|
@@ -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;"' | ||
); | ||
|
||
|
@@ -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() ?? '' | ||
); | ||
} | ||
|
@@ -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() | ||
) | ||
); | ||
|
@@ -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;"' | ||
); | ||
|
||
|
@@ -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() ?? '' | ||
); | ||
} | ||
|
@@ -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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters