Configure symfony for localization:
Add localization to the session(please note that the convention is /locale/action):
goodbye:
pattern: /{_locale}/goodbye
defaults: { _controller: AcmeBudgetTrackerBundle:Goodbye:goodbye, _locale: en }
requirements:
_locale: en|bg
Alternatively locale can be set manually:
$this->get('session')->set('_locale', 'en_US');
app/config/config.yml
framework:
translator: { fallback: en }
In your response:
use Symfony\Component\HttpFoundation\Response;
public function indexAction()
{
$translated = $this->get('translator')->trans('Symfony2 is great');
return new Response($translated);
}
Configure localization messages localized files:
messages.bg
<?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>Symfony2 е супер</target>
</trans-unit>
<trans-unit id="2">
<source>symfony2.great</source>
<target>Symfony2 е супер</target>
</trans-unit>
</body>
</file>
</xliff>
messages.fr
<?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>
<trans-unit id="2">
<source>symfony2.great</source>
<target>J'aime Symfony2</target>
</trans-unit>
</body>
</file>
</xliff>
More on the topic: Official symfony documentation