Skip to content

Commit

Permalink
Fix loading of .rb locale files when load_path is not a string, eg it…
Browse files Browse the repository at this point in the history
… is a Pathname
  • Loading branch information
stevegeek committed Sep 3, 2024
1 parent eacc34f commit ee22f10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions test/i18n/load_path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ee22f10

Please sign in to comment.