Skip to content

Commit ee22f10

Browse files
committed
Fix loading of .rb locale files when load_path is not a string, eg it is a Pathname
1 parent eacc34f commit ee22f10

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/i18n/backend/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def load_file(filename)
244244
# Loads a plain Ruby translations file. eval'ing the file must yield
245245
# a Hash containing translation data with locales as toplevel keys.
246246
def load_rb(filename)
247-
translations = eval(IO.read(filename), binding, filename)
247+
translations = eval(IO.read(filename), binding, filename.to_s)
248248
[translations, false]
249249
end
250250

test/i18n/load_path_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,14 @@ def setup
3131
I18n.load_path << Dir[locales_dir + '/*.{rb,yml}']
3232
assert_equal "baz", I18n.t(:'foo.bar')
3333
end
34+
35+
test "adding Pathnames to the load path does not break YML file locale loading" do
36+
I18n.load_path << Pathname.new(locales_dir + '/en.yml')
37+
assert_equal "baz", I18n.t(:'foo.bar')
38+
end
39+
40+
test "adding Pathnames to the load path does not break Ruby file locale loading" do
41+
I18n.load_path << Pathname.new(locales_dir + '/en.rb')
42+
assert_equal "bas", I18n.t(:'fuh.bah')
43+
end
3444
end

0 commit comments

Comments
 (0)