Skip to content

Commit

Permalink
Fix translation button renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
e-spin committed Jan 12, 2024
1 parent 75286c1 commit 97afb24
Show file tree
Hide file tree
Showing 45 changed files with 1,113 additions and 283 deletions.
2 changes: 1 addition & 1 deletion src/Contao/Event/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ private static function renderSimpleCheckbox(
return;
}

$event->setRendered($translator->translate('MSC.' . $map[$value]));
$event->setRendered($translator->translate($map[$value], 'dc-general'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Contao/Picker/AbstractAwarePickerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function createMenuItem(PickerConfig $config)
return $this->menuFactory->createItem(
$name,
[
'label' => $this->translator->trans('TL_LANG.MSC.' . $name, [], 'contao_default'),
'label' => $this->translator->trans('MSC.' . $name, [], 'contao_default'),
'linkAttributes' => ['class' => $name],
'current' => $this->isCurrent($config),
'uri' => $this->generateUrl($config, true)
Expand Down
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 @@ -16,7 +16,7 @@
* @author David Molineus <[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 @@ -76,8 +76,8 @@

use function array_key_exists;
use function implode;
use function str_contains;
use function str_replace;
use function strpos;
use function trigger_error;

/**
Expand Down Expand Up @@ -280,7 +280,7 @@ private function languageSwitcher(EnvironmentInterface $environment)
return $template
->set('languages', $controller->getSupportedLanguages(null))
->set('language', $dataProvider->getCurrentLanguage())
->set('submit', $this->translator->trans('MSC.showSelected', [], 'contao_default'))
->set('submit', $this->translator->trans('change-language', [], 'dc-general'))
->set('REQUEST_TOKEN', $this->tokenManager->getToken($this->tokenName))
->parse();
}
Expand Down Expand Up @@ -323,11 +323,12 @@ protected function translate($key, $domain, array $parameters = [])
$translated = $this->translator->trans($key, $parameters, $domain);

// Fallback translate for non symfony domain.
if ($translated === $key) {
if (null !== $domain && $translated === $key && !str_starts_with($domain, 'contao_')) {
// @codingStandardsIgnoreStart
@trigger_error(
'Fallback translation for contao lang in the global array. ' .
'This will remove in the future, use the symfony domain translation.',
'Fallback translation for contao lang in the global array for key "' . $key .
'" in domain "' . $domain . '". ' .
'This will get removed in the future, use the symfony domain translation.',
E_USER_DEPRECATED
);
// @codingStandardsIgnoreEnd
Expand Down Expand Up @@ -402,7 +403,7 @@ protected function renderTemplate(ContaoBackendViewTemplate $template, Environme
$showColumn = $this->getViewSection($definition)->getListingConfig()->getShowColumns();

$template
->set('subHeadline', $this->translate('MSC.select_models', 'contao_default'))
->set('subHeadline', $this->translator->trans('select_models', [], 'dc-general'))
->set('tableName', ($definition->getName() ?: 'none'))
->set('select', 'select' === $provider->getParameter('act'))
->set('action', StringUtil::ampersand(Environment::get('request')))
Expand All @@ -419,7 +420,7 @@ protected function renderTemplate(ContaoBackendViewTemplate $template, Environme

if (
(null !== $template->get('action'))
&& (false !== strpos($template->get('action'), 'select=models'))
&& (str_contains($template->get('action'), 'select=models'))
) {
$template->set('action', str_replace('select=models', 'select=properties', $template->get('action')));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ private function process(Action $action, EnvironmentInterface $environment): str
$action,
[
'subHeadline' =>
$translator->translate('MSC.' . $inputProvider->getParameter('mode') . 'Selected') . ': ' .
$translator->translate('MSC.all.0'),
$translator->translate($inputProvider->getParameter('mode') . 'Selected', 'dc-general') . ': ' .
$translator->translate('all_label', 'dc-general'),
'fieldsets' => $renderInformation->offsetGet('fieldsets'),
'table' => $definition->getName(),
'error' => $renderInformation->offsetGet('error'),
Expand Down Expand Up @@ -289,7 +289,7 @@ private function renderEditFields(

$fields[] = \sprintf(
'<p>&nbsp;</p><strong>%s</strong><p>&nbsp;</p>',
$translator->translate('MSC.no_properties_available')
$translator->translate('no_properties_available', 'dc-general')
);
}

Expand Down
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 @@ -14,7 +14,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
* @filesource
*/
Expand Down Expand Up @@ -131,8 +131,8 @@ private function process(Action $action, EnvironmentInterface $environment)
$action,
[
'subHeadline' =>
$translator->translate('MSC.' . $inputProvider->getParameter('mode') . 'Selected') . ': ' .
$translator->translate('MSC.all.0'),
$translator->translate($inputProvider->getParameter('mode') . 'Selected', 'dc-general') . ': ' .
$translator->translate('all_label', 'dc-general'),
'fieldsets' => $renderInformation->offsetGet('fieldsets'),
'table' => $definition->getName(),
'error' => $renderInformation->offsetGet('error'),
Expand Down Expand Up @@ -332,7 +332,7 @@ private function renderFieldSets(
if (empty($fieldSet['palette'])) {
$fieldSet['palette'] = \sprintf(
'<p>&nbsp;</p><strong>%s</strong><p>&nbsp;</p>',
$translator->translate('MSC.no_properties_available')
$translator->translate('no_properties_available', 'dc-general')
);
}

Expand Down
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 @@ -13,7 +13,7 @@
* @package contao-community-alliance/dc-general
* @author Sven Baumann <[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
* @filesource
*/
Expand Down Expand Up @@ -234,10 +234,16 @@ private function isPropertyAllowed(PropertyInterface $property, EnvironmentInter
assert($inputProvider instanceof InputProviderInterface);

Message::addInfo(
\sprintf(
$translator->translate('MSC.not_allowed_property_info'),
$property->getLabel() ?: $property->getName(),
$translator->translate('MSC.' . $inputProvider->getParameter('mode') . 'Selected')
$translator->translate(
'not_allowed_property_info',
'dc-general',
[
'%property%' => $property->getLabel() ?: $property->getName(),
'%mode%' => $translator->translate(
$inputProvider->getParameter('mode') . 'Selected',
'dc-general'
)
]
)
);

Expand Down Expand Up @@ -380,8 +386,6 @@ protected function renderTemplate(ContaoBackendViewTemplate $template, Environme
$dataDefinition = $environment->getDataDefinition();
assert($dataDefinition instanceof ContainerInterface);

$languageDomain = 'contao_' . $dataDefinition->getName();

$this->getViewSection($dataDefinition)->getListingConfig()->setShowColumns(false);

parent::renderTemplate($template, $environment);
Expand All @@ -391,8 +395,8 @@ protected function renderTemplate(ContaoBackendViewTemplate $template, Environme
'subHeadline',
\sprintf(
'%s: %s',
$this->translate('MSC.' . $inputProvider->getParameter('mode') . 'Selected', $languageDomain),
$this->translate('MSC.edit_all_select_properties', $languageDomain)
$this->translate($inputProvider->getParameter('mode') . 'Selected', 'dc-general'),
$this->translate('edit_all_select_properties', 'dc-general')
)
)
->set('mode', 'none')
Expand Down Expand Up @@ -427,18 +431,16 @@ protected function getSelectButtons(EnvironmentInterface $environment)
$definition = $environment->getDataDefinition();
assert($definition instanceof ContainerInterface);

$languageDomain = 'contao_' . $definition->getName();

$confirmMessage = \htmlentities(
\sprintf(
'<h2 class="tl_error">%s</h2>' .
'<p></p>' .
'<div class="tl_submit_container">' .
'<input class="%s" value="%s" onclick="%s">' .
'</div>',
StringUtil::specialchars($this->translate('MSC.nothingSelect', $languageDomain)),
StringUtil::specialchars($this->translate('nothingSelect', 'dc-general')),
'tl_submit',
StringUtil::specialchars($this->translate('MSC.close', $languageDomain)),
StringUtil::specialchars($this->translate('close', 'dc-general')),
'BackendGeneral.hideMessage(); return false;'
)
);
Expand All @@ -457,7 +459,7 @@ protected function getSelectButtons(EnvironmentInterface $environment)
$continueName,
$continueName,
'c',
StringUtil::specialchars($this->translate('MSC.continue', $languageDomain)),
StringUtil::specialchars($this->translate('continue', 'dc-general')),
$onClick
)
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function ($value) {
private function translateHeaderColumnName($field, $parentName)
{
return ('tstamp' === $field)
? $this->translate('MSC.tstamp', 'contao_default')
? $this->translate('tstamp', 'dc-general')
: $this->translate(\sprintf('%s.0', $field), $parentName);
}

Expand Down Expand Up @@ -294,8 +294,8 @@ private function renderForCheckbox(PropertyInterface $property, $value, &$isRend
$isRendered = true;

return !empty($value)
? $this->translate('MSC.yes', 'contao_default')
: $this->translate('MSC.no', 'contao_default');
? $this->translate('yes', 'dc-general')
: $this->translate('no', 'dc-general');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ private function handleGlobalCommands(EnvironmentInterface $environment)

$closeCommand
->setName('close_all_button')
->setLabel('MSC.closeAll.0')
->setDescription('MSC.closeAll.1')
->setLabel('closeAll_label')
->setDescription('closeAll_description')
->setParameters(new ArrayObject())
->setExtra(new ArrayObject($closeExtra))
->setDisabled(false);
Expand Down
26 changes: 13 additions & 13 deletions src/Contao/View/Contao2BackendView/ActionHandler/ShowHandler.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 @@ -16,7 +16,7 @@
* @author Sven Baumann <[email protected]>
* @author David Molineus <[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 @@ -208,9 +208,9 @@ protected function getPropertyLabel(EnvironmentInterface $environment, PropertyI
return $label;
}

$mscKey = 'MSC.' . $property->getName() . '.0';
$label = $translator->translate($mscKey);
if ($label !== $mscKey) {
$translationKey = $property->getName() . '_label';
$label = $translator->translate($translationKey, 'dc-general');
if ($label !== $translationKey) {
return $label;
}

Expand Down Expand Up @@ -292,19 +292,19 @@ protected function convertModel(ModelInterface $model, EnvironmentInterface $env
protected function getHeadline(TranslatorInterface $translator, $model)
{
$headline = $translator->translate(
'MSC.showRecord',
'showRecord',
$model->getProviderName(),
['ID ' . $model->getId()]
['%id%' => 'ID ' . $model->getId()]
);

if ('MSC.showRecord' !== $headline) {
if ('showRecord' !== $headline) {
return $headline;
}

return $translator->translate(
'MSC.showRecord',
null,
['ID ' . $model->getId()]
'showRecord',
'dc-general',
['%id%' => 'ID ' . $model->getId()]
);
}

Expand Down Expand Up @@ -354,8 +354,8 @@ protected function process(Action $action, EnvironmentInterface $environment)
$template
->set('languages', $controller->getSupportedLanguages($model->getId()))
->set('currentLanguage', $dataProvider->getCurrentLanguage())
->set('languageSubmit', $translator->translate('MSC.showSelected'))
->set('backBT', StringUtil::specialchars($translator->translate('MSC.backBT')))
->set('languageSubmit', $translator->translate('change-language', 'dc-general'))
->set('backBT', StringUtil::specialchars($translator->translate('backBT', 'dc-general')))
->set('REQUEST_TOKEN', $this->tokenManager->getToken($this->tokenName));
} else {
$template->set('languages', null);
Expand Down
Loading

0 comments on commit 97afb24

Please sign in to comment.