Logging undefined translation

This commit is contained in:
Dennis Eichhorn 2016-07-02 14:36:04 +02:00
parent dcf1abe3fe
commit 8550bbda59

View File

@ -15,6 +15,9 @@
*/ */
namespace phpOMS\Localization; namespace phpOMS\Localization;
use phpOMS\Log\FileLogger;
use phpOMS\Log\LoggerInterface;
/** /**
* Localization class. * Localization class.
* *
@ -37,6 +40,27 @@ class L11nManager
*/ */
private $language = []; private $language = [];
/**
* Logger.
*
* @var LoggerInterface
* @since 1.0.0
*/
private $logger = null;
/**
* Construct.
*
* @param LoggerInterface $logger Logger
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/** /**
* Verify if language is loaded. * Verify if language is loaded.
* *
@ -119,6 +143,14 @@ class L11nManager
*/ */
public function getText(string $code, string $module, string $translation) public function getText(string $code, string $module, string $translation)
{ {
return $this->language[$code][$module][$translation] ?? 'ERROR'; if (!isset($this->language[$code][$module][$translation])) {
$this->logger->warning(FileLogger::MSG_FULL, [
'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.'
]);
return 'ERROR';
}
return $this->language[$code][$module][$translation];
} }
} }