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.

Template Questions /

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

How can I set locale for a custom controller / route


Go to End


2 Posts   1691 Views

Avatar
mp165

Community Member, 1 Post

16 October 2015 at 5:30am

Hi,

I have a custom route on a localized site (en & fr), but I'm relatively new to SS and haven't figured out how to provide a French version of the same route. I hard coded a second route with "fr/" (using the same action), but I still need to pass the locale to the templates. I was trying to do something in the controller init function along the lines of :

i18n->set_locale('fr_FR');

here are the routes:

Director:
rules:
'collection-rules//$Action/$ID/$OtherID': 'CollectionRulePageController'
'fr/collection-rules//$Action/$ID/$OtherID': 'CollectionRulePageController'

any advise would be greatly appreciated...

Mike

Avatar
martimiz

Forum Moderator, 1391 Posts

24 October 2015 at 10:12am

Edited: 24/10/2015 10:13am

First of all I think it should be:

i18n::set_locale('fr_FR'):

Next: why not use a second controller for the french route, something like:

FrCollectionRulePageController extends CollectionRulePageController

And then have each provide its own locale?

Another way would be to check the url from within the controller