Skip to content

Commit

Permalink
[framework] fixed dumping translations by adding support for translat…
Browse files Browse the repository at this point in the history
…ion domain constants (#2561)
  • Loading branch information
TomasLudvik committed Feb 16, 2023
2 parents 5819fd4 + ffa43a8 commit 40da3d3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Scalar\String_;
use Shopsys\FrameworkBundle\Component\Translation\Exception\StringValueUnextractableException;
use SplFileInfo;

class PhpParserNodeHelper
{
protected const TRANSLATOR_CLASS_FQN = '\Shopsys\FrameworkBundle\Component\Translation\Translator';

/**
* @param \PhpParser\Node $node
* @param \SplFileInfo $fileInfo
Expand All @@ -28,10 +31,15 @@ public static function getConcatenatedStringValue(Node $node, SplFileInfo $fileI
);
}

if ($node instanceof ClassConstFetch && $node->class->parts[0] === 'Translator') {
return constant(static::TRANSLATOR_CLASS_FQN . '::' . $node->name->name);
}

throw new StringValueUnextractableException(
sprintf(
'Can only extract the message ID or message domain from a scalar or concatenated string,'
'Can only extract the message ID or message domain from a scalar, concatenated string or "%s" class constant,'
. ' but got "%s". Please refactor your code to make it extractable (in %s on line %d).',
static::TRANSLATOR_CLASS_FQN,
get_class($node),
$fileInfo,
$node->getLine()
Expand Down
3 changes: 3 additions & 0 deletions packages/framework/src/Resources/translations/messages.cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ msgstr "Vytvořeno administrátorem"
msgid "Created on"
msgstr "Vytvořeno dne"

msgid "Creation date"
msgstr "Datum vytvoření"

msgid "Cron overview"
msgstr "Přehled cronů"

Expand Down
3 changes: 3 additions & 0 deletions packages/framework/src/Resources/translations/messages.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ msgstr ""
msgid "Created on"
msgstr ""

msgid "Creation date"
msgstr ""

msgid "Cron overview"
msgstr ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ msgstr "Vyplňte prosím kurz měny"
msgid "Please enter currency minimum fraction digits"
msgstr "Prosím zadejte minimální počet desetinných míst měny"

msgid "Please enter date of creation"
msgstr "Vyplňte prosím datum vytvoření"

msgid "Please enter default VAT"
msgstr "Prosím zadejte výchozí výši DPH"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ msgstr ""
msgid "Please enter currency minimum fraction digits"
msgstr ""

msgid "Please enter date of creation"
msgstr ""

msgid "Please enter default VAT"
msgstr ""

Expand Down
3 changes: 0 additions & 3 deletions project-base/translations/validators.cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ msgstr "Vyplňte prosím název firmy"
msgid "Please enter content"
msgstr "Vyplňte prosím text"

msgid "Please enter date of creation"
msgstr "Vyplňte prosím datum vytvoření"

msgid "Please enter email"
msgstr "Vyplňte prosím e-mail"

Expand Down
3 changes: 0 additions & 3 deletions project-base/translations/validators.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ msgstr ""
msgid "Please enter content"
msgstr ""

msgid "Please enter date of creation"
msgstr ""

msgid "Please enter email"
msgstr ""

Expand Down

0 comments on commit 40da3d3

Please sign in to comment.