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

Allow generation of raw named routes with single locale configuration #286

Closed

Conversation

timfsw
Copy link
Contributor

@timfsw timfsw commented Jul 21, 2023

If there is only one locale like es it's now possible to generate routes like products_path instead of products_es_path.

It is not needed in a single locale application to use the localized route name.

@tagliala
Copy link
Collaborator

Can I ask why this is needed?

If there is only one locale available I would not use this gem

@timfsw
Copy link
Contributor Author

timfsw commented Jul 23, 2023

Can I ask why this is needed?

If there is only one locale available I would not use this gem

Of course.

I often start with a monolingual app that is translated later (or maybe not).

Therefore, the use of a Yaml file directly during the implementation is a great advantage and all translations are centrally located in the locales folder.

So far, I have had to install the following fix in order to call tests successfully.

ActionController::TestCase::Behavior.module_eval do
  alias_method :process_old, :process

  def process(action, **args)
    args[:params] ||= {}
    args[:params]["locale"] ||= I18n.default_locale.to_s

    process_old(action, **args)
  end
end
Failures:
  1) Web::AppointmentsController GET #new should be successful
     Failure/Error: get :new
     ActionController::UrlGenerationError:
       No route matches {:action=>"new", :controller=>"web/appointments"}
     # ./spec/controllers/web/appointments_controller_spec.rb:8:in `block (3 levels) in <top (required)>'
require 'rails_helper'

RSpec.describe Web::AppointmentsController, type: :controller do
  routes { Web::Engine.routes }

  describe 'GET #new' do
    it 'should be successful' do
      get :new

      expect(response).to be_successful
    end
  end
end

@tagliala
Copy link
Collaborator

Are you using route translator inside an engine?

@timfsw
Copy link
Contributor Author

timfsw commented Jul 23, 2023

Yes, it's used inside an engine.

@tagliala
Copy link
Collaborator

As per #178, it is possible that the engine feature will be entirely dropped in a future version of route translator because the implementation is buggy and partial

Anyway, I need to take a look at this.

I do not remember if there is an existing configuration to allow this and also I would avoid to support this use case because I prefer to introduce dependencies only when needed

I did not understand if this is an issue related to specs/tests

@tagliala
Copy link
Collaborator

@timfsw any chance to clarify if this is an issue with specs?

Tomorrow I will have some time to invest on route translator

@tagliala
Copy link
Collaborator

tagliala commented Aug 5, 2023

Closing here as wontfix

Applications with a single locale should not use this library

@tagliala tagliala closed this Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants