Skip to content

Commit d718ed4

Browse files
authored
Merge pull request #701 from stevegeek/fix_load_rb_with_pathname
Fix loading of .rb locale files when `load_path` is not a string
2 parents eacc34f + ee22f10 commit d718ed4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/i18n/backend/base.rb

+1-1
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

+10
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)