Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Translating scopes #306

Open
2 tasks done
james-em opened this issue Jan 17, 2024 · 0 comments
Open
2 tasks done

[Question] Translating scopes #306

james-em opened this issue Jan 17, 2024 · 0 comments
Labels

Comments

@james-em
Copy link

james-em commented Jan 17, 2024

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
@james-em james-em added the bug label Jan 17, 2024
@james-em james-em changed the title [Question]: Translating scopes [Question] Translating scopes Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant