Hanami is great for static sites using the Parklife gem to build the static version. However, things get a little trickier when a site has to be translated.
Localizing the routes is the easy part:
module MySite
class Routes < Hanami::Routes
root to: "home.show" # browser language redirect by JS
Hanami.app.settings.available_locales.each do |locale|
scope locale do
get "about", to: "about.show", as: :about
get "contact", to: "contact.show", as: :contact
end
end
end
end
To get say the french URL of the about page, the route’s name is :fr_about
and the following works fine e.g. in templates:
routes.path(:fr_about)
Doesn’t look so nice if the locale prefix is added according to the current locale:
routes.path([I18n.locale, :about].join("_"))
It would be nice to have localized counterparts like lpath
(localized path
) and lurl
(localized url
). Monkey patching Hanami::Slice::RoutesHelper
would do the trick, but I guess, there is a better way?