Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

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.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Custom login & translatable


Go to End


1240 Views

Avatar
micschk

Community Member, 22 Posts

28 April 2011 at 4:12am

I've build a multilanguage-site (NL & FR, using translatable) and I created a custom login form

class CustomLoginForm extends MemberLoginForm 

Everything works fine, but when a visitor selects the French locale, the login-form part is always displayed in Dutch (NL). The header & footer are all in french, and even $Locale outputs 'fr_FR'

In page.php Page_Controller::init():

if($this->dataRecord->hasExtension('Translatable')) {
    i18n::set_locale($this->dataRecord->Locale);
} 
// Set locale for PHP, dates etc;
setlocale(LC_TIME, Translatable::get_current_locale() . ".UTF8");

Even when I set the locale to French in _config.php, the form is still shown in Dutch;

i18n::set_locale('fr_FR');

I ended up setting the locale again within the custom loginform file, which works (at least a preliminary fix);

<?php 

// Set locale again, for some reason the locale from page_controller isn't adhered to...
i18n::set_locale(Translatable::get_current_locale());

class CustomLoginForm extends MemberLoginForm { ...

Is this the way translations are supposed to work? Or have I done something wrong?