I use the Phalcon build in I18N functionality as shown in docu and now want to achieve this: In case a key is not already in csv or in case a requested translation is not there I want to trigger a certain action. Action could be just logging or adding the key to the csv or any kind of notification. Why? I have written a bigger project at the beginning only one language but already using always something like this in my templates:
<?= $t->_('Please complete your profile!'); ?>
In I18N controller
public function initialize()
{
$this->view->t = $this->getTranslation();
}
protected function getTranslation()
{
$messages = [];
$language = strtolower(substr($this->detectLanguage(), 0, 2));
$translationFile = $this->di->getConfig()->translation->messagesDir . $language . '.php';
if (!file_exists($translationFile)) { // Is there a translation file for that language
$language = 'en';
}
require $this->di->getConfig()->translation->messagesDir . $language . '.php';
setcookie('language', $language, time() + 15 * 86400, '/', "", false, false);
$this->view->selectedLang = $language;
return new NativeArray(
[
'content' => $messages,
]
);
}
How can i Hook something in here on failing translation?