ruby-i18n / i18n

Internationalization (i18n) library for Ruby
MIT License
986 stars 411 forks source link

[BUG] Loading RB files with Pathname in `load_path` raises `TypeError` #700

Closed stevegeek closed 1 month ago

stevegeek commented 2 months ago

What I tried to do

Set I18n.load_path to Pathname instances rather than strings. This works for .yml, but for .rb files it raises.

This came up cause I allowed Rubocop to auto correct a configuration from

config.i18n.load_path += Dir[Rails.root.join("config/locales/**/*.{rb,yml}")]

to

config.i18n.load_path += Rails.root.glob("config/locales/**/*.{rb,yml}")

where glob returns Pathnames

What I expected to happen

It to not raise. It raises cause the 3rd argument to eval() should be a string to the file path

What actually happened

`eval': no implicit conversion of Pathname into String (TypeError)

translations = eval(IO.read(filename), binding, filename)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Versions of i18n, rails, and anything else you think is necessary

Rails 7.2, I18n 1.14.5

PR with fix coming soon.

Thanks!