Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading of .rb locale files when load_path is not a string #701

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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