的Prestashop爲此提供了一個無證的解決方案:
您可以添加{l}
函數調用內部的tags
參數。此參數的值是一個字符串數組。從這個數組字符串中添加一個標籤,你需要使用[i]x[/i]
(其中i
爲1和x
從數組標籤索引要看到標籤包圍的文本)
例如,如果我想使這個字符串在一個單一的翻譯線:
<strong>Welcome</strong> <i class="name_class">Florian Lemaitre</i>!
我可以使用此代碼:
{l s='[1]Welcome[/1] [2]%s[/2]!' sprintf=[$name] tags=['<strong>', '<i class="name_class">']}
你的情況,你可以使用:
{l s="se stai inserendo un indirizzo per consegna all'interno dell'area [1]EXPO[/1]" tags=['<span class=orange>']}
您可以在文件classes/Translate.php
找到相關的代碼:
/**
* Perform operations on translations after everything is escaped and before displaying it
*/
public static function postProcessTranslation($string, $params)
{
// If tags were explicitely provided, we want to use them *after* the translation string is escaped.
if (!empty($params['tags'])) {
foreach ($params['tags'] as $index => $tag) {
// Make positions start at 1 so that it behaves similar to the %1$d etc. sprintf positional params
$position = $index + 1;
// extract tag name
$match = array();
if (preg_match('/^\s*<\s*(\w+)/', $tag, $match)) {
$opener = $tag;
$closer = '</'.$match[1].'>';
$string = str_replace('['.$position.']', $opener, $string);
$string = str_replace('[/'.$position.']', $closer, $string);
$string = str_replace('['.$position.'/]', $opener.$closer, $string);
}
}
}
return $string;
}
沒有在這種情況下,我不能。我的例子很清楚:我需要在翻譯中移動詞語(''EXPO'在''區域'詞語之前和之後),這就是爲什麼。 – Stratboy