Skip to content

Localized routes #35

Answered by janko
renchap asked this question in Q&A
Apr 12, 2021 · 2 comments · 5 replies
Discussion options

You must be logged in to vote

Hi Renault, nice to see you again 👋🏻

I believe you should be able set up locale path prefixes as follows:

class RodauthApp < Rodauth::Rails::App
  configure do
    # ...
    prefix { "/#{I18n.locale}/users" }
    # ...
  end

  route do |r|
    # ...
    all_locales = I18n.available_locales.map(&:to_s) - [I18n.default_locale.to_s]

    r.on [*all_locales, true], "users" do |locale|
      rails_request = ActionDispatch::Request.new(env)
      rails_request.params[:locale] = locale if locale

      r.rodauth
      r.pass
    end
    # ...
  end
end

This uses Roda's routing to match an optional locale prefix, using an array matcher, in combination with true matcher to achieve an optional seg…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@renchap
Comment options

@janko
Comment options

@renchap
Comment options

@janko
Comment options

Answer selected by renchap
Comment options

You must be logged in to vote
1 reply
@janko
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants