Hi,
How do I go about getting the current language? No just the country code ‘en’, ‘de’ but the actual name for example ‘English’ or ‘Deutsch’.
I am using langswitcher, but can seem to find anything that can help. I have tried to use
’{{ grav.language.getLanguage }}’ but this only shows the country code
Currently that is not available in Twig directly. That lookup is in the class LanguageCodes.php, but it currently can only be used by PHP, ie in a plugin or something. You could do this easily enough in your theme or plugin class:
I’m using Antimatter theme here for example:
<?php
namespace Grav\Theme;
use Grav\Common\Language\LanguageCodes;
use Grav\Common\Theme;
class Antimatter extends Theme
{
public static function getSubscribedEvents()
{
return [
'onTwigPageVariables' => ['onTwigVariables', 0],
'onTwigSiteVariables' => ['onTwigVariables', 0]
];
}
public function onTwigVariables()
{
$this->grav['twig']->twig_vars['language_codes'] = new LanguageCodes;
}
}
Then in your page content (with Twig processing enabled) or Twig template you can use it like this: