Skip to content

Commit

Permalink
Merge pull request #701 from stevegeek/fix_load_rb_with_pathname
Browse files Browse the repository at this point in the history
Fix loading of .rb locale files when `load_path` is not a string
  • Loading branch information
radar committed Sep 15, 2024
2 parents eacc34f + ee22f10 commit d718ed4
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 d718ed4

Please sign in to comment.