enriclluelles/route_translator

Translating scopes

james-em opened this issue · 1 comments

Bug description

We have multiple routes that target the same controller and actions, but the controller filter results based on the "scope" parameter in the routes. Let me try to clarify by exemple:

Exemple

class ArticlesController
  def index
    @articles = Article.where(scope: params[:scope])
  end

  def show
    @article = Article.find_by!(scope: params[:scope], id: params[:id])
  end

  def new
    @article = Article.new(scope: params[:scope])
  end
end

%w[stories careers].each do |route_scope|
  scope route_scope, scope: route_scope, as: route_scope, module: nil do
    resources :articles, only: %i[index show new]
  end
end

Available routes:

/stories
/stories/:id
/stories/new

/careers
/careers/:id
/careers/new

Problem

I can translate all routes at once by targetting the controller, but I can't translate them individually.

All at once:

fr:
  routes:
    controllers:
      articles:
        articles: articles
        index: liste-des-articles
        new: nouvel-article

What I can't do is something like

fr:
  routes:
    controllers:
      careers:
        careers: carrieres
        index: liste-des-carrieres
        new: nouvelle-carriere
      stories:
        stories: articles
        index: liste-des-histoires
        new: nouvelle-histoire

or something like

fr:
  routes:
    controllers:
      careers/articles:
        careers: carrieres
        index: liste-des-carrieres
        new: nouvelle-carriere
      stories/articles:
        stories: articles
        index: liste-des-histoires
        new: nouvelle-histoire

Steps to reproduce

Follow example

Expected behavior

To have a way to target specific scope when they use the same controller/action

Actual behavior

There is no documented way to target a specific scope when they use the same controller/action

Reproducible reduced test case

No response

Ruby version

3.2.2

Ruby on Rails version

7.1.2

Route Translator version

14.1.1

I18n configuration

I18n.available_locales = %i[fr en]
I18n.default_locale = :fr
I18n.enforce_available_locales = false

Route Translator configuration

Empty initializer

Rails routes source

%w[stories careers].each do |route_scope|
  scope route_scope, scope: route_scope, as: route_scope, module: nil do
    resources :articles, only: %i[index show new]
  end
end

Rails locales

N/A

Rails routes

N/A

Bug report checklist

  • I have searched for existing issues and to the best of my knowledge this is not a duplicate
  • I understand that debugging Route Translator is a time consuming task, and I have carefully provided all the information requested