Skip to content

Commit

Permalink
added parameter to check if its from attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
sircxes committed Dec 6, 2024
1 parent 0643171 commit 6a81814
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/View/Helper/MelisSiteTranslationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ public function setServiceManager(ServiceManager $serviceManager)
* @param string $key
* @param int $langId
* @param int $siteId
* @param boolean $isInAttribute - check if the translations is put inside an attribute like placeholder or title
* @return string
*/
public function __invoke($key, $langId, $siteId)
public function __invoke($key, $langId, $siteId, $isInAttribute = false)
{
$siteTransSrv = $this->serviceManager->get('MelisSiteTranslationService');

Expand All @@ -46,16 +47,24 @@ public function __invoke($key, $langId, $siteId)
}
$str = $cacheData[$langId][$key] ?? $key;


if(!empty($this->getView()->renderMode)){
if($this->getView()->renderMode != 'front'){
$str = '<span title="'.$key.'">'.$str.'</span>';
}
}else{//try to check uri if we are in BO
$uri = $_SERVER['REQUEST_URI'];
$uri = explode('/', $uri);
if(in_array('renderMode', $uri)){
$str = '<span title="'.$key.'">'.$str.'</span>';
/**
* We modify only the translation if we are not inside
* an attribute since html attribute don't accept
* html tag like span
*/
if(!$isInAttribute) {
if (!empty($this->getView()->renderMode)) {
if ($this->getView()->renderMode != 'front') {
//return translation with a span so they can see the key when they hover the text
$str = '<span title="' . $key . '">' . $str . '</span>';
}
} else {//try to check uri if we are in BO
$uri = $_SERVER['REQUEST_URI'];
$uri = explode('/', $uri);
if (in_array('renderMode', $uri)) {
//return translation with a span so they can see the key when they hover the text
$str = '<span title="' . $key . '">' . $str . '</span>';
}
}
}

Expand Down

0 comments on commit 6a81814

Please sign in to comment.