的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