Coder Social home page Coder Social logo

Comments (1)

zackxu1 avatar zackxu1 commented on July 18, 2024

After reading the source-code, I see what this gem is doing:

The Locale filter extracts segments matching /:locale from the beginning of
the recognized path and exposes the page parameter as params[:locale]. When a
path is generated the filter adds the segments to the path accordingly if
the page parameter is passed to the url helper.

incoming url: /de/products
filtered url: /products
params: params[:locale] = 'de'

You can install the filter like this:

in config/routes.rb

Rails.application.routes.draw do
filter :locale
end

To make your named_route helpers or url_for add the locale segments you
can use:

products_path(:locale => 'de')
url_for(:products, :locale => 'de'))

I added the needed logic to application_controller.rb so it's all working.

As a suggestion, maybe you want to add the above to the gem documentation so it's more clear what this gem is doing for persisting locale.
Thanks, this is a great gem!
Zack

from routing-filter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.