Skip to content

Commit

Permalink
T7764 (#32)
Browse files Browse the repository at this point in the history
* T7764

* Update src/I18n/TranslationUpdater.php

Co-authored-by: Brooke Bryan <brooke@bajb.net>

* Update src/Context/Context.php

Co-authored-by: Brooke Bryan <brooke@bajb.net>

* Update src/Context/Context.php

Co-authored-by: Brooke Bryan <brooke@bajb.net>
  • Loading branch information
aktorou and bajb authored Feb 26, 2021
1 parent 730ac31 commit afa5f5a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function prepareTranslator($path = '/translations/', $withUpdater = false
if($withUpdater)
{
//Push all translations via a translation logger
$cubex->share(Translator::class, new TranslationLogger(new CatalogTranslator($catalog)));
$translationLogger = new TranslationLogger(new CatalogTranslator($catalog));
$cubex->share(Translator::class, $translationLogger);

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

//Setup the translation logger to listen @ shutdown
$cubex->retrieve(TranslationUpdater::class, [$this->getCubex(), $tplCatalog, $catFile, static::DEFAULT_LANGUAGE]);
$cubex->retrieve(TranslationUpdater::class, [$cubex, $tplCatalog, $catFile, static::DEFAULT_LANGUAGE, $translationLogger]);
}
else
{
Expand Down
18 changes: 13 additions & 5 deletions src/I18n/TranslationUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,28 @@ class TranslationUpdater implements CubexAware
protected $_file;
protected $_lang;

public function __construct(Cubex $cubex, MessageCatalog $catalog, $file, $lang)
public function __construct(Cubex $cubex, MessageCatalog $catalog, $file, $lang, TranslationLogger $translationLogger = null)
{
$this->_catalog = $catalog;
$this->_file = $file;
$this->_lang = $lang;
$this->setCubex($cubex);
$cubex->listen(
ShutdownEvent::class,
function () {
$translator = $this->getCubex()->retrieve(Translator::class);
if($translator instanceof TranslationLogger)
function () use ($translationLogger) {
if ($translationLogger !== null)
{
$this->storeTranslations($translator);
$this->storeTranslations($translationLogger);
}
else
{
$translator = $this->getCubex()->retrieve(Translator::class);
if($translator instanceof TranslationLogger)
{
$this->storeTranslations($translator);
}
}

}
);
}
Expand Down

0 comments on commit afa5f5a

Please sign in to comment.