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

Can't use arguments in t helper in Ruby 3 #617

Closed
nashbridges opened this issue Aug 28, 2022 · 1 comment
Closed

Can't use arguments in t helper in Ruby 3 #617

nashbridges opened this issue Aug 28, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@nashbridges
Copy link

nashbridges commented Aug 28, 2022

Bridgetown Version: 1.1.0
Ruby Version: 3.1.0

To Reproduce

# src/_locales/en.yml

title_template: "%{title} | My site"
# src/_layouts/default.erb

<title><%= t :title_template, title: "Homepage" %></title>

Current behavior

[Bridgetown]   Exception raised: ArgumentError
[Bridgetown] wrong number of arguments (given 2, expected 0..1)
[Bridgetown]                  1: /Users/nash/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/i18n-1.12.0/lib/i18n.rb:210:in `translate'
[Bridgetown]                  2: /Users/nash/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/bridgetown-core-1.1.0/lib/bridgetown-core/helpers.rb:115:in `t'
[Bridgetown]                  3: /Users/nash/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/bridgetown-core-1.1.0/lib/bridgetown-core/ruby_template_view.rb:66:in `method_missing'

The reason is that t uses delegation to I18n.t:

def t(*args)
I18n.send :t, *args
end

Delegation is tricky to do correctly in order to support both Ruby 2.x and 3.x.

Current workaround

Use I18n.t in templates.

Project wide?

I haven't checked, but maybe there are other places in the project where delegation is used. These should be fixed as well.

@nashbridges nashbridges added the bug Something isn't working label Aug 28, 2022
@nashbridges
Copy link
Author

Just noticed the recent (unreleased) PR fixed the issue.

maybe there are other places in the project where delegation is used

That is worth to check anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant