Translate-plugin: get current or active language in component

Created on 30 Jun 2017  路  6Comments  路  Source: rainlab/translate-plugin

Hi i was able to find a way to get current local in partial, but failed to find any way to determine active local in one of my component. Is there any function which returns active language like {{activeLocale}} in components? Thank you for the attention.

Update:

Although for a fast work around, i solved using this way Session::get('rainlab.translate.locale')

Question

Most helpful comment

Best approach is probably:

App::getLocale()

how about you add in the documentation

If you need help creating a Pull Request, there is documentation for that.

All 6 comments

@yeomann Take a look how it's done in LocalePicker Component

So You can go something like:

use RainLab\Translate\Classes\Translator;

$translator = Translator::instance();
$activeLocale = $translator->getLocale();

I think it would be great to have a facade with this and maybe a few other convenience features.

@adsa95 there is:

\RainLab\Translate\Classes\Translator::instance()->getLocale();

馃槃

Hi thanks for providing facade, how about you add in the documentation 馃槃 Although at the time of asking that question, i solved that situation in 2 different ways, one with session and one with digging in your LocalePicker Component. My approach for one of partial was this

==
use RainLab\Translate\Classes\Translator;
protected $translator;

function onStart()
{
    $this->translator = Translator::instance();
    $this['SelectedLanguage'] = $this->activeLocale = $this->translator->getLocale();
}
==
{% set CurrentLanguage = SelectedLanguage %}

Best approach is probably:

App::getLocale()

how about you add in the documentation

If you need help creating a Pull Request, there is documentation for that.

@daftspunk thank you for mentioning the Best approach. I will give a try.
and i know about Pull request so i will do that as well perhaps.

Was this page helpful?
0 / 5 - 0 ratings