Reputation: 484
I am failing to setup translation for my Symfony 2 project. I have manually created a folder inside app\Resources\translations\message.en.yml
and it's content:
base:
title:
homePage: TeamERP IMS for BA
Then on the base twig template inside my bundle I am trying to call it:
<title>
{% block title %}
{{ base.title.homePage|trans }}
{% endblock %}
</title>
Then on the config.yml
I has the following:
framework:
translator: { fallbacks: en }
I am getting this error:
Variable "base" does not exist in TeamERPBaseBundle::base.html.twig at line 7
What am I doing wrong?
Edit: after fixing the problem here:
{{ 'base.title.homePage'|trans }}
I stopped getting the error, thanks for that. now the page is not giveng the error but not loading the page with the warning in the logs fine:
[2015-05-01 12:42:57] translation.WARNING: Translation not found. {"id":"base.title.homePage","domain":"messages","locale":"en"} []
[2015-05-01 12:42:57] translation.WARNING: Translation not found. {"id":"Home","domain":"messages","locale":"en"} []
Edit2: There was some kind of problem with my version of symfony 2.6. I just did a composer update
due to this, and it started working. normaly.
Upvotes: 1
Views: 2020
Reputation: 1697
The format of your yaml file is imho not correct and the translation in twig is wrong.
message.en.yml
base.title.homePage: TeamERP IMS for BA
your.twig.html
<title>
{% block title %}
{{ 'base.title.homePage' | trans }}
{% endblock %}
</title>
You can use the Translation component as you like, but better is to write down correct sentences in your main language (TeamERP IMS for BA) and translate them. Think of giving a translation file away to native speaker who should translate it:
message.de.yml
TeamERP IMS for BA: TeamERP IMS für BA
your.twig.html
<title>
{% block title %}
{% trans %}TeamERP IMS for BA{% endtrans %}
{% endblock %}
</title>
And of course check the domains {% trans_default_domain "message" %}
Upvotes: 0
Reputation: 83622
First of all it should be messages.en.yml
as indicated by @xurshid29, but most important it should be
<title>
{% block title %}
{{ 'base.title.homePage'|trans }}
{% endblock %}
</title>
inside the template. The value passed to the trans
filter must be a string but base.title.homePage|trans
would be expanded to something similar to $base->getTitle()->getHomepage()
because it's a Twig variable syntax. That's why you're getting the error message Variable "base" does not exist
.
Upvotes: 2