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\Loader\YamlFileLoader as BaseYamlFileLoader;
|
|
|
|
use Symfony\Component\Translation\MessageCatalogueInterface;
|
|
|
|
|
|
|
|
class YamlFileLoader extends BaseYamlFileLoader
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function load($resource, $locale, $domain = 'messages')
|
|
|
|
{
|
|
|
|
$messages = parent::load($resource, $locale, $domain);
|
|
|
|
|
|
|
|
foreach ($messages->all($domain) as $id => $translation) {
|
|
|
|
$messages->set($id, $this->getTranslation($messages, $id, $domain));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|