Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 translation sonata admin bunle

I tried to translate Sonata Admin Bundle Breadcrumbs and Tablename List headline. So far nothing worked :-(

I put my own translation files in /app/Resources/translations and in the translations folder of my own bundle. I tried to put them in SonataAdminBundle.de.yml and messages.de.yml. I also set a translation domain in my Admin class. But still I cannot see my own translation. The only translation file that is used is the one from the SonataAdminBundle.

Can anyone show me how to handle the translation for SonataAdminBundle correctly? What files have to be placed where and what has to be the content of these files?

Thanks in advance.

Lisa

like image 602
Lisa Riemann Avatar asked Nov 10 '12 10:11

Lisa Riemann


2 Answers

Well, this is how i do it:

In my XYBundle, i create a XYBundle.fr.xliff file in XYBundle/Ressources/translations ( make sure it's translation and not Translation. Nothing worked for me with a T ) With at least one translation :

<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext" original="" >
        <body>
            <trans-unit id="breadcrumb.link_article_list">
                <source>breadcrumb.link_article_list</source>
                <target>Liste des articles</target>
            </trans-unit>  
        </body>
    </file>
</xliff>

In your service declaration:

 <call method="setTranslationDomain">
            <argument>"XYBundle"</argument>
        </call>

And don't forget clearing your cache php app/console cache:clear

like image 179
Skizomik Avatar answered Oct 24 '22 18:10

Skizomik


Make sure you have cleared the cache. Otherwise new translation will be ignored.

In my case it still works with yaml and xml files together. But make sure the $translationDomain is set. Otherwise only the default SonataAdmin translation file will be loaded.

You can set the property manually in all sonata admin classes:

protected $translationDomain = 'messages';

or in the service declartion as shown above...

like image 42
sensi Avatar answered Oct 24 '22 17:10

sensi