ruby-i18n / i18n

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

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

Open EnziinSystem opened 4 years ago

EnziinSystem commented 4 years ago

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 commented 4 years ago

Not enough information.

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

matthuhiggins commented 4 years ago

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

lucascaton commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

mgomes commented 4 years ago

@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 commented 4 years ago

When I run rails test

On Sun, May 31, 2020, 4:34 PM Mauricio Gomes notifications@github.com 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 .

opsydev commented 4 years ago

I am seeing this in regular application logs as well.

matthuhiggins commented 4 years ago

@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 commented 4 years ago

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

alecslupu commented 3 years ago

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 commented 3 years ago

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

alecslupu commented 3 years ago

@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 commented 2 years ago

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