3
votes

I am new to Symfony2. Trying to establish translation Service. I am following the steps given in the official documentation. But not successful.

Following are steps followed

  1. In 'symfony/app/config/config.yml' translation service by defining locale "#translator:{ fallback: %locale% }"

  2. In 'symfony/app/config/parameters.yml' defined locale parameter "locale:de"

  3. In 'src/MyBundle/translateBundle/Resources/translations/messages.de.xlf' is created

    <?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>Symfony2 is great</source>
                <target>J'aime Symfony2</target>
            </trans-unit>
        </body>
    </file>
    </xliff>    
    

Now I hope with this coding now I should get: 'J'aime Symfony2' on execution of following code.

<?php

namespace MyDays\translateBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller {
    public function indexAction() {
        $t = $this->get ( 'translator' )->trans ( 'Symfony2 is great' );        
        return new Response ( $t );
    }
}

But still getting original text as 'Symfony2 is great'! Is there anything I have to do apart from the steps given in documentation?

1

1 Answers

8
votes

Have you removed # before translator... in config.yml?

Also you need to clear the cache after adding a new translation file.