Add Languages::getTranslation()

This commit is contained in:
Giuseppe Criscione 2020-12-18 14:48:38 +01:00
parent 37fe4d482f
commit 943c0bb1f2

View File

@ -3,6 +3,7 @@
namespace Formwork\Languages;
use Formwork\Core\Formwork;
use Formwork\Translations\Translation;
use Formwork\Utils\HTTPNegotiation;
class Languages
@ -99,6 +100,15 @@ class Languages
return $this->current === $this->default;
}
/**
* Get the translation for the current language or the fallback one
*/
public function getTranslation(): Translation
{
$fallback = Formwork::instance()->config()->get('translations.fallback');
return Formwork::instance()->translations()->get($this->current ?? $fallback, true);
}
/**
* Create a Languages instance from a given request
*/