No commit activity in last 3 years
No release in over 3 years
Flexible toolkit to localize routes in rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 0.21

Runtime

~> 5.1
 Project Readme

Gem Version Code Climate Build Status Dependency Status

Localizable Routes

Minimalistic toolkit to localize routes in rails.

Why

I did this gem to:

  • Being able to use different configurations on each set of routes.
  • Having most common strategies available out of the box.
  • Prevent bugs using not invasive code.

Install

Put this line in your Gemfile:

gem 'localizable_routes'

Then bundle:

$ bundle

Usage

Definitions

In your config/routes.rb use the localized method to decide wich routes will be localized:

localized strategy: :param, locales: %i(es en) do
  get 'page' => 'pages#show', as: :param
end

localized strategy: :subdomain, locales: { 'es' => :es, 'www' => :en } do
  get 'page' => 'pages#show', as: :subdomain
end

localized strategy: :domain, locales: { 'domain.es' => :es, 'domain.com' => :en } do
  get 'page' => 'pages#show', as: :domain
end

Localization

Put your localizations inside the routes key in your locales yamls:

es:
  routes:
    page: "pagina"

NOTE: There is no need to put the full path, just localize each part individually.

Urls

Url helpers will continue working the same:

param_path
# => /en/pagina if I18n.locale is :es

subdomain_url
# => http://es.domain.com/pagina if current subdomain is es

domain_url
# => http://domain.es/pagina if current domain is domain.es

And you can change the locale by passing the corresponding parameter:

param_path locale: :en
# => /en/page

subdomain_url sudomain: 'es'
# => http://es.domain.com/pagina

domain_url domain: 'domain.com'
# => http://domain.com/page

Contributing

Any issue, pull request, comment of any kind is more than welcome!

I will mainly ensure compatibility to Rails, AWS, PostgreSQL, Redis, Elasticsearch and FreeBSD. 

Credits

This gem is maintained and funded by museways.

License

It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.