2013-06-22 228 views
2

在我問這個問題之前,我已經仔細檢查了很多類似於stackoverflow的問題,但還沒有解決它。Symfony 2消息翻譯

該任務是使用俄語信息,而不是英語。讓我們假設它是衆所周知的身份驗證失敗消息「Bad credentials」。所以這就是我所做的。

在我的配置:

translator:  { fallback: en } 
default_locale: ru 

創建messages.ru.xliff

<?xml version="1.0"?> 
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> 
    <file source-language="en" datatype="plaintext" original="file.ext"> 
     <body> 
      <trans-unit id="1"> 
       <source>Bad credentials</source> 
       <target>My russian variant here</target> 
      </trans-unit> 
     </body> 
    </file> 
</xliff> 

最後,在我的login.html.twig:

{% if error %} 
<div class="error">{{ error.message | trans }}</div> 
{% endif %} 

如果驗證失敗,我仍然繼續收到「Bad credentials」消息。我試圖清除緩存,但它沒有幫助。

也許我錯過了什麼。任何幫助讚賞。謝謝。

+0

你確定你把messages.ru.xliff在正確的地方? – Hast

回答

1

我想問題是因爲你指定源翻譯爲「Bad credentials」,但你使用「error.message」作爲翻譯器的輸入。所以,你應該messages.ru.xliff看起來更像:

<?xml version="1.0"?> 
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> 
    <file source-language="en" datatype="plaintext" original="file.ext"> 
     <body> 
      <trans-unit id="1"> 
       <source>error.message</source> 
       <target>My russian variant here</target> 
      </trans-unit> 
     </body> 
    </file> 
</xliff> 

或更改消息標籤在你的模板:

{% if error %} 
<div class="error">{{ "Bad credentials" | trans }}</div> 
{% endif %} 
+0

其實error.message確實會返回錯誤的憑據。所以看起來他一切正常。 – Hast

+0

哦,你是對的,我錯過了那個error.message是一個變量而不是文字 – Cyprian

+0

是的,現在我不知道什麼是錯的:) – Hast