Skip to content

Commit

Permalink
Changes for MM xliff
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed May 13, 2024
1 parent 898f7e3 commit 5b8a374
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,16 @@ protected function translate($key, $domain, array $parameters = [])
);
// @codingStandardsIgnoreEnd

$oldKey = sprintf('%s.%s', $domain, $key);
$translated =
$this->translator->trans(
sprintf('%s.%s', $domain, $key),
$oldKey,
$parameters,
sprintf('contao_%s', $domain)
);
if ($translated === $oldKey) {
return $key;
}
}

return $translated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ private function translateHeaderColumnName($field, $parentName)
// FIXME: deprecation here? - old translation handling.

return ('tstamp' === $field)
? $this->translate('tstamp', 'contao_dc-general')
: $this->translate(\sprintf('%s.0', $field), 'contao_' . $parentName);
? $this->translate('tstamp', 'dc-general')
: $this->translate(\sprintf('%s.0', $field), $parentName);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/Contao/View/Contao2BackendView/ButtonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,15 @@ protected function translateButtonDescription(
return $header;
}

return $this->translator->translate($buttonName . '.1', $definitionName, $parameter);
if (
1 !== preg_match('#%(?:[bcdeEfFgGhHosuxX]|\d*\$[bcdeEfFgGhHosuxX])#', $buttonName)
&& $definitionName . '.' . $buttonName . '.1'
!== ($header = $this->translator->translate($definitionName . '.' . $buttonName . '.1', 'contao_' . $definitionName, $parameter))

Check warning on line 664 in src/Contao/View/Contao2BackendView/ButtonRenderer.php

View workflow job for this annotation

GitHub Actions / PHP: 8.1 Contao: ~4.13.0

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

Check warning on line 664 in src/Contao/View/Contao2BackendView/ButtonRenderer.php

View workflow job for this annotation

GitHub Actions / PHP: 8.2 Contao: ~4.13.0

Line exceeds 120 characters; contains 141 characters (reported by phpcs: Generic.Files.LineLength.TooLong)
) {
return $header;
}

return vsprintf($buttonName, $parameter);
}

/**
Expand Down
22 changes: 19 additions & 3 deletions src/Contao/View/Contao2BackendView/GlobalButtonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ private function renderButton(CommandInterface $command)
{
$extra = $command->getExtra();
$label = $this->translate($command->getLabel());
// Translation fallback to old Contao translations.
// @deprecated Remove in 3.0
if (str_ends_with($label, '.label') && $label === $command->getLabel()) {
$label = $this->translate(substr($command->getLabel(), 0, -6) . '.0');
}

$description = $this->translate($command->getDescription());
// Translation fallback to old Contao translations.
// @deprecated Remove in 3.0
if (str_ends_with($description, '.description') && $description === $command->getDescription()) {
$description = $this->translate(substr($command->getDescription(), 0, -12) . '.1');
}

if (isset($extra['href'])) {
$href = $extra['href'];
Expand Down Expand Up @@ -150,7 +162,7 @@ private function renderButton(CommandInterface $command)
->setKey($command->getName())
->setHref($href)
->setLabel($label)
->setTitle($this->translate($command->getDescription()));
->setTitle($description);
$this->dispatcher->dispatch($buttonEvent, GetGlobalButtonEvent::NAME);

// Allow to override the button entirely - if someone sets empty string, we keep it.
Expand Down Expand Up @@ -181,8 +193,12 @@ private function translate(string $path): string
$definition = $this->environment->getDataDefinition();
assert($definition instanceof ContainerInterface);

$value = $this->translator->translate($path, $definition->getName());
if ($path !== $value) {
$domain = $definition->getName();
if ($path !== ($value = $this->translator->translate($path, $domain))) {
return $value;
}
// Fallback translate for non symfony domain.
if ($domain . '.' . $path !== ($value = $this->translator->translate($domain . '.' . $path, 'contao_' . $domain))) {

Check warning on line 201 in src/Contao/View/Contao2BackendView/GlobalButtonRenderer.php

View workflow job for this annotation

GitHub Actions / PHP: 8.1 Contao: ~4.13.0

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

Check warning on line 201 in src/Contao/View/Contao2BackendView/GlobalButtonRenderer.php

View workflow job for this annotation

GitHub Actions / PHP: 8.2 Contao: ~4.13.0

Line exceeds 120 characters; contains 124 characters (reported by phpcs: Generic.Files.LineLength.TooLong)
return $value;
}

Expand Down

0 comments on commit 5b8a374

Please sign in to comment.