From d09b736a96bf5ae9f0fcc9cd8c829248b473dab6 Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Sat, 18 Jun 2022 20:31:25 +0200 Subject: [PATCH] Process nested trans directives, fixes #35449 --- .../Command/_files/expectedPhrases.csv | 3 ++ .../_files/phrases/test_mail_template.html | 28 +++++++++++++++++++ .../Setup/Module/I18n/Parser/Adapter/Html.php | 15 +++++++--- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/test_mail_template.html diff --git a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv index f1efc31fa0d38..1d50db5f74fed 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv +++ b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv @@ -18,4 +18,7 @@ "string with escaped ""double quotes""","string with escaped ""double quotes""" "string with placeholder in escaped double quotes ""%1""","string with placeholder in escaped double quotes ""%1""" "string that's got an unclosed single quote in it","string that's got an unclosed single quote in it" +"Thank you for your order from %store_name.","Thank you for your order from %store_name." +"Our hours are %store_hours.","Our hours are %store_hours." +"Translation inside if directive","Translation inside if directive" "Test di text","Test di text" diff --git a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/test_mail_template.html b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/test_mail_template.html new file mode 100644 index 0000000000000..bcfd42c1dc306 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/test_mail_template.html @@ -0,0 +1,28 @@ + + +{{template config_path="design/email/header_template"}} + + + + + +
+ +{{template config_path="design/email/footer_template"}} diff --git a/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Html.php b/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Html.php index d70e5c6a81c37..11f7f0ae73454 100644 --- a/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Html.php +++ b/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Html.php @@ -50,6 +50,14 @@ protected function _parse() throw new Exception('Failed to load file from disk.'); } + $this->extractPhrasesFromTransDirective($data); + $this->extractPhrases(self::REGEX_I18N_BINDING, $data, 2, 1); + $this->extractPhrases(self::REGEX_TRANSLATE_TAG_OR_ATTR, $data, 3, 2); + $this->extractPhrases(Js::REGEX_TRANSLATE_FUNCTION, $data, 3, 2); + } + + private function extractPhrasesFromTransDirective(string $data): void + { $results = []; preg_match_all(Filter::CONSTRUCTION_PATTERN, $data, $results, PREG_SET_ORDER); for ($i = 0, $count = count($results); $i < $count; $i++) { @@ -61,12 +69,11 @@ protected function _parse() $quote = $directive[1]; $this->_addPhrase($quote . $directive[2] . $quote); + } elseif (in_array($results[$i][1], ['depend', 'if'], true) && isset($results[$i][3])) { + // make sure to process trans directives nested inside depend / if directives + $this->extractPhrasesFromTransDirective($results[$i][3]); } } - - $this->extractPhrases(self::REGEX_I18N_BINDING, $data, 2, 1); - $this->extractPhrases(self::REGEX_TRANSLATE_TAG_OR_ATTR, $data, 3, 2); - $this->extractPhrases(Js::REGEX_TRANSLATE_FUNCTION, $data, 3, 2); } /**