如何将目录应用到 FOSUserBundle 的重写布局?
正如 这里 所说,我已经覆盖了布局。 html.twig 模板 FOSUserBundle。
这是新模板:
//app/Resources/FOSUserBundle/views
{% extends 'AibFrontendBundle::layout.html.twig' %}
{% block content%}
<div>
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
{{ 'layout.logged_in_as'|trans({'%username%':
app.user.username}, 'FOSUserBundle') }} |
<a href="{{ path('fos_user_security_logout') }}">
{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
</a>
{% else %}
<a
href="{{ path('fos_user_security_login') }}">{{ 'layout.login'|
trans({}, 'FOSUserBundle') }}</a>
{% endif %}
</div>
{% for key, message in app.session.getFlashes() %}
<div class="{{ key }}">
{{ message|trans({}, 'messages') }}
</div>
{% endfor %}
<div>
{% block fos_user_content %}
{% endblock fos_user_content %}
</div>
{% endblock %}
如您所见,我的layout.html.twig几乎与原始模板相同 FOSUserBundle,但我将 i18n 目录称为“消息”。
我在 /Aib/FrontendBundle/Resources/ 中有 messages.it.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>Username o password invalidi</target>
</trans-unit>
</body>
</file>
</xliff>
问题:“错误凭据”的翻译不起作用..
我清除了缓存。
as here is said I've overrided the layout.html.twig template of
FOSUserBundle.
This is the new template:
//app/Resources/FOSUserBundle/views
{% extends 'AibFrontendBundle::layout.html.twig' %}
{% block content%}
<div>
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
{{ 'layout.logged_in_as'|trans({'%username%':
app.user.username}, 'FOSUserBundle') }} |
<a href="{{ path('fos_user_security_logout') }}">
{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
</a>
{% else %}
<a
href="{{ path('fos_user_security_login') }}">{{ 'layout.login'|
trans({}, 'FOSUserBundle') }}</a>
{% endif %}
</div>
{% for key, message in app.session.getFlashes() %}
<div class="{{ key }}">
{{ message|trans({}, 'messages') }}
</div>
{% endfor %}
<div>
{% block fos_user_content %}
{% endblock fos_user_content %}
</div>
{% endblock %}
As you can see my layout.html.twig is almost the same as the original
FOSUserBundle, but I'm calling the i18n catalog "messages".
I have messages.it.xliff inside /Aib/FrontendBundle/Resources/
translations. Here it is:
<?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>Username o password invalidi</target>
</trans-unit>
</body>
</file>
</xliff>
The problem: the translation of "Bad credentials" doesn't work..
I cleared the cache.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了你的答案的解决方案。
在这里创建一个 yml 文件对我来说很有效:
app/Resources/translations/FOSUserBundle.fr.yml
如果您不知道如何填充此文件,请在捆绑包中查找具有相似名称的文件。清除缓存很重要。
你没有回答我对这个问题(以及其他几个问题)的评论,真的让我很生气,但你的问题是一个好问题,其他一些人可能需要答案,他们没有理由不得到答案,所以在这里这是。祝你有美好的一天,当有人与你交谈时请回复。这是基本的礼貌。
I found the solution to your answer.
creating a yml file here did the trick for me:
app/Resources/translations/FOSUserBundle.fr.yml
If you don't know how to fill this file, look for the file with a similar name in the bundle. Clearing the cache is important.
You really pissed me off by not answering my comment on this question (and on several others), but your question is a good question and some other people may need the answer, and there is no reason for them not to get an answer so here it is. Have a good day, and please reply when someone talks to you. It is basic politeness.