How would I get the current language?

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:

{{ language_codes.getName('pt') }}

FYI i’ve added this to base set of Twig variables so it will be available without any extra custom work for Grav 1.2.0 release : https://github.com/getgrav/grav/commit/330a90b0ab810f1ed3ca4f89f2e13cd4bc5b8087

@rhukster, thats handy to know, thanks very much :smiley: i will take a look at the exisiting solution. How long until Grav 1.2 is released roughly?

@rhukster and how would i get the natvie name?

Its ok i worked it out :smiley: - {{ language_codes.getnativeName(grav.language.getActive) }}

Yup, and Grav 1.2.0 should be release this week.