Hello,
Indeed, I already readed it. But something I think is not working properly. Docs mentions user's language will define which language will be served. I, as a logged member, always receive the default language even I specify 'it', 'de' or 'ru'.
I have no way to force processwire to show the current user language option, it always show the 'default' language.
I saw a lot of people looking how to prevent that, but I cannot find a working solution at the moment.
-----------------------------------------------------------------
Solved, I figure it out looking at different forum snippets. This is the code I'm using on a new module. It also adds the $user->savedLanguage variable to receive the language name user has set on profile. I hope you find it useful.
<?php
class LanguageDefault extends WireData implements Module {
/**
* getModuleInfo is a module required by all modules to tell ProcessWire about them
*
* @return array
*
*/
public static function getModuleInfo() {
return array(
'title' => 'LanguageDefault',
'version' => 0,
'summary' => 'A work around to changing the default language.',
'singular' => true,
'autoload' => true,
);
}
/**
* Initialize the module
*
* ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called
* when ProcessWire's API is ready. As a result, this is a good place to attach hooks.
*
*/
public function init() {
if ($this->wire("user")->language->name == "default") {
$this->wire("user")->savedLanguage = "en";
} else {
$this->wire("user")->savedLanguage = $this->wire("user")->language->name;
}
$this->session->addHookBefore('redirect', $this, 'setDefaultLanguage');
}
public function setDefaultLanguage($event) {
if ($this->page->id == 1 && $event->arguments(0) == $this->page->localUrl('default')) {
$event->arguments(0, $this->page->localUrl($this->wire("user")->savedLanguage));
}
}
}