enriclluelles/route_translator

Issue with partial implementation of route_translator

breiko83 opened this issue · 3 comments

I'm trying to use route_translator only on a specific route.

This is my routes.rb

Rails.application.routes.draw do
  scope '(:locale)', locale: /fr/ do
    get 'account/index'
    root 'account#index'
  end

  localized do
    resources :pages, only: %w[index]
  end
end

The issue I'm having is when I'm on pages/index view the links to account are incorrect:

# app/views/pages/index.html.erb
<%= link_to "Account", account_index_url %> 
# is -> http://localhost:3000/en/account/index 
# should be -> http://localhost:3000/account/index
# app/views/pages/index.html.erb
<%= link_to "Account", url_for(controller: 'account', action: 'index', locale: I18n.locale.to_s) %>
# is -> http://localhost:3000/en/account/index 
# should be -> http://localhost:3000/account/index 
# app/views/pages/index.html.erb
<%= link_to "Root", root_path %> 
# is -> http://localhost:3000/en
# should be -> http://localhost:3000

My locale.rb

# Permitted locales available for the application
I18n.available_locales = %i[en fr]

# Set default locale to something other than :en
I18n.default_locale = :en

Hi!

Thanks for being part of the Route Translator Community.

# app/views/pages/index.html.erb
<%= link_to "Account", account_index_url %> 
# is -> http://localhost:3000/en/account/index 
# should be -> http://localhost:3000/account/index

I'm not sure, because account is not managed by Route Translator and the url is specifying a locale param managed by the application (scope '(:locale)', locale: /fr/ block).

should be -> http://localhost:3000

Not sure either, because localized block does not know about the root path, which is nested in a different block

Can you please rephrase this request in terms of what your application need to achieve?

What I'm trying to achieve is using localized only on subset of routes.

account is just standard localised route as described here: https://guides.rubyonrails.org/i18n.html#setting-the-locale-from-url-params. As this does not require translation I don't want to move it inside the localized block.

Probably the gem does not support mixing standard route localisations (not translatable) with translatable routes?

What I'm trying to achieve is using localized only on subset of routes.

This is possible by wrapping only a subset of routes in the localized block

As this does not require translation I don't want to move it inside the localized block.

This is not yet clear to me

<%= link_to "Account", url_for(controller: 'account', action: 'index', locale: I18n.locale.to_s) %>

If this url is "localized (in french) but not translatable", then I would expect locale: to be :fr for all routes 🤷🏻‍♂️

I would consider reopening with a clear use case