fnando / i18n-js

It's a small library to provide the I18n translations on the Javascript. It comes with Rails support.
MIT License
3.77k stars 520 forks source link

Bug: multiple locales dir in listen configuration require to specify full path, not relative #675

Closed francescob closed 1 year ago

francescob commented 2 years ago

Description

When setting locales dir array using I18n.listen method, using relative paths leads to an error

How to reproduce

set I18nJS.listen( locales_dir: ["config/locales"] + Dir.glob("vendor/**/config/locales"), )

in config/initializers/i18n.rb

What do you expect

Listen should watch for all changes in those folders

What happened instead

Server won't start with error:

/Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/pathname.rb:528:inrelative_path_from': different prefix: "" and "/Users/francesco/projects/" (ArgumentError)`

current working fix:

use

locales_dir: ["#{Rails.root}/config/locales"] + Dir.glob("#{Rails.root}/vendor/**/config/locales"),

Software:

Full backtrace

`16:16:55 rails.1   | /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/pathname.rb:528:in `relative_path_from': different prefix: "" and "/Users/francesco/projects/epiclin_2" (ArgumentError)
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/i18n-js-4.0.1/lib/i18n-js/listen.rb:34:in `relative_path'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/i18n-js-4.0.1/lib/i18n-js/listen.rb:25:in `block in listen'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/i18n-js-4.0.1/lib/i18n-js/listen.rb:25:in `map'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/i18n-js-4.0.1/lib/i18n-js/listen.rb:25:in `listen'
16:16:55 rails.1   |    from /Users/francesco/projects/epiclin_2/config/initializers/i18n.rb:3:in `block in <top (required)>'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/lazy_load_hooks.rb:68:in `block in execute_hook'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-6.1.6.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/application/finisher.rb:140:in `block in <module:Finisher>'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/initializable.rb:32:in `instance_exec'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/initializable.rb:32:in `run'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/initializable.rb:61:in `block in run_initializers'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `each'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `call'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/initializable.rb:60:in `run_initializers'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/application.rb:391:in `initialize!'
16:16:55 rails.1   |    from /Users/francesco/projects/epiclin_2/config/environment.rb:5:in `<top (required)>'
16:16:55 rails.1   |    from config.ru:3:in `require_relative'
16:16:55 rails.1   |    from config.ru:3:in `block in <main>'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:116:in `eval'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:116:in `new_from_string'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:105:in `load_file'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:66:in `parse_file'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:349:in `build_app_and_options_from_config'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:249:in `app'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:422:in `wrapped_app'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/server/server_command.rb:77:in `log_to_stdout'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/server/server_command.rb:37:in `start'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/server/server_command.rb:144:in `block in perform'
16:16:55 rails.1   |    from <internal:kernel>:90:in `tap'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/server/server_command.rb:135:in `perform'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/command/base.rb:69:in `perform'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/command.rb:48:in `invoke'
16:16:55 rails.1   |    from /Users/francesco/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-6.1.6.1/lib/rails/commands.rb:18:in `<top (required)>'
16:16:55 rails.1   |    from bin/rails:4:in `require'
16:16:55 rails.1   |    from bin/rails:4:in `<main>'
16:16:56 rails.1   | exited with code 1
16:16:56 system    | sending SIGTERM to all processes
16:17:01 system    | sending SIGKILL to all processes`