parent
b876412d3b
commit
6aee641a1e
@ -35,7 +35,6 @@
|
||||
<argument type="collection">
|
||||
<argument key="cache_dir">%kernel.cache_dir%/translations</argument>
|
||||
<argument key="debug">%kernel.debug%</argument>
|
||||
<argument key="charset">%kernel.charset%</argument>
|
||||
</argument>
|
||||
</service>
|
||||
|
||||
|
@ -49,7 +49,6 @@ class Translator extends BaseTranslator
|
||||
$this->options = array(
|
||||
'cache_dir' => null,
|
||||
'debug' => false,
|
||||
'charset' => null,
|
||||
);
|
||||
|
||||
// check option names
|
||||
@ -59,10 +58,7 @@ class Translator extends BaseTranslator
|
||||
|
||||
$this->options = array_merge($this->options, $options);
|
||||
|
||||
if ($this->options['charset'] === 'UTF-8') {
|
||||
$this->options['charset'] = null;
|
||||
}
|
||||
parent::__construct(null, $selector, $this->options['charset']);
|
||||
parent::__construct(null, $selector);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,18 +28,16 @@ class Translator implements TranslatorInterface
|
||||
private $loaders;
|
||||
private $resources;
|
||||
private $selector;
|
||||
private $charset;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $locale The locale
|
||||
* @param MessageSelector $selector The message selector for pluralization
|
||||
* @param string $charset Application charset
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($locale, MessageSelector $selector = null, $charset = null)
|
||||
public function __construct($locale, MessageSelector $selector = null)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
$this->selector = null === $selector ? new MessageSelector() : $selector;
|
||||
@ -47,7 +45,6 @@ class Translator implements TranslatorInterface
|
||||
$this->resources = array();
|
||||
$this->catalogues = array();
|
||||
$this->fallbackLocales = array();
|
||||
$this->charset = $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,18 +173,7 @@ class Translator implements TranslatorInterface
|
||||
if (!isset($this->loaders[$resource[0]])) {
|
||||
throw new \RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0]));
|
||||
}
|
||||
$catalogue = $this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]);
|
||||
if (null !== $this->charset && extension_loaded('mbstring')) {
|
||||
foreach ($catalogue->all() as $domain => $messages) {
|
||||
foreach ($messages as $key => $translation) {
|
||||
$srcCharset = mb_detect_encoding($translation);
|
||||
if ($srcCharset !== $this->charset) {
|
||||
$catalogue->set($key, mb_convert_encoding($translation, $this->charset, $srcCharset), $domain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->catalogues[$locale]->addCatalogue($catalogue);
|
||||
$this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,27 +132,6 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expected, $translator->trans($id, array(), '', 'fr'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadCatalogueTests
|
||||
*/
|
||||
public function testLoadCatalogueConvertsEncoding($translation, $charset)
|
||||
{
|
||||
if (!extension_loaded('mbstring')) {
|
||||
$this->markTestSkipped('This test relies on the mbstring extension');
|
||||
}
|
||||
$translator = new Translator('en', new MessageSelector(), $charset);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('id' => $translation), 'en', 'messages');
|
||||
|
||||
if (null !== $charset && mb_detect_encoding($translation) !== $charset) {
|
||||
$expected = mb_convert_encoding($translation, $charset, mb_detect_encoding($translation));
|
||||
} else {
|
||||
$expected = $translation;
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $translator->trans('id', array(), 'messages', 'en'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTransChoiceTests
|
||||
*/
|
||||
@ -220,21 +199,6 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function getLoadCatalogueTests()
|
||||
{
|
||||
return array(
|
||||
array('oia', null),
|
||||
array('oia', 'UTF-8'),
|
||||
array('öïä', 'UTF-8'),
|
||||
array('oia', 'ISO-8859-1'),
|
||||
array('öïä', 'ISO-8859-1'),
|
||||
array('цфЭ', 'UTF-8'),
|
||||
array('цфЭ', 'KOI8-R'),
|
||||
array('ヨラリ', 'UTF-8'),
|
||||
array('ヨラリ', 'SJIS'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testTransChoiceFallback()
|
||||
{
|
||||
$translator = new Translator('ru', new MessageSelector());
|
||||
|
Reference in New Issue
Block a user