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

Fix extra i18n namespacing #293

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/pagy/extras/i18n.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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