If i set the locale of my website from swedish to english, it works allright except for the loginform.
It somehow forces the locale to go back to it's default setting (wich is swedish). How can i fix this?
I'm not using any custom login form or something, just the form supplied by sapphire.
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
The problem is that if you're setting the locale of the site in the init method of your Page_Controller as you usually do when you have a multilingual site then it doesn't affect Security since Security extends Controller, not Page_Controller. There's extension points in Controller, one called onBeforeInit and one called onAfterInit.
I think you can hook into onBeforeInit and set the site locale then and it will affect the login form as well. If onBeforeInit proves to be too early then try onAfterInit, I know one of them works.
I kinda got what you mean. But can you show me an example, i'm new to Silverstripe :P
So I'm kind of assuming that you have something like this in your Page_Controller:
public function init() {
i18n::set_locale(Translatable::get_current_locale());
parent::init();
}
And this generally works since the rest of your page classes extends the Page/Page_Controller classes.
However like I said, Security doesn't extend Page_Controller, it extends Controller.
In order to affect it we need to hook into Controller.
First we make a new class that's going to hook into Controller like this for example:
class LoginFormLanguageSetter extends Extension {
function onBeforeInit() {
i18n:: set_locale(Translatable::get_current_locale());
}
}
Now in order to make this run you need to put the following in your _config.php:
Object::add_extension('Controller', 'LoginFormLanguageSetter');
The function name in LoginLanguageSetter matches the name of the function in the $this->extend() call in Controller on line 132.
Thanks Smurkas that helped a lot...