Skip to content

Commit

Permalink
Fallback to 'ago' when 'time_ago' does not exist, making #3135 backwa…
Browse files Browse the repository at this point in the history
…rd-compatible
  • Loading branch information
mshibuya committed May 21, 2019
1 parent 33a69f1 commit 49add74
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/rails_admin/main/dashboard.html.haml
Expand Up @@ -18,7 +18,7 @@
%span.show= link_to capitalize_first_letter(abstract_model.config.label_plural), index_path, class: 'pjax'
%td
- if last_created
= t "admin.misc.time_ago", time: time_ago_in_words(last_created)
= t "admin.misc.time_ago", time: time_ago_in_words(last_created), default: "#{time_ago_in_words(last_created)} #{t("admin.misc.ago")}"
%td
- count = @count[abstract_model.model.name]
- percent = count > 0 ? (@max <= 1 ? count : ((Math.log(count+1) * 100.0) / Math.log(@max+1)).to_i) : -1
Expand Down
Expand Up @@ -43,4 +43,38 @@
expect(find('tr.user_confirmed_links')).to have_content '10 days ago'
expect(find('tr.comment_confirmed_links')).to have_content '20 days ago'
end

describe 'with I18n' do
around do |example|
I18n.config.available_locales = I18n.config.available_locales + [:xx]
I18n.backend.class.send(:include, I18n::Backend::Pluralization)
I18n.backend.store_translations :xx,
admin: {
misc: {
ago: 'back',
},
},
datetime: {
distance_in_words: {
x_days: {
one: '1 day',
},
},
}

I18n.locale = :xx

example.run

I18n.locale = :en
I18n.config.available_locales = I18n.config.available_locales - [:xx]
end

it "fallbacks to 'ago' when 'time_ago' is not available" do
FactoryBot.create(:player, created_at: 1.day.ago)

visit dashboard_path
expect(page).to have_content '1 day back'
end
end
end

0 comments on commit 49add74

Please sign in to comment.