hous
hous

Reputation: 2679

Translations doesn't work

I'm using Symfony2.6 and this is the catalogue of translation but it doesn't work

message.en.yml

#src/AppBundle/Resources/translations/message.en.yml
app:
    menu:
        home: Home

message.fr.yml

#src/AppBundle/Resources/translations/message.fr.yml
app:
    menu:
        home: Accueil

And this is the twig

{{ 'app.menu.home'|trans }}

this is the output

APP.MENU.HOME

Upvotes: 0

Views: 356

Answers (3)

M Gholami
M Gholami

Reputation: 971

Your translator file name might be messages.fr.yml you named it message.fr.yml the default translation domain is messges if you use any other translator file name , in your twig file you can translate in 2 way:

  1. {% trans_default_domain "translator-file-name"%} in first line of twig note : if your translator file name is like this : mytrans.fa.yml your domain must set in this way

{% trans_default_domain "mytrans"%}

  1. {{ "app.menu.home"|trans({},"mytrans")}}

Upvotes: 1

COil
COil

Reputation: 7586

Your translation namespace is not correct (the final s of message is missing), the files should be named:

#src/AppBundle/Resources/translations/messages.en.yml
#src/AppBundle/Resources/translations/messages.fr.yml

Or call the trans helper with the message namespace:

{{ 'app.menu.home'|trans({},'message') }

Upvotes: 2

Francesco Abeni
Francesco Abeni

Reputation: 4265

What you did seems correct so there's probably a typo somewhere. Check carefully the YML file syntax and spaces, it's easy to mess it up.

Upvotes: 0

Related Questions