【问题标题】:Translation of "User account is disabled."“用户帐户被禁用”的翻译。
【发布时间】:2013-10-05 09:30:06
【问题描述】:

我需要翻译(并覆盖英语)“用户帐户已禁用”。当用户尝试使用禁用的用户帐户登录时显示的消息。

我在https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/User/UserChecker.php找到了这条消息

该消息似乎不是任何 xliff 或 yml 翻译文件的一部分。这是否意味着我们必须重写这个类来更改/翻译这条消息?

有没有更清洁的解决方案?

谢谢

【问题讨论】:

    标签: symfony


    【解决方案1】:

    未捕获的异常通常由 TwigBundle 中的 ExceptionController 呈现,然后根据请求使用 TwigBundle/Resources/Resources/views/Exception 中的模板之一呈现 - 很可能是 exception.html.twig

    在这种情况下,这些异常都扩展了AuthenticationException,因此在身份验证过程中被Symfony\Component\Security\Http\Firewall\ExceptionListener 捕获。

    该异常将触发 SecurityContext 包含一个身份验证错误,该错误将(在 FOSUserBundle 的示例中)作为a variable called error 传递到您的登录表单。然后这个变量将在the login template 中呈现(并使用 trans 过滤器进行翻译)。

    您可以在 app/Resources/translations 或 app/Resources/FOSUserBundle/translation 或 symfony (documentation) 正在搜索翻译的其他位置之一中为这些消息添加新翻译 - 确保您正在使用正确的 translation domain - 如果您使用的是捆绑包,则为 FOSUserBundle

    【讨论】:

      【解决方案2】:

      感谢@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>
      

      【讨论】:

        【解决方案3】:

        推杆

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

        进入 MyBundle/Resources/translations/security.fr.yml 为我工作。

        【讨论】:

          猜你喜欢
          • 2016-05-03
          • 2014-11-15
          • 1970-01-01
          • 2017-03-07
          • 2022-06-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-11-24
          相关资源
          最近更新 更多