mirror of
https://github.com/flarum/framework.git
synced 2025-01-21 12:24:15 +08:00
i18n: Make cross-file translation references work
This commit is contained in:
parent
d6691e6299
commit
aeeb16cb86
|
@ -13,8 +13,8 @@ namespace Flarum\Locale;
|
||||||
use Flarum\Event\ConfigureLocales;
|
use Flarum\Event\ConfigureLocales;
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
use Symfony\Component\Translation\Loader\YamlFileLoader;
|
||||||
use Symfony\Component\Translation\MessageSelector;
|
use Symfony\Component\Translation\MessageSelector;
|
||||||
use Symfony\Component\Translation\Translator;
|
|
||||||
|
|
||||||
class LocaleServiceProvider extends AbstractServiceProvider
|
class LocaleServiceProvider extends AbstractServiceProvider
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,25 +10,33 @@
|
||||||
|
|
||||||
namespace Flarum\Locale;
|
namespace Flarum\Locale;
|
||||||
|
|
||||||
use Symfony\Component\Translation\Loader\YamlFileLoader as BaseYamlFileLoader;
|
|
||||||
use Symfony\Component\Translation\MessageCatalogueInterface;
|
use Symfony\Component\Translation\MessageCatalogueInterface;
|
||||||
|
use Symfony\Component\Translation\Translator as BaseTranslator;
|
||||||
|
|
||||||
class YamlFileLoader extends BaseYamlFileLoader
|
class Translator extends BaseTranslator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function load($resource, $locale, $domain = 'messages')
|
public function getCatalogue($locale = null)
|
||||||
{
|
{
|
||||||
$messages = parent::load($resource, $locale, $domain);
|
$catalogue = parent::getCatalogue($locale);
|
||||||
|
|
||||||
foreach ($messages->all($domain) as $id => $translation) {
|
foreach ($catalogue->all() as $domain => $messages) {
|
||||||
$messages->set($id, $this->getTranslation($messages, $id, $domain));
|
foreach ($messages as $id => $translation) {
|
||||||
|
$catalogue->set($id, $this->getTranslation($catalogue, $id, $domain), $domain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $messages;
|
return $catalogue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param MessageCatalogueInterface $messages
|
||||||
|
* @param string $id
|
||||||
|
* @param string $domain
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
private function getTranslation(MessageCatalogueInterface $messages, $id, $domain)
|
private function getTranslation(MessageCatalogueInterface $messages, $id, $domain)
|
||||||
{
|
{
|
||||||
$translation = $messages->get($id, $domain);
|
$translation = $messages->get($id, $domain);
|
Loading…
Reference in New Issue
Block a user