No commit activity in last 3 years
No release in over 3 years
rack-i18n_routes is a Rack middleware component that internally re-routes URLS that have been translated into untranslated or canonical URL.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

>= 3.8.0
>= 2.0.1
>= 0.6.1

Runtime

>= 1.4.1
 Project Readme

rack-i8n_routes: route translated URLs to their canonical URLs

rack-i18n_routes is a Rack middleware component that internally re-routes URLS that have been translated into untranslated or canonical URL.

If you manage a site that has content many languages and also localized URLs, you will find rack-i18n_routes very useful, especially when used in conjunction with rack-i18n_best_langs.

Differently from other similar Rack middleware components, rack-i18n_routes focuses only on path translation/normalization and does not require Rails or the i18n gem.

Features

The main task of rack-i18n_routes is the normalization of request paths.

Path normalization rewrites the URI (actually the PATH_INFO) so that that the downstream applications will have to deal with the normalized path only, instead of a myriad of localized paths.

The original path is saved in the rack.i18n_routes_orig_PATH_INFO variable.

Examples

rack-i18n_routes works like any other Rack middleware component:

# in your server.ru rackup file
require 'rack/i18n_routes'

aliases = {
    'articles' => {
        'fra' => 'articles',
        'spa' => ['artículos', 'articulos'],

        :children => {
            'the-victory' => {
                'fra' => 'la-victoire',
                'spa' => 'la-victoria',
            },
            'the-block' => {
                'fra' => 'le-bloc',
                'spa' => 'el-bloque',
            },
        },
    },

    'paintings' => {
        'fra' => 'peintures',
        'spa' => 'pinturas',
    }
}

MAPPING_FN = Rack::I18nRoutes::AliasMapping.new(aliases)

use Rack::I18nRoutes, MAPPING_FN
run MyApp

Requests to /articulos/el-bloque, /articles/le-bloc and even /articulos/le-bloc will all be sent to /articles/the-block.

This component deals only with URL normalization. You can use rack-i18n_best_langs (documentation) to automatically associate the translated URLs to their languages.

Requirements

No requirements outside Ruby >= 1.8.7 and Rack.

Install

gem install rack-i18n_routes

Author

Development

Code : https://github.com/gioele/rack-i18n_routes

Report issues : https://github.com/gioele/rack-i18n_routes/issues

Documentation : http://rubydoc.info/gems/rack-i18n_routes

License

This is free software released into the public domain (CC0 license).

See the COPYING file or http://creativecommons.org/publicdomain/zero/1.0/ for more details.