2015-10-15 20:00:45 +08:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
|
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Flarum\Locale;
|
|
|
|
|
|
|
|
use Symfony\Component\Translation\MessageCatalogueInterface;
|
2015-10-24 10:46:26 +08:00
|
|
|
use Symfony\Component\Translation\Translator as BaseTranslator;
|
2015-10-15 20:00:45 +08:00
|
|
|
|
2015-10-24 10:46:26 +08:00
|
|
|
class Translator extends BaseTranslator
|
2015-10-15 20:00:45 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2015-10-24 10:46:26 +08:00
|
|
|
public function getCatalogue($locale = null)
|
2015-10-15 20:00:45 +08:00
|
|
|
{
|
2015-10-24 10:46:26 +08:00
|
|
|
$catalogue = parent::getCatalogue($locale);
|
2015-10-15 20:00:45 +08:00
|
|
|
|
2015-10-24 10:46:26 +08:00
|
|
|
foreach ($catalogue->all() as $domain => $messages) {
|
|
|
|
foreach ($messages as $id => $translation) {
|
|
|
|
$catalogue->set($id, $this->getTranslation($catalogue, $id, $domain), $domain);
|
|
|
|
}
|
2015-10-15 20:00:45 +08:00
|
|
|
}
|
|
|
|
|
2015-10-24 10:46:26 +08:00
|
|
|
return $catalogue;
|
2015-10-15 20:00:45 +08:00
|
|
|
}
|
|
|
|
|
2015-10-24 10:46:26 +08:00
|
|
|
/**
|
|
|
|
* @param MessageCatalogueInterface $messages
|
|
|
|
* @param string $id
|
|
|
|
* @param string $domain
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-10-15 20:00:45 +08:00
|
|
|
private function getTranslation(MessageCatalogueInterface $messages, $id, $domain)
|
|
|
|
{
|
|
|
|
$translation = $messages->get($id, $domain);
|
|
|
|
|
2015-10-22 14:31:21 +08:00
|
|
|
if (preg_match('/^=>\s*([a-z0-9_\-\.]+)$/i', $translation, $matches)) {
|
2015-10-15 20:00:45 +08:00
|
|
|
return $this->getTranslation($messages, $matches[1], $domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $translation;
|
|
|
|
}
|
2015-10-15 20:21:26 +08:00
|
|
|
}
|