Skip to content

Commit

Permalink
Share message catalog (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb authored Feb 25, 2021
1 parent 082d473 commit 730ac31
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Packaged\Http\Response;
use Packaged\I18n\Catalog\ArrayCatalog;
use Packaged\I18n\Catalog\DynamicArrayCatalog;
use Packaged\I18n\Catalog\MessageCatalog;
use Packaged\I18n\Translators\CatalogTranslator;
use Packaged\I18n\Translators\TranslationLogger;
use Packaged\I18n\Translators\Translator;
Expand Down Expand Up @@ -85,6 +86,8 @@ public function prepareTranslator($path = '/translations/', $withUpdater = false
$transDir = $this->getProjectRoot() . $path;
$catalog = new ArrayCatalog([]);

$cubex = $this->getCubex();

foreach($this->_attemptLanguages() as $language)
{
$transFile = $transDir . $language . '.php';
Expand All @@ -96,10 +99,12 @@ public function prepareTranslator($path = '/translations/', $withUpdater = false
}
}

$cubex->share(MessageCatalog::class, $catalog);

if($withUpdater)
{
//Push all translations via a translation logger
$this->getCubex()->share(Translator::class, new TranslationLogger(new CatalogTranslator($catalog)));
$cubex->share(Translator::class, new TranslationLogger(new CatalogTranslator($catalog)));

//Keep track of all new translations within _tpl.php
$catFile = $transDir . '_tpl.php';
Expand All @@ -114,14 +119,11 @@ public function prepareTranslator($path = '/translations/', $withUpdater = false
}

//Setup the translation logger to listen @ shutdown
$this->getCubex()->retrieve(
TranslationUpdater::class,
[$this->getCubex(), $tplCatalog, $catFile, static::DEFAULT_LANGUAGE]
);
$cubex->retrieve(TranslationUpdater::class, [$this->getCubex(), $tplCatalog, $catFile, static::DEFAULT_LANGUAGE]);
}
else
{
$this->getCubex()->share(Translator::class, new CatalogTranslator($catalog));
$cubex->share(Translator::class, new CatalogTranslator($catalog));
}
}

Expand Down

0 comments on commit 730ac31

Please sign in to comment.