2013-10-05 86 views
2

我需要翻譯(並覆蓋英文)「用戶帳戶已禁用」。當用戶嘗試使用禁用的用戶帳戶登錄時顯示的消息。「用戶帳戶被禁用」的翻譯。

我在https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/User/UserChecker.php

發現這個消息似乎這消息不是任何XLIFF或YML翻譯文件的一部分。這是否意味着我們必須重寫此類來更改/翻譯此消息?

有沒有更清潔的解決方案?

感謝

回答

4

捕獲的異常通常由ExceptionController在TwigBundle呈現和使用的模板之一取決於請求,則呈現在TwigBundle/Resources/Resources/views/Exception - 最有可能exception.html.twig

在這種情況下的那些異常的所有延伸AuthenticationException和由Symfony\Component\Security\Http\Firewall\ExceptionListener在認證過程期間因此被捕獲。

該異常將觸發SecurityContext包含驗證錯誤,該錯誤將(以FOSUserBundle爲例)作爲a variable called error傳遞給您的登錄表單。然後該變量將在the login template中呈現(並使用反式過濾器進行翻譯)。

您可以在app/Resources/translations或app/Resources/FOSUserBundle /翻譯中添加這些消息的新翻譯,或者通過symfony搜索其他位置的翻譯(documentation) - 確保您使用的是right translation domain - 這是FOSUserBundle以防您正在使用該軟件包。

1

感謝@nifr爲您的答案。除了我沒有考慮到翻譯領域,我幾乎在那裏。它現在是我的翻譯文件已經從security.en.xlf更名爲FOSUserBundle.en.xlf幷包含以下內容:

<?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>User account is disabled.</source> 
       <target>The actual error label I wanted...</target> 
      </trans-unit> 
     </body> 
    </file> 
</xliff> 
0

'User account is disabled.': Ce compte n'est pas activé. 

到MyBundle /資源/翻譯/安全.fr.yml爲我工作。