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

Ruby 2.7.0 warning: The called method `t' is defined here #516

Open
EnziinSystem opened this issue Feb 1, 2020 · 15 comments
Open

Ruby 2.7.0 warning: The called method `t' is defined here #516

EnziinSystem opened this issue Feb 1, 2020 · 15 comments

Comments

@EnziinSystem
Copy link

EnziinSystem commented Feb 1, 2020

Ruby version: 2.7.0
Rails version: 6.0.2.1
i18n version: 1.8.2

I get a message, please update for Ruby 2.7

/bundle/ruby/2.7.0/gems/i18n-1.8.2/lib/i18n.rb:195: warning: The called method `t' is defined here

Thanks.

@radar
Copy link
Collaborator

radar commented Feb 1, 2020

@matthuhiggins
Copy link

matthuhiggins commented Feb 19, 2020

This is a duplicate of #500.

It was fixed in Rails 6.0.1: rails/rails@adef632#diff-cda406008ce3935156e8ba173b1e9837L85. There's nothing for you to do here.

The error that ruby 2.7 outputs is quite terrible

@lucascaton
Copy link

Hi there. I'm running Rails 6.0.3 and i18n 1.8.2 and I still get the error:

~/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/i18n-1.8.2/lib/i18n.rb:195: warning: The called method `t' is defined here

@jakehockey10
Copy link

I am still receiving this as well:

$ rails -v
Rails 6.0.3.1
$ gem which i18n
/home/jakehockey10/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/i18n-1.8.2/lib/i18n.rb

@radar
Copy link
Collaborator

radar commented May 31, 2020

I am not sure how to fix this one without changing the API of I18n.translate , and the fix might require a bump for the minimum version of Ruby supported as well.

@radar
Copy link
Collaborator

radar commented May 31, 2020

@jakehockey10 Under what circumstances are you seeing the message? What call specifically are you making in your Rails app to generate that message?

@mgomes
Copy link

mgomes commented May 31, 2020

@radar I still see this warning as well, but in my apps it seems to originate from the mongoid gem. Specifically this call: https://github.com/mongodb/mongoid/blob/master/lib/mongoid/errors/mongoid_error.rb#L51

@jakehockey10
Copy link

jakehockey10 commented May 31, 2020 via email

@opsydev
Copy link

opsydev commented Jun 1, 2020

I am seeing this in regular application logs as well.

@matthuhiggins
Copy link

matthuhiggins commented Jun 1, 2020

@radar I can guarantee that it's due to dependencies unique to everyone's apps. I have 4 rails apps on ruby 2.7, neither having this problem. Two are 6.0.1 and two are are 6.0.3. The confusing error message leads users to think it's caused by your gem.

@shinyamagami
Copy link

I upgrade versions of faker or i18n, and the error disappeared.

@alecslupu
Copy link

While running

ruby 2.7.1 
rails 6.0.4.1
ruby-i18n 1.8.10

I get the following message:
/bundle_cache/ruby/2.7.0/gems/i18n-1.8.10/lib/i18n.rb:196: warning: The called method `t' is defined here

While running

ruby 3.0.2
rails 6.0.4.1
ruby-i18n 1.8.10

I get

     Failure/Error:
            def translate(key = nil, throw: false, raise: false, locale: nil, **options) # TODO deprecate :raise
              locale ||= config.locale
              raise Disabled.new('t') if locale == false
              enforce_available_locales!(locale)
        
              backend = config.backend
        
              result = catch(:exception) do
                if key.is_a?(Array)
                  key.map { |k| backend.translate(locale, k, options) }
      
      ArgumentError:
        wrong number of arguments (given 2, expected 0..1)
      Shared Example Group: "present admin log entry" called from ./spec/presenters/decidim/sortitions/admin_log/sortition_presenter_spec.rb:6
      # /bundle_cache/ruby/3.0.0/gems/i18n-1.8.10/lib/i18n.rb:196:in `translate'
      # /code/decidim/decidim-core/app/presenters/decidim/log/base_presenter.rb:108:in `block in present_explanation'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:45:in `block in capture'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:209:in `with_output_buffer'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:45:in `capture'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/tag_helper.rb:273:in `content_tag'
      # /code/decidim/decidim-core/app/presenters/decidim/log/base_presenter.rb:107:in `present_explanation'
      # /code/decidim/decidim-core/app/presenters/decidim/log/base_presenter.rb:121:in `block in present_content'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:45:in `block in capture'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:209:in `with_output_buffer'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:45:in `capture'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/tag_helper.rb:273:in `content_tag'
      # /code/decidim/decidim-core/app/presenters/decidim/log/base_presenter.rb:120:in `present_content'
      # /code/decidim/decidim-core/app/presenters/decidim/log/base_presenter.rb:154:in `block in present_action_log'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:45:in `block in capture'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:209:in `with_output_buffer'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/capture_helper.rb:45:in `capture'
      # /bundle_cache/ruby/3.0.0/gems/actionview-6.0.4.1/lib/action_view/helpers/tag_helper.rb:273:in `content_tag'
      # /code/decidim/decidim-core/app/presenters/decidim/log/base_presenter.rb:153:in `present_action_log'
      # /code/decidim/decidim-core/app/presenters/decidim/log/base_presenter.rb:43:in `present'
      # /code/decidim/decidim-core/lib/decidim/core/test/shared_examples/admin_log_presenter_examples.rb:28:in `block (3 levels) in <top (required)>'
      # /code/decidim/decidim-core/lib/decidim/core/test/shared_examples/admin_log_presenter_examples.rb:32:in `block (4 levels) in <top (required)>'
      # /bundle_cache/ruby/3.0.0/gems/webmock-3.13.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <main>'

@radar
Copy link
Collaborator

radar commented Aug 19, 2021

@alecslupu: I’m going to need to see the line from the spec that is invoking i18n

@alecslupu
Copy link

@radar, the project is open source :

https://github.com/decidim/decidim/blob/develop/decidim-sortitions/spec/presenters/decidim/sortitions/admin_log/sortition_presenter_spec.rb#L6
https://github.com/decidim/decidim/blob/develop/decidim-core/app/presenters/decidim/log/base_presenter.rb#L108

the code you're interested in:

def present_explanation
        h.content_tag(:div, class: "logs__log__explanation") do
          I18n.t(
            action_string,
            i18n_params
          ).html_safe
        end
      end

@sandstrom
Copy link
Contributor

sandstrom commented Aug 24, 2022

Here is another example of this issue:

https://github.com/bridgetownrb/bridgetown/blob/v1.1.0/bridgetown-core/lib/bridgetown-core/helpers.rb#L110-L116

      # Forward all arguments to I18n.t method
      #
      # @return [String] the translated string
      # @see I18n
      def t(*args)
        I18n.send :t, *args
      end

I've opened a PR in that repo: bridgetownrb/bridgetown#615

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants