Skip to content

Commit

Permalink
Fix custom translations with options
Browse files Browse the repository at this point in the history
  • Loading branch information
decabeza committed Mar 31, 2020
1 parent 14106ce commit ff64afe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion config/initializers/i18n_translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ def t(key, options = {})
i18_content = I18nContent.find_by(key: key)
translation = I18nContentTranslation.find_by(i18n_content_id: i18_content&.id,
locale: current_locale)&.value
translation.presence || translate(key, options)
if translation.present?
if options.present?
translation % options
else
translation
end
else
translate(key, options)
end
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions spec/features/site_customization/information_texts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,26 @@
expect(page).not_to have_content "Help about proposals"
end
end

scenario "Show custom text with options", :js do
admin = create(:administrator)
user = create(:user, username: "Rachel")
create(:budget_investment, author_id: user.id)

intro_key = "mailers.budget_investment_created.intro"
create(:i18n_content, key: intro_key, value_en: "Hi %{author}")

login_as(admin.user)
visit admin_site_customization_information_texts_path(tab: "mailers")

expect(page).to have_content "Hi %{author}"

fill_in "contents[content_#{intro_key}]values[value_en]", with: "Custom hi to %{author}"
click_button "Save"

visit admin_system_email_view_path("budget_investment_created")

expect(page).to have_content "Custom hi to Rachel"
expect(page).not_to have_content "%{author}"
end
end

0 comments on commit ff64afe

Please sign in to comment.