Skip to content

Commit

Permalink
Process nested trans directives, fixes #35449
Browse files Browse the repository at this point in the history
  • Loading branch information
sprankhub committed Jun 18, 2022
1 parent 28c1f28 commit d09b736
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span class=""no-link"">%store_hours</span>.","Our hours are <span class=""no-link"">%store_hours</span>."
"Translation inside if directive","Translation inside if directive"
"Test di text","Test di text"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

{{template config_path="design/email/header_template"}}

<table>
<tr class="email-intro">
<td>
<p>
{{trans "Thank you for your order from %store_name." store_name=$store.frontend_name}}
</p>
<p>
{{depend store_hours}}
{{trans 'Our hours are <span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
{{/depend}}
</p>
{{if something}}
<p>{{trans 'Translation inside if directive'}}</p>
{{/if}}
</td>
</tr>
</table>

{{template config_path="design/email/footer_template"}}
15 changes: 11 additions & 4 deletions setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit d09b736

Please sign in to comment.