From ee22f105906e502d77b9375e36b7ca55aaabe3b7 Mon Sep 17 00:00:00 2001 From: Stephen Ierodiaconou Date: Tue, 3 Sep 2024 09:06:14 +0200 Subject: [PATCH] Fix loading of .rb locale files when load_path is not a string, eg it is a Pathname --- lib/i18n/backend/base.rb | 2 +- test/i18n/load_path_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index 7ca9c28a..6e7c7df1 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -244,7 +244,7 @@ def load_file(filename) # Loads a plain Ruby translations file. eval'ing the file must yield # a Hash containing translation data with locales as toplevel keys. def load_rb(filename) - translations = eval(IO.read(filename), binding, filename) + translations = eval(IO.read(filename), binding, filename.to_s) [translations, false] end diff --git a/test/i18n/load_path_test.rb b/test/i18n/load_path_test.rb index 7d0d27a1..ab354c08 100644 --- a/test/i18n/load_path_test.rb +++ b/test/i18n/load_path_test.rb @@ -31,4 +31,14 @@ def setup I18n.load_path << Dir[locales_dir + '/*.{rb,yml}'] assert_equal "baz", I18n.t(:'foo.bar') end + + test "adding Pathnames to the load path does not break YML file locale loading" do + I18n.load_path << Pathname.new(locales_dir + '/en.yml') + assert_equal "baz", I18n.t(:'foo.bar') + end + + test "adding Pathnames to the load path does not break Ruby file locale loading" do + I18n.load_path << Pathname.new(locales_dir + '/en.rb') + assert_equal "bas", I18n.t(:'fuh.bah') + end end