Skip to content

Commit e677f64

Browse files
committed
AC-3226::i18n:collect-phrases does not include titles in layout files
1 parent 365fdc0 commit e677f64

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Xml.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ class Xml extends AbstractAdapter
2020
*/
2121
protected function _parse()
2222
{
23-
foreach ($this->_getNodes($this->_file) as $element) {
23+
foreach ($this->_getNodes($this->_file) as $key => $element) {
2424
if (!$element instanceof \SimpleXMLElement) {
2525
continue;
2626
}
27-
$attributes = $element->attributes();
28-
if ((string)$attributes['translate'] === 'true' || (string)$attributes['translatable'] === 'true') {
27+
28+
$attributes = (string)$key ==='title' ? $element : $element->attributes();
29+
30+
if ((string)$attributes['translate'] === 'true' || (string)$attributes['translatable'] === 'true' ) {
2931
$this->_addPhrase((string)$element);
32+
} else if (isset($attributes->title)) {
33+
$this->_addPhrase((string)$element->title);
3034
} else {
3135
$this->parseTranslatableNodes($attributes, $element);
3236
}
@@ -44,8 +48,13 @@ protected function _getNodes($file)
4448
libxml_use_internal_errors(true);
4549
$xml = simplexml_load_file($file);
4650
libxml_use_internal_errors(false);
51+
4752
if ($xml) {
4853
$nodes = $xml->xpath('//*[@translate|@translatable]');
54+
/* To add title of all xml files in translation csv */
55+
if($xml->head){
56+
$nodes['title'] = $xml->head;
57+
}
4958
unset($xml);
5059

5160
return is_array($nodes) ? $nodes : [];

setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/XmlTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function parseDataProvider()
6060
['phrase' => 'Phrase 3', 'file' => $default, 'line' => '', 'quote' => ''],
6161
['phrase' => 'Phrase 1', 'file' => $default, 'line' => '', 'quote' => ''],
6262
['phrase' => 'Comment from new line.', 'file' => $default, 'line' => '', 'quote' => ''],
63+
['phrase' => 'Title', 'file' => $default, 'line' => '', 'quote' => ''],
6364
],
6465
],
6566
[

setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/_files/default.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
-->
88

99
<layout>
10+
<head>
11+
<title>Title</title>
12+
</head>
1013
<node1 translate="description, label">
1114
<description>Phrase 1</description>
1215
<label>Phrase 2</label>

0 commit comments

Comments
 (0)