How would you setup Alchemy with multi locales on a single domain?

49 views
Skip to first unread message

Deniz Okcu

unread,
Jan 16, 2017, 12:24:39 PM1/16/17
to Alchemy CMS
Hello!

I am trying to switch from a multi TLD setup (.de/.fr/co.uk...) to a single domain setup (.com/de/, etc).
I would like to keep one site (page tree) per language in Alchemy.

It looks like Alchemy is capable of supporting this out of the box.

/components/alchemy_cms/config/routes.rb:166
get '(/:locale)/*urlname(.:format)' => 'pages#show'

Right now I am struggling getting it to work because the default scope of the Language model prevents the load_alchemy_language_from_params method to find the language from another Site:

/components/alchemy_cms/app/models/alchemy/language.rb:51
default_scope { on_site(Site.current) }

/components/alchemy_cms/lib/alchemy/controller_actions.rb:106
def load_alchemy_language_from_params
  if params[:locale].present?
    Language.find_by_code(params[:locale])
  end
end

What would be a best practice to setup Alchemy with multi site/language support behind one domain?

Thanks for your help!
Deniz

Robin Böning

unread,
Jan 16, 2017, 1:23:55 PM1/16/17
to Alchemy CMS
Hi Deniz,

Why do you want to keep one site per page tree? You might have a good reason for it but consider that Alchemy is initially built to handle multiple locales right out of the box without changing any code. Actually, you don't need to do anything else than creating multiple languages in the admin frontend and set your locales as you wish.

Then, to switch the language in the frontend you can simply call a helper method `language_links` in your view. (http://www.rubydoc.info/github/magiclabs/alchemy_cms/Alchemy/PagesHelper#language_links-instance_method)

Having one site per page tree doesn't feel right. A page tree is still the same website, while a Site is conected to a different Domain. So, using Sites would be like still maintaining your multi TLD setup. I suggest to change/migrate it so you only have one Site. You might be able to delete code! :)

Deniz Okcu

unread,
Jan 18, 2017, 4:55:02 AM1/18/17
to Alchemy CMS
Hi Robin,

thank you for your quick response!
Using multiple languages per site works perfectly.
Looks like we can simplify our setup.
Reply all
Reply to author
Forward
0 new messages