i18n icon indicating copy to clipboard operation
i18n copied to clipboard

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

Open EnziinSystem opened this issue 5 years ago • 15 comments

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.

EnziinSystem avatar Feb 01 '20 05:02 EnziinSystem

Not enough information.

https://github.com/ruby-i18n/i18n/blob/master/.github/ISSUE_TEMPLATE/bug_report.md

radar avatar Feb 01 '20 08:02 radar

This is a duplicate of https://github.com/ruby-i18n/i18n/issues/500.

It was fixed in Rails 6.0.1: https://github.com/rails/rails/commit/adef6323e682e026ea6bdbf3a6eb187491f0fbd6#diff-cda406008ce3935156e8ba173b1e9837L85. There's nothing for you to do here.

The error that ruby 2.7 outputs is quite terrible

matthuhiggins avatar Feb 19 '20 05:02 matthuhiggins

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

lucascaton avatar May 09 '20 08:05 lucascaton

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

jakehockey10 avatar May 31 '20 19:05 jakehockey10

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 avatar May 31 '20 22:05 radar

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

radar avatar May 31 '20 22:05 radar

@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

mgomes avatar May 31 '20 22:05 mgomes

When I run rails test

On Sun, May 31, 2020, 4:34 PM Mauricio Gomes [email protected] wrote:

@radar https://github.com/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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ruby-i18n/i18n/issues/516#issuecomment-636540399, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4VR7VFH4VRARDNDN7SFLRULLQHANCNFSM4KOQ5LVA .

jakehockey10 avatar May 31 '20 23:05 jakehockey10

I am seeing this in regular application logs as well.

opsydev avatar Jun 01 '20 02:06 opsydev

@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.

matthuhiggins avatar Jun 01 '20 04:06 matthuhiggins

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

shinyamagami avatar Jun 21 '20 04:06 shinyamagami

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>'

alecslupu avatar Aug 19 '21 20:08 alecslupu

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

radar avatar Aug 19 '21 21:08 radar

@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

alecslupu avatar Aug 19 '21 22:08 alecslupu

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: https://github.com/bridgetownrb/bridgetown/pull/615

sandstrom avatar Aug 24 '22 11:08 sandstrom