Skip to content

Commit

Permalink
Fix extra i18n namespacing (#293)
Browse files Browse the repository at this point in the history
* Add a test that looks at i18n working in Modules included
* Demonstrates #290
* Correct name collision with I18n with UseI18n
(fixes #290)
  • Loading branch information
whithajess committed Apr 8, 2021
1 parent 8cd25d2 commit 3a9e70f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pagy/extras/i18n.rb
Expand Up @@ -10,10 +10,10 @@ module Frontend

Pagy::I18n.clear.instance_eval { undef :load; undef :t } # unload the pagy default constant for efficiency

module I18n
module UseI18nGem
def pagy_t(key, **opts) = ::I18n.t(key, **opts)
end
prepend I18n
prepend UseI18nGem

end
end
8 changes: 8 additions & 0 deletions test/mock_helpers/application_helper.rb
@@ -0,0 +1,8 @@
module ApplicationHelper
include Pagy::Frontend

def any_method_name()
I18n.t("test")
end

end
6 changes: 6 additions & 0 deletions test/pagy/extras/i18n_test.rb
Expand Up @@ -7,11 +7,17 @@

SimpleCov.command_name 'i18n' if ENV['RUN_SIMPLECOV'] == 'true'

require_relative '../../mock_helpers/application_helper'
include ApplicationHelper

describe Pagy::Frontend do

let(:view) { MockView.new }

describe "#pagy_t with I18n" do
it 'works with an included Module' do
ApplicationHelper.any_method_name()
end

it 'pluralizes' do
_(view.pagy_t('pagy.nav.prev')).must_equal "‹ Prev"
Expand Down

0 comments on commit 3a9e70f

Please sign in to comment.