Skip to content

Crash on enforce_avialable_locales without locale :en #1778

Closed
@thedarkside

Description

@thedarkside

My rails app is configured this way:

config.i18n.available_locales = [:de]
config.i18n.default_locale = :de
config.i18n.fallbacks = true

The enforce_available_locales is set to true by default.

When hitting the grape api with an invalid request, grape sets the locale to the FALLBACK_LOCALE which is :en and crashes due to enforce_available_locales being true like so:

I18n::InvalidLocale (:en is not a valid locale):
  
i18n (1.0.1) lib/i18n.rb:311:in `enforce_available_locales!'
i18n (1.0.1) lib/i18n.rb:179:in `translate'
grape (1.1.0) lib/grape/exceptions/base.rb:77:in `translate'
grape (1.1.0) lib/grape/exceptions/base.rb:65:in `translate_message'
grape (1.1.0) lib/grape/exceptions/validation.rb:13:in `initialize'
grape (1.1.0) lib/grape/validations/validators/presence.rb:6:in `exception'
grape (1.1.0) lib/grape/validations/validators/presence.rb:6:in `raise'

In my opinion grape should check if :en is available and if not then just return the key in the error response instead of crashing miserably

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions