From 75ebc1bd98cc5f642ea1f25700ff479bb9b5d04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 27 Aug 2024 17:03:52 +0200 Subject: [PATCH] Fix custom locales not taking precedence When we upgraded to Rails 7 in commit 8596f1539, we broke the custom locales since now all nested folders in `config/locales/` are loaded by default [1]. This meant that the custom folder was now loaded before any languages whose code alphabetically goes after the word "custom". As a workaround, we're overwriting the default locales paths so they don't include the custom folder. We're doing this step before the `add_locales` initializer; that is, before the default locales paths are used. Unfortunately, I haven't found a way to add a test for this behavior, since we would need to add a file in `config/locales/custom` that overwrites an internationalization key for an existing language, but only during a specific test, and the i18n load path is evaluated when the application starts up. [1] See pull request 41872 in https://github.com/rails/rails/ --- config/application.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index ca6317e38..3411e15e0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -113,7 +113,9 @@ module Consul "val" => "es" }] - config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**[^custom]*", "*.{rb,yml}")] + initializer :exclude_custom_locales_automatic_loading, before: :add_locales do + paths.add "config/locales", glob: "**[^custom]*/*.{rb,yml}" + end config.i18n.load_path += Dir[Rails.root.join("config", "locales", "custom", "**", "*.{rb,yml}")] config.after_initialize do