Zeka Posted April 6, 2018 Share Posted April 6, 2018 Hi! Just curious is it possible to get current language in init.php or init method of modules? Link to comment Share on other sites More sharing options...
Sergio Posted April 6, 2018 Share Posted April 6, 2018 It is. // _init.php $lang = $user->language; //_main.php <?= $lang->title ?> //English or German etc. Link to comment Share on other sites More sharing options...
Zeka Posted April 6, 2018 Author Share Posted April 6, 2018 @Sergio Thanks, but not in templates/_init.php, but site/init.php Link to comment Share on other sites More sharing options...
tpr Posted April 6, 2018 Share Posted April 6, 2018 If nothing else helps you can get it from the first url segment I guess. Link to comment Share on other sites More sharing options...
Sergio Posted April 6, 2018 Share Posted April 6, 2018 1 hour ago, Zeka said: @Sergio Thanks, but not in templates/_init.php, but site/init.php Ops! Sorry! Soma showed a way to get in on a module init method: Link to comment Share on other sites More sharing options...
Zeka Posted April 6, 2018 Author Share Posted April 6, 2018 @Sergio Thanks, I have tried all from that thread, but it also doesn't work. $this->wire("user")->language->name always returns 'default', but in ready.php or ready modules method it works as expected, so it seems that user language is determined and set on ready stage here. The issue that I'm trying to solve: I'm using Padloper and by accessing 'padloper/ajaxViewCart/' I can get the view of the cart for ajax requests. It works as expected for default language, but not for non-default languages. So, I was trying to find a way how to get current language, but now I assume that it's not going to help as on init stage there is no page object and I actually can't get non-default lang values of fields. Here the code which responsible for that. public function init() { ..... $this->addHookBefore('ProcessPageView::execute', $this, 'runPadloper'); .... } public function runPadloper($event) { $it = isset($_GET['it']) ? $_GET['it'] : ""; if (substr($it, 0, 1) === '/') $it = ltrim($it, "/"); // We only allow urls like /padloper/ and /d/ here if(strpos($it, "padloper/") !== false || strpos($it, "d/") !== false) { // Do nothing } else { return; } switch ($it) { ..... case 'padloper/ajaxViewCart/': echo $this->modules->get("PadRender")->viewCart(); exit(); break; Link to comment Share on other sites More sharing options...
horst Posted April 7, 2018 Share Posted April 7, 2018 whats about detecting it and set it to a session var in site/finished.php and afterwards looking for it in site/init.php? PS: it would need extra attention if a language change url was currently clicked. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now