Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
902c2c8c
Commit
902c2c8c
authored
Nov 01, 2013
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed translator locale management
parent
f4af8175
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
4 deletions
+51
-4
doc/changelog.rst
doc/changelog.rst
+1
-1
src/Silex/Provider/TranslationServiceProvider.php
src/Silex/Provider/TranslationServiceProvider.php
+2
-3
src/Silex/Translator.php
src/Silex/Translator.php
+37
-0
tests/Silex/Tests/Provider/TranslationServiceProviderTest.php
...s/Silex/Tests/Provider/TranslationServiceProviderTest.php
+11
-0
No files found.
doc/changelog.rst
View file @
902c2c8c
...
...
@@ -4,7 +4,7 @@ Changelog
1.1.3 (2013-XX-XX)
------------------
*
n/a
*
Fixed translator locale management
1.1.2 (2013-10-30)
------------------
...
...
src/Silex/Provider/TranslationServiceProvider.php
View file @
902c2c8c
...
...
@@ -13,8 +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
;
...
...
@@ -29,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'
]))
{
...
...
src/Silex/Translator.php
0 → 100644
View file @
902c2c8c
<?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'
];
}
}
tests/Silex/Tests/Provider/TranslationServiceProviderTest.php
View file @
902c2c8c
...
...
@@ -125,4 +125,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'
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment