Commit 44883022 authored by Fabien Potencier's avatar Fabien Potencier

Merge branch '1.1'

* 1.1:
  fixed translator locale management
  bumped version to 1.1.3-DEV
  prepared the 1.1.2 release
  updated CHANGELOG
  prepared the 1.0.2 release
  updated CHANGELOG

Conflicts:
	doc/changelog.rst
	src/Silex/Application.php
	src/Silex/Provider/TranslationServiceProvider.php
parents bcb07f44 d12b4177
......@@ -11,6 +11,22 @@ Changelog
* Added HttpFragmentServiceProvider
* Add support for using a service method as a converter.
1.1.3 (2013-XX-XX)
------------------
* Fixed translator locale management
1.1.2 (2013-10-30)
------------------
* Added missing "security.hide_user_not_found" support in SecurityServiceProvider
* Fixed event listeners that are registered after the boot via the on() method
1.0.2 (2013-10-30)
------------------
* Fixed SecurityServiceProvider to use null as a fake controller so that routes can be dumped
1.1.1 (2013-10-11)
------------------
......
......@@ -13,7 +13,7 @@ namespace Silex\Provider;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\Translation\Translator;
use Silex\Translator;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Loader\XliffFileLoader;
......@@ -28,7 +28,7 @@ class TranslationServiceProvider implements ServiceProviderInterface
public function register(Application $app)
{
$app['translator'] = $app->share(function ($app) {
$translator = new Translator($app['locale'], $app['translator.message_selector']);
$translator = new Translator($app, $app['translator.message_selector']);
// Handle deprecated 'locale_fallback'
if (isset($app['locale_fallback'])) {
......
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\Translation\Translator as BaseTranslator;
use Symfony\Component\Translation\MessageSelector;
/**
* Translator that gets the current locale from the Silex application.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Translator extends BaseTranslator
{
protected $app;
public function __construct(Application $app, MessageSelector $selector)
{
$this->app = $app;
parent::__construct(null, $selector);
}
public function getLocale()
{
return $this->app['locale'];
}
}
......@@ -123,4 +123,15 @@ class TranslationServiceProviderTest extends \PHPUnit_Framework_TestCase
$result = $app['translator']->trans('key1', array(), null, 'ru');
$this->assertEquals('The german translation', $result);
}
public function testChangingLocale()
{
$app = $this->getPreparedApp();
$this->assertEquals('The translation', $app['translator']->trans('key1'));
$app['locale'] = 'de';
$this->assertEquals('The german translation', $app['translator']->trans('key1'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment