From aeeb16cb8687f0e94d48ea50c7b6a5aa14d55c6c Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 24 Oct 2015 13:16:26 +1030 Subject: [PATCH] i18n: Make cross-file translation references work --- .../core/src/Locale/LocaleServiceProvider.php | 2 +- .../{YamlFileLoader.php => Translator.php} | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) rename framework/core/src/Locale/{YamlFileLoader.php => Translator.php} (54%) diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index ed5b30d87..71bbda9e2 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -13,8 +13,8 @@ namespace Flarum\Locale; use Flarum\Event\ConfigureLocales; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Events\Dispatcher; +use Symfony\Component\Translation\Loader\YamlFileLoader; use Symfony\Component\Translation\MessageSelector; -use Symfony\Component\Translation\Translator; class LocaleServiceProvider extends AbstractServiceProvider { diff --git a/framework/core/src/Locale/YamlFileLoader.php b/framework/core/src/Locale/Translator.php similarity index 54% rename from framework/core/src/Locale/YamlFileLoader.php rename to framework/core/src/Locale/Translator.php index 9bd1660c4..a6b936b91 100644 --- a/framework/core/src/Locale/YamlFileLoader.php +++ b/framework/core/src/Locale/Translator.php @@ -10,25 +10,33 @@ namespace Flarum\Locale; -use Symfony\Component\Translation\Loader\YamlFileLoader as BaseYamlFileLoader; use Symfony\Component\Translation\MessageCatalogueInterface; +use Symfony\Component\Translation\Translator as BaseTranslator; -class YamlFileLoader extends BaseYamlFileLoader +class Translator extends BaseTranslator { /** * {@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) { - $messages->set($id, $this->getTranslation($messages, $id, $domain)); + foreach ($catalogue->all() as $domain => $messages) { + 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) { $translation = $messages->get($id, $domain);