Parser.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Translation\Model\Inline;
  7. /**
  8. * This class is responsible for parsing content and applying necessary html element
  9. * wrapping and client scripts for inline translation.
  10. *
  11. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  12. */
  13. class Parser implements \Magento\Framework\Translate\Inline\ParserInterface
  14. {
  15. /**
  16. * data-translate html element attribute name
  17. */
  18. const DATA_TRANSLATE = 'data-translate';
  19. /**
  20. * Response body or JSON content string
  21. *
  22. * @var string
  23. */
  24. protected $_content;
  25. /**
  26. * Current content is JSON or Response body
  27. *
  28. * @var bool
  29. */
  30. protected $_isJson = false;
  31. /**
  32. * Get max translate block in same tag
  33. *
  34. * @var int
  35. */
  36. protected $_maxTranslateBlocks = 7;
  37. /**
  38. * List of global tags
  39. *
  40. * @var array
  41. */
  42. protected $_allowedTagsGlobal = ['script' => 'String in Javascript', 'title' => 'Page title'];
  43. /**
  44. * List of simple tags
  45. *
  46. * @var array
  47. */
  48. protected $_allowedTagsSimple = [
  49. 'legend' => 'Caption for the fieldset element',
  50. 'label' => 'Label for an input element.',
  51. 'button' => 'Push button',
  52. 'a' => 'Link label',
  53. 'b' => 'Bold text',
  54. 'strong' => 'Strong emphasized text',
  55. 'i' => 'Italic text',
  56. 'em' => 'Emphasized text',
  57. 'u' => 'Underlined text',
  58. 'sup' => 'Superscript text',
  59. 'sub' => 'Subscript text',
  60. 'span' => 'Span element',
  61. 'small' => 'Smaller text',
  62. 'big' => 'Bigger text',
  63. 'address' => 'Contact information',
  64. 'blockquote' => 'Long quotation',
  65. 'q' => 'Short quotation',
  66. 'cite' => 'Citation',
  67. 'caption' => 'Table caption',
  68. 'abbr' => 'Abbreviated phrase',
  69. 'acronym' => 'An acronym',
  70. 'var' => 'Variable part of a text',
  71. 'dfn' => 'Term',
  72. 'strike' => 'Strikethrough text',
  73. 'del' => 'Deleted text',
  74. 'ins' => 'Inserted text',
  75. 'h1' => 'Heading level 1',
  76. 'h2' => 'Heading level 2',
  77. 'h3' => 'Heading level 3',
  78. 'h4' => 'Heading level 4',
  79. 'h5' => 'Heading level 5',
  80. 'h6' => 'Heading level 6',
  81. 'center' => 'Centered text',
  82. 'select' => 'List options',
  83. 'img' => 'Image',
  84. 'input' => 'Form element',
  85. ];
  86. /**
  87. * @var \Magento\Translation\Model\ResourceModel\StringFactory
  88. */
  89. protected $_resourceFactory;
  90. /**
  91. * @var \Magento\Store\Model\StoreManagerInterface
  92. */
  93. protected $_storeManager;
  94. /**
  95. * @var \Zend_Filter_Interface
  96. */
  97. protected $_inputFilter;
  98. /**
  99. * @var \Magento\Framework\App\State
  100. */
  101. protected $_appState;
  102. /**
  103. * @var \Magento\Framework\Translate\InlineInterface
  104. */
  105. protected $_translateInline;
  106. /**
  107. * @var \Magento\Framework\App\Cache\TypeListInterface
  108. */
  109. protected $_appCache;
  110. /**
  111. * @var \Magento\Translation\Model\Inline\CacheManager
  112. */
  113. private $cacheManager;
  114. /**
  115. * @var array
  116. */
  117. private $relatedCacheTypes;
  118. /**
  119. * @return \Magento\Translation\Model\Inline\CacheManager
  120. *
  121. * @deprecated 100.1.0
  122. */
  123. private function getCacheManger()
  124. {
  125. if (!$this->cacheManager instanceof \Magento\Translation\Model\Inline\CacheManager) {
  126. $this->cacheManager = \Magento\Framework\App\ObjectManager::getInstance()->get(
  127. \Magento\Translation\Model\Inline\CacheManager::class
  128. );
  129. }
  130. return $this->cacheManager;
  131. }
  132. /**
  133. * Initialize base inline translation model
  134. *
  135. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  136. * @param \Magento\Translation\Model\ResourceModel\StringUtilsFactory $resource
  137. * @param \Zend_Filter_Interface $inputFilter
  138. * @param \Magento\Framework\App\State $appState
  139. * @param \Magento\Framework\App\Cache\TypeListInterface $appCache
  140. * @param \Magento\Framework\Translate\InlineInterface $translateInline
  141. * @param array $relatedCacheTypes
  142. */
  143. public function __construct(
  144. \Magento\Translation\Model\ResourceModel\StringUtilsFactory $resource,
  145. \Magento\Store\Model\StoreManagerInterface $storeManager,
  146. \Zend_Filter_Interface $inputFilter,
  147. \Magento\Framework\App\State $appState,
  148. \Magento\Framework\App\Cache\TypeListInterface $appCache,
  149. \Magento\Framework\Translate\InlineInterface $translateInline,
  150. array $relatedCacheTypes = []
  151. ) {
  152. $this->_resourceFactory = $resource;
  153. $this->_storeManager = $storeManager;
  154. $this->_inputFilter = $inputFilter;
  155. $this->_appState = $appState;
  156. $this->_appCache = $appCache;
  157. $this->_translateInline = $translateInline;
  158. $this->relatedCacheTypes = $relatedCacheTypes;
  159. }
  160. /**
  161. * Parse and save edited translation
  162. *
  163. * @param array $translateParams
  164. * @return array
  165. */
  166. public function processAjaxPost(array $translateParams)
  167. {
  168. if (!$this->_translateInline->isAllowed()) {
  169. return ['inline' => 'not allowed'];
  170. }
  171. if (!empty($this->relatedCacheTypes)) {
  172. $this->_appCache->invalidate($this->relatedCacheTypes);
  173. }
  174. $this->_validateTranslationParams($translateParams);
  175. $this->_filterTranslationParams($translateParams, ['custom']);
  176. /** @var $validStoreId int */
  177. $validStoreId = $this->_storeManager->getStore()->getId();
  178. /** @var $resource \Magento\Translation\Model\ResourceModel\StringUtils */
  179. $resource = $this->_resourceFactory->create();
  180. foreach ($translateParams as $param) {
  181. if ($this->_appState->getAreaCode() == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
  182. $storeId = 0;
  183. } else {
  184. if (empty($param['perstore'])) {
  185. $resource->deleteTranslate($param['original'], null, false);
  186. $storeId = 0;
  187. } else {
  188. $storeId = $validStoreId;
  189. }
  190. }
  191. $resource->saveTranslate($param['original'], $param['custom'], null, $storeId);
  192. }
  193. return $this->getCacheManger()->updateAndGetTranslations();
  194. }
  195. /**
  196. * Validate the structure of translation parameters
  197. *
  198. * @param array $translateParams
  199. * @return void
  200. * @throws \InvalidArgumentException
  201. */
  202. protected function _validateTranslationParams(array $translateParams)
  203. {
  204. foreach ($translateParams as $param) {
  205. if (!is_array($param) || !isset($param['original']) || !isset($param['custom'])) {
  206. throw new \InvalidArgumentException(
  207. 'Both original and custom phrases are required for inline translation.'
  208. );
  209. }
  210. }
  211. }
  212. /**
  213. * Apply input filter to values of translation parameters
  214. *
  215. * @param array &$translateParams
  216. * @param array $fieldNames Names of fields values of which are to be filtered
  217. * @return void
  218. */
  219. protected function _filterTranslationParams(array &$translateParams, array $fieldNames)
  220. {
  221. foreach ($translateParams as &$param) {
  222. foreach ($fieldNames as $fieldName) {
  223. $param[$fieldName] = $this->_inputFilter->filter($param[$fieldName]);
  224. }
  225. }
  226. }
  227. /**
  228. * Replace html body with translation wrapping.
  229. *
  230. * @param string $body
  231. * @return string
  232. */
  233. public function processResponseBodyString($body)
  234. {
  235. $this->_content = $body;
  236. $this->_specialTags();
  237. $this->_tagAttributes();
  238. $this->_otherText();
  239. return $this->_content;
  240. }
  241. /**
  242. * Returns the body content that is being parsed.
  243. *
  244. * @return string
  245. */
  246. public function getContent()
  247. {
  248. return $this->_content;
  249. }
  250. /**
  251. * Sets the body content that is being parsed passed upon the passed in string.
  252. *
  253. * @param string $content
  254. * @return void
  255. */
  256. public function setContent($content)
  257. {
  258. $this->_content = $content;
  259. }
  260. /**
  261. * Set flag about parsed content is Json
  262. *
  263. * @param bool $flag
  264. * @return $this
  265. */
  266. public function setIsJson($flag)
  267. {
  268. $this->_isJson = $flag;
  269. return $this;
  270. }
  271. /**
  272. * Get attribute location.
  273. *
  274. * @param array $matches
  275. * @param array $options
  276. * @return string
  277. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  278. */
  279. protected function _getAttributeLocation($matches, $options)
  280. {
  281. // return value should not be translated.
  282. return 'Tag attribute (ALT, TITLE, etc.)';
  283. }
  284. /**
  285. * Get tag location
  286. *
  287. * @param array $matches
  288. * @param array $options
  289. * @return string
  290. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  291. */
  292. protected function _getTagLocation($matches, $options)
  293. {
  294. $tagName = strtolower($options['tagName']);
  295. if (isset($options['tagList'][$tagName])) {
  296. return $options['tagList'][$tagName];
  297. }
  298. return ucfirst($tagName) . ' Text';
  299. }
  300. /**
  301. * Format translation for special tags. Adding translate mode attribute for vde requests.
  302. *
  303. * @param string $tagHtml
  304. * @param string $tagName
  305. * @param array $trArr
  306. * @return string
  307. */
  308. protected function _applySpecialTagsFormat($tagHtml, $tagName, $trArr)
  309. {
  310. $specialTags = $tagHtml . '<span class="translate-inline-' . $tagName . '" ' . $this->_getHtmlAttribute(
  311. self::DATA_TRANSLATE,
  312. '[' . htmlspecialchars(join(',', $trArr)) . ']'
  313. );
  314. $additionalAttr = $this->_getAdditionalHtmlAttribute($tagName);
  315. if ($additionalAttr !== null) {
  316. $specialTags .= ' ' . $additionalAttr . '>';
  317. } else {
  318. $specialTags .= '>' . strtoupper($tagName);
  319. }
  320. $specialTags .= '</span>';
  321. return $specialTags;
  322. }
  323. /**
  324. * Format translation for simple tags. Added translate mode attribute for vde requests.
  325. *
  326. * @param string $tagHtml
  327. * @param string $tagName
  328. * @param array $trArr
  329. * @return string
  330. */
  331. protected function _applySimpleTagsFormat($tagHtml, $tagName, $trArr)
  332. {
  333. $simpleTags = substr(
  334. $tagHtml,
  335. 0,
  336. strlen($tagName) + 1
  337. ) . ' ' . $this->_getHtmlAttribute(
  338. self::DATA_TRANSLATE,
  339. htmlspecialchars('[' . join(',', $trArr) . ']')
  340. );
  341. $additionalAttr = $this->_getAdditionalHtmlAttribute($tagName);
  342. if ($additionalAttr !== null) {
  343. $simpleTags .= ' ' . $additionalAttr;
  344. }
  345. $simpleTags .= substr($tagHtml, strlen($tagName) + 1);
  346. return $simpleTags;
  347. }
  348. /**
  349. * Get translate data by regexp
  350. *
  351. * @param string $regexp
  352. * @param string &$text
  353. * @param string|array $locationCallback
  354. * @param array $options
  355. * @return array
  356. */
  357. private function _getTranslateData($regexp, &$text, $locationCallback, $options = [])
  358. {
  359. $trArr = [];
  360. $next = 0;
  361. while (preg_match($regexp, $text, $matches, PREG_OFFSET_CAPTURE, $next)) {
  362. $trArr[] = json_encode(
  363. [
  364. 'shown' => htmlspecialchars_decode($matches[1][0]),
  365. 'translated' => htmlspecialchars_decode($matches[2][0]),
  366. 'original' => htmlspecialchars_decode($matches[3][0]),
  367. 'location' => htmlspecialchars_decode(call_user_func($locationCallback, $matches, $options)),
  368. ]
  369. );
  370. $text = substr_replace($text, $matches[1][0], $matches[0][1], strlen($matches[0][0]));
  371. $next = $matches[0][1];
  372. }
  373. return $trArr;
  374. }
  375. /**
  376. * Prepare tags inline translates
  377. *
  378. * @return void
  379. */
  380. private function _tagAttributes()
  381. {
  382. $this->_prepareTagAttributesForContent($this->_content);
  383. }
  384. /**
  385. * Prepare tags inline translates for the content
  386. *
  387. * @param string &$content
  388. * @return void
  389. */
  390. private function _prepareTagAttributesForContent(&$content)
  391. {
  392. $quoteHtml = $this->_getHtmlQuote();
  393. $tagMatch = [];
  394. $nextTag = 0;
  395. $tagRegExp = '#<([a-z]+)\s*?[^>]+?((' . self::REGEXP_TOKEN . ')[^>]*?)+\\\\?/?>#iS';
  396. while (preg_match($tagRegExp, $content, $tagMatch, PREG_OFFSET_CAPTURE, $nextTag)) {
  397. $tagHtml = $tagMatch[0][0];
  398. $matches = [];
  399. $attrRegExp = '#' . self::REGEXP_TOKEN . '#S';
  400. $trArr = $this->_getTranslateData($attrRegExp, $tagHtml, [$this, '_getAttributeLocation']);
  401. if ($trArr) {
  402. $transRegExp = '# ' . $this->_getHtmlAttribute(
  403. self::DATA_TRANSLATE,
  404. '\[([^' . preg_quote($quoteHtml) . ']*)]'
  405. ) . '#i';
  406. if (preg_match($transRegExp, $tagHtml, $matches)) {
  407. $tagHtml = str_replace($matches[0], '', $tagHtml);
  408. $trAttr = ' ' . $this->_getHtmlAttribute(
  409. self::DATA_TRANSLATE,
  410. '[' . htmlspecialchars($matches[1]) . ',' . str_replace("\"", "'", join(',', $trArr)) . ']'
  411. );
  412. } else {
  413. $trAttr = ' ' . $this->_getHtmlAttribute(
  414. self::DATA_TRANSLATE,
  415. '[' . str_replace("\"", "'", join(',', $trArr)) . ']'
  416. );
  417. }
  418. $trAttr = $this->_addTranslateAttribute($trAttr);
  419. $tagHtml = substr_replace($tagHtml, $trAttr, strlen($tagMatch[1][0]) + 1, 1);
  420. $content = substr_replace($content, $tagHtml, $tagMatch[0][1], strlen($tagMatch[0][0]));
  421. }
  422. $nextTag = $tagMatch[0][1] + strlen($tagHtml);
  423. }
  424. }
  425. /**
  426. * Get html element attribute
  427. *
  428. * @param string $name
  429. * @param string $value
  430. * @return string
  431. */
  432. private function _getHtmlAttribute($name, $value)
  433. {
  434. return $name . '=' . $this->_getHtmlQuote() . $value . $this->_getHtmlQuote();
  435. }
  436. /**
  437. * Add data-translate-mode attribute
  438. *
  439. * @param string $trAttr
  440. * @return string
  441. */
  442. private function _addTranslateAttribute($trAttr)
  443. {
  444. $translateAttr = $trAttr;
  445. $additionalAttr = $this->_getAdditionalHtmlAttribute();
  446. if ($additionalAttr !== null) {
  447. $translateAttr .= ' ' . $additionalAttr . ' ';
  448. }
  449. return $translateAttr;
  450. }
  451. /**
  452. * Get html quote symbol
  453. *
  454. * @return string
  455. */
  456. private function _getHtmlQuote()
  457. {
  458. if ($this->_isJson) {
  459. return '\"';
  460. } else {
  461. return '"';
  462. }
  463. }
  464. /**
  465. * Prepare special tags
  466. *
  467. * @return void
  468. */
  469. private function _specialTags()
  470. {
  471. $this->_translateTags($this->_content, $this->_allowedTagsGlobal, '_applySpecialTagsFormat');
  472. $this->_translateTags($this->_content, $this->_allowedTagsSimple, '_applySimpleTagsFormat');
  473. }
  474. /**
  475. * Prepare simple tags
  476. *
  477. * @param string &$content
  478. * @param array $tagsList
  479. * @param string|array $formatCallback
  480. * @return void
  481. */
  482. private function _translateTags(&$content, $tagsList, $formatCallback)
  483. {
  484. $nextTag = 0;
  485. $tagRegExpBody = '#<(body)(/?>| \s*[^>]*+/?>)#iSU';
  486. $tags = implode('|', array_keys($tagsList));
  487. $tagRegExp = '#<(' . $tags . ')(/?>| \s*[^>]*+/?>)#iSU';
  488. $tagMatch = [];
  489. $headTranslateTags = '';
  490. while (preg_match($tagRegExp, $content, $tagMatch, PREG_OFFSET_CAPTURE, $nextTag)) {
  491. $tagName = strtolower($tagMatch[1][0]);
  492. if (substr($tagMatch[0][0], -2) == '/>') {
  493. $tagClosurePos = $tagMatch[0][1] + strlen($tagMatch[0][0]);
  494. } else {
  495. $tagClosurePos = $this->_findEndOfTag($content, $tagName, $tagMatch[0][1]);
  496. }
  497. if ($tagClosurePos === false) {
  498. $nextTag += strlen($tagMatch[0][0]);
  499. continue;
  500. }
  501. $tagLength = $tagClosurePos - $tagMatch[0][1];
  502. $tagStartLength = strlen($tagMatch[0][0]);
  503. $tagHtml = $tagMatch[0][0] . substr(
  504. $content,
  505. $tagMatch[0][1] + $tagStartLength,
  506. $tagLength - $tagStartLength
  507. );
  508. $tagClosurePos = $tagMatch[0][1] + strlen($tagHtml);
  509. $trArr = $this->_getTranslateData(
  510. '#' . self::REGEXP_TOKEN . '#iS',
  511. $tagHtml,
  512. [$this, '_getTagLocation'],
  513. ['tagName' => $tagName, 'tagList' => $tagsList]
  514. );
  515. if (!empty($trArr)) {
  516. $trArr = array_unique($trArr);
  517. $tagBodyMatch = [];
  518. preg_match($tagRegExpBody, $content, $tagBodyMatch, PREG_OFFSET_CAPTURE);
  519. if (!empty($tagBodyMatch)) {
  520. $tagBodyOpenStartPosition = $tagBodyMatch[0][1];
  521. if (array_key_exists($tagName, $this->_allowedTagsGlobal)
  522. && $tagBodyOpenStartPosition > $tagMatch[0][1]
  523. ) {
  524. $tagHtmlHead = call_user_func([$this, $formatCallback], $tagHtml, $tagName, $trArr);
  525. $headTranslateTags .= substr($tagHtmlHead, strlen($tagHtml));
  526. } else {
  527. $tagHtml = call_user_func([$this, $formatCallback], $tagHtml, $tagName, $trArr);
  528. }
  529. }
  530. $tagClosurePos = $tagMatch[0][1] + strlen($tagHtml);
  531. $content = substr_replace($content, $tagHtml, $tagMatch[0][1], $tagLength);
  532. }
  533. $nextTag = $tagClosurePos;
  534. }
  535. if ($headTranslateTags) {
  536. $tagBodyMatch = [];
  537. preg_match($tagRegExpBody, $content, $tagBodyMatch, PREG_OFFSET_CAPTURE);
  538. $tagBodyOpenStartPosition = $tagBodyMatch[0][1];
  539. $openTagBodyEndPosition = $tagBodyOpenStartPosition + strlen($tagBodyMatch[0][0]);
  540. $content = substr($content, 0, $openTagBodyEndPosition)
  541. . $headTranslateTags
  542. . substr($content, $openTagBodyEndPosition);
  543. }
  544. }
  545. /**
  546. * Find end of tag
  547. *
  548. * @param string $body
  549. * @param string $tagName
  550. * @param int $from
  551. * @return bool|int return false if end of tag is not found
  552. */
  553. private function _findEndOfTag($body, $tagName, $from)
  554. {
  555. $openTag = '<' . $tagName;
  556. $closeTag = ($this->_isJson ? '<\\/' : '</') . $tagName;
  557. $tagLength = strlen($tagName);
  558. $length = $tagLength + 1;
  559. $end = $from + 1;
  560. while (substr_count($body, $openTag, $from, $length) !== substr_count($body, $closeTag, $from, $length)) {
  561. $end = strpos($body, $closeTag, $end + $tagLength + 1);
  562. if ($end === false) {
  563. return false;
  564. }
  565. $length = $end - $from + $tagLength + 3;
  566. }
  567. if (preg_match('#<\\\\?\/' . $tagName . '\s*?>#i', $body, $tagMatch, null, $end)) {
  568. return $end + strlen($tagMatch[0]);
  569. } else {
  570. return false;
  571. }
  572. }
  573. /**
  574. * Prepare other text inline translates
  575. *
  576. * @return void
  577. */
  578. private function _otherText()
  579. {
  580. $next = 0;
  581. $matches = [];
  582. while (preg_match('#' . self::REGEXP_TOKEN . '#', $this->_content, $matches, PREG_OFFSET_CAPTURE, $next)) {
  583. $translateProperties = json_encode(
  584. [
  585. 'shown' => $matches[1][0],
  586. 'translated' => $matches[2][0],
  587. 'original' => $matches[3][0],
  588. 'location' => 'Text',
  589. 'scope' => $matches[4][0],
  590. ],
  591. JSON_HEX_QUOT
  592. );
  593. $spanHtml = $this->_getDataTranslateSpan(
  594. '[' . htmlspecialchars($translateProperties) . ']',
  595. $matches[1][0]
  596. );
  597. $this->_content = substr_replace($this->_content, $spanHtml, $matches[0][1], strlen($matches[0][0]));
  598. $next = $matches[0][1] + strlen($spanHtml) - 1;
  599. }
  600. }
  601. /**
  602. * Returns the html span that contains the data translate attribute including vde specific translate mode attribute
  603. *
  604. * @param string $data
  605. * @param string $text
  606. * @return string
  607. */
  608. protected function _getDataTranslateSpan($data, $text)
  609. {
  610. $translateSpan = '<span ' . $this->_getHtmlAttribute(self::DATA_TRANSLATE, $data);
  611. $additionalAttr = $this->_getAdditionalHtmlAttribute();
  612. if ($additionalAttr !== null) {
  613. $translateSpan .= ' ' . $additionalAttr;
  614. }
  615. $translateSpan .= '>' . $text . '</span>';
  616. return $translateSpan;
  617. }
  618. /**
  619. * Add an additional html attribute if needed.
  620. *
  621. * @param mixed $tagName
  622. * @return string
  623. */
  624. protected function _getAdditionalHtmlAttribute($tagName = null)
  625. {
  626. return $this->_translateInline->getAdditionalHtmlAttribute($tagName);
  627. }
  628. }