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

Error with default locale not :en #219

Closed
baldarn opened this issue Dec 4, 2024 · 12 comments
Closed

Error with default locale not :en #219

baldarn opened this issue Dec 4, 2024 · 12 comments

Comments

@baldarn
Copy link

baldarn commented Dec 4, 2024

hello,

i have default locale as :it. i have this error when accessing the jobs page:

MissionControl::Jobs::JobsControllerTest#test_get_jobs_and_job_details_when_the_default_locale_is_set_to_another_language_than_English:
I18n::InvalidLocale: :it is not a valid locale
    /home/baldarn/.local/share/mise/installs/ruby/3.3.1/lib64/ruby/gems/3.3.0/gems/i18n-1.14.6/lib/i18n.rb:382:in `enforce_available_locales!'

i tried monkeypatching the lib/mission_control/jobs/i18n_config.rb with

class MissionControl::Jobs::I18nConfig < ::I18n::Config
  def available_locales
    [ :it, :en ]
  end
end

and works, do you think there is a better way to achieve this? maybe fallbacking to :en locale if another locale is there

@rosa
Copy link
Member

rosa commented Dec 4, 2024

Hey @baldarn, huh, that's odd. The locale used should be set to English for Mission Control controllers here. I see the error you're posting above is from a test, so it's not clear to me how are you triggering it 🤔

@baldarn
Copy link
Author

baldarn commented Dec 4, 2024

i triggered that adding: I18n.current_locale = :it

that here: test/controllers/jobs_controller_test.rb:108

i had that in my app and wanted to understand what was happening XD

@rosa
Copy link
Member

rosa commented Dec 4, 2024

Do you mean I18n.default_locale? Are you setting it for Mission Control's controllers as well as your app?

@rosa
Copy link
Member

rosa commented Dec 4, 2024

Maybe it'd be more helpful to see the whole backtrace of the error in your app 🤔

@guizaols
Copy link

guizaols commented Dec 4, 2024

Same error over here: :"pt-BR" is not a valid locale. I tried the monkey patch from @baldarn and still doesn't working. I set back to the version 0.6.0 to make it work again

foreman start -f Procfile.dev
16:10:26 web.1  | Started GET "/administrate/jobs" for ::1 at 2024-12-04 16:10:26 -0300
16:10:26 web.1  | Processing by MissionControl::Jobs::QueuesController#index as HTML
16:10:27 web.1  |   ↳ lib/middleware/request_logger.rb:23:in `call'
16:10:27 web.1  |   Rendering layout /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/layouts/mission_control/jobs/application.html.erb
16:10:27 web.1  |   Rendering /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/mission_control/jobs/queues/index.html.erb within layouts/mission_control/jobs/application
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/mission_control/jobs/queues/_actions.html.erb (Duration: 3.4ms | GC: 0.0ms)
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/mission_control/jobs/queues/_actions.html.erb (Duration: 0.4ms | GC: 0.0ms)
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/mission_control/jobs/queues/_actions.html.erb (Duration: 0.3ms | GC: 0.0ms)
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/mission_control/jobs/queues/_actions.html.erb (Duration: 0.4ms | GC: 0.0ms)
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/mission_control/jobs/queues/_actions.html.erb (Duration: 0.8ms | GC: 0.0ms)
16:10:27 web.1  |   Rendered collection of /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/mission_control/jobs/queues/_queue.html.erb [5 times] (Duration: 10.6ms | GC: 0.6ms)
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/mission_control/jobs/queues/index.html.erb within layouts/mission_control/jobs/application (Duration: 12.1ms | GC: 0.6ms)
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/layouts/mission_control/jobs/application_selection/_servers.html.erb (Duration: 0.5ms | GC: 0.0ms)
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/layouts/mission_control/jobs/_application_selection.html.erb (Duration: 1.6ms | GC: 0.0ms)
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/layouts/mission_control/jobs/_flash.html.erb (Duration: 0.5ms | GC: 0.0ms)
16:10:27 web.1  |   ↳ lib/middleware/request_logger.rb:23:in `call'
16:10:27 web.1  |   Rendered /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/layouts/mission_control/jobs/_navigation.html.erb (Duration: 75.6ms | GC: 0.0ms)
16:10:27 web.1  |   Rendered layout /Users/guizaols/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-1.0.0/app/views/layouts/mission_control/jobs/application.html.erb (Duration: 130.4ms | GC: 1.1ms)
16:10:27 web.1  | Completed 500 Internal Server Error in 618ms (Views: 120.8ms | ActiveRecord: 174.1ms (13 queries, 0 cached) | GC: 109.0ms)
16:10:27 web.1  | I18n::InvalidLocale (:"pt-BR" is not a valid locale):
16:10:27 web.1  | lib/middleware/request_logger.rb:23:in `call'

@rosa
Copy link
Member

rosa commented Dec 4, 2024

@guizaols ahhh, I see the problem now. I'll fix it shortly. Thank you!

rosa added a commit that referenced this issue Dec 4, 2024
Otherwise, the `with_locale` block will try to set back any locale set
by the host app, which might or might not be :en, leading to an
`I18n::InvalidLocale` error.

Addresses #219.
@rosa
Copy link
Member

rosa commented Dec 4, 2024

I think this should fix it: #220. Would you mind trying out that branch and see if it works for you? I'll ship a new hotfix version if so.

@guizaols
Copy link

guizaols commented Dec 4, 2024

@rosa This fix worked!

@rosa
Copy link
Member

rosa commented Dec 4, 2024

Awesome, thanks so much for confirming! I'll ship version 1.0.1 with it shortly.

rosa added a commit that referenced this issue Dec 4, 2024
Otherwise, the `with_locale` block will try to set back any locale set
by the host app, which might or might not be :en, leading to an
`I18n::InvalidLocale` error.

Addresses #219.
@guizaols
Copy link

guizaols commented Dec 4, 2024

Thanks a lot!

@rosa
Copy link
Member

rosa commented Dec 4, 2024

Thanks to you and @baldarn for reporting, and sorry for the trouble. I've just published v1.0.1 🙏

@rosa rosa closed this as completed Dec 4, 2024
@baldarn
Copy link
Author

baldarn commented Dec 4, 2024

@rosa thank you! super fast!
thanks also to @guizaols for giving more details. I'm wasn't at the PC :/

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants