2015-05-19 47 views
4

我找不到解決方案。我所要做的就是翻譯:如果我使用標籤,這樣如何在prestashop的smarty翻譯中使用html標籤?

If your delivery address is in the <span class=orange>EXPO</span> area 

{l s="se stai inserendo un indirizzo per consegna all'interno dell'area <span class=orange>EXPO</span>"} 

他們不會看到

se stai inserendo un indirizzo per consegna all'interno dell'area <span class=orange>EXPO</span> 

到這一點。所以呢?

回答

6

的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; 
} 
0

嘗試將HTML保留在翻譯字符串之外。你可以做,通過使兩個字符串:

{l s="se stai inserendo un indirizzo per consegna all'interno dell'area"} <span class="orange">{l s='EXPO'}</span> 
+1

沒有在這種情況下,我不能。我的例子很清楚:我需要在翻譯中移動詞語(''EXPO'在''區域'詞語之前和之後),這就是爲什麼。 – Stratboy

2

的翻譯功能將刪除所有HTML標記,所以你將不得不使用像這樣

{capture "string"} 
    {l s="se stai inserendo un indirizzo per consegna all'interno dell'area _h1_EXPO_h2_"} 
{/capture} 
{$smarty.capture.string|replace:'_h1_':'<span class="orange">'|replace:'_h2_':'</span>'} 

_h1__h2_另一種是在翻譯和他們分別被<span class="orange"></span>取代

聰明的capture函數用於獲取翻譯到變量string,而不是dispaying它

所以,你的英文翻譯是這樣的
If your delivery address is in the _h1_EXPO_h2_ area

+0

解決這個問題的一個不錯的核心解決方案。 – dlopezgonzalez

+0

我會進一步瞭解一下,我們甚至可以提出一個拉動請求,看看它是如何發展的(目標:PrestaShop 1.7) – UnLoCo