Setting locale in front-end and backend

309 views
Skip to first unread message

Slava Ptsarev

unread,
Oct 25, 2013, 12:59:09 PM10/25/13
to spree...@googlegroups.com
How can I set different locales for back-end and front-end of a Spree app?

Washington Luiz

unread,
Oct 25, 2013, 3:12:38 PM10/25/13
to spree...@googlegroups.com
I'm afraid you can't do that out of the box. Spree has only one session[:locale], that is used in both frontend and backend, see Spree::Core::ControllerHelpers::Common.

I think you could however skip the before_filter that set that locale in backend and create a new session key to keep the backend locale. That's how I'd start trying it out. 


On Fri, Oct 25, 2013 at 1:59 PM, Slava Ptsarev <lee...@gmail.com> wrote:
How can I set different locales for back-end and front-end of a Spree app?



--
Washington L Braga Jr

Developer
Spree Commerce, Inc.

Slava Ptsarev

unread,
Oct 26, 2013, 4:48:28 AM10/26/13
to spree...@googlegroups.com
Thanks for the tip and I'm sorry I should have been more specific. I just need to set 2 separate static locales like this:

Spree::Frontend::Config.locale = :en
Spree::Backend::Config.locale = :ru

So front-end is always in English and back-end in Russian.

There was an issue already on this and looks like Ryan Biggs addressed it when splitting core in front-end and back-end https://github.com/spree/spree/issues/1946

I just couldn't find where to put the code and what code should be like.

пятница, 25 октября 2013 г., 23:12:38 UTC+4 пользователь Washington Luiz написал:

Ryan Bigg

unread,
Oct 26, 2013, 3:51:38 PM10/26/13
to spree...@googlegroups.com
I think you can do that with this method:

Spree::Backend::Config[:locale] = :es
Spree::Frontend::Config[:locale] = :es

Slava Ptsarev

unread,
Oct 27, 2013, 2:10:37 AM10/27/13
to spree...@googlegroups.com
Thanks, Ryan, I already figured I should use [:locale] instead of .locale from your commits. But where do I put the code? I tried /config/initializers/spree.rb
and /app/controllers/application_controller.rb but no effect.

суббота, 26 октября 2013 г., 23:51:38 UTC+4 пользователь Ryan Bigg написал:

Washington Luiz

unread,
Oct 27, 2013, 10:10:03 AM10/27/13
to spree...@googlegroups.com
Nice I didnt know about that frontend backend config. Slava I think this might not work if you have set a session[:locale] already. Once you do that Spree controllers will ignore the specific locales for each component which would be a bug. Could you file an issue for that please (in case you confirm it's not working)?

Nate Lowrie

unread,
Oct 28, 2013, 9:54:41 AM10/28/13
to spree...@googlegroups.com
The other option is to split the backend out into a different site on a subdomain like admin.yourdomain.com.

Regards,

Nate

Ryan Bigg

unread,
Oct 28, 2013, 11:56:56 AM10/28/13
to spree...@googlegroups.com
This was actually a bug within spree_i18n and I have fixed it with the patch linked in https://github.com/spree/spree/issues/3915.
--

Ryan Bigg
Community Manager
Spree Commerce, Inc.
Reply all
Reply to author
Forward
0 new messages