From 5216223407fe7c614e66c380ff8985de8754bd52 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Thu, 6 Jul 2017 14:24:00 -0500 Subject: [PATCH] Provide a default application_name --- .../blacklight/blacklight_helper_behavior.rb | 8 +++++- config/locales/blacklight.de.yml | 2 -- config/locales/blacklight.en.yml | 1 - config/locales/blacklight.es.yml | 2 -- config/locales/blacklight.fr.yml | 2 -- config/locales/blacklight.it.yml | 2 -- config/locales/blacklight.pt-BR.yml | 2 -- config/locales/blacklight.sq.yml | 2 -- spec/helpers/blacklight_helper_spec.rb | 28 +++++++++++++++++++ 9 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app/helpers/blacklight/blacklight_helper_behavior.rb b/app/helpers/blacklight/blacklight_helper_behavior.rb index ff735fa1a8..e633b19a60 100644 --- a/app/helpers/blacklight/blacklight_helper_behavior.rb +++ b/app/helpers/blacklight/blacklight_helper_behavior.rb @@ -9,10 +9,16 @@ module Blacklight::BlacklightHelperBehavior ## # Get the name of this application from an i18n string # key: blacklight.application_name + # Try first in the current locale, then the default locale # # @return [String] the application name def application_name - t('blacklight.application_name') + # It's important that we don't use ActionView::Helpers::CacheHelper#cache here + # because it returns nil. + Rails.cache.fetch 'blacklight/application_name' do + t('blacklight.application_name', + default: t('blacklight.application_name', locale: I18n.default_locale)) + end end ## diff --git a/config/locales/blacklight.de.yml b/config/locales/blacklight.de.yml index a2571636db..a7e191f1b2 100644 --- a/config/locales/blacklight.de.yml +++ b/config/locales/blacklight.de.yml @@ -12,8 +12,6 @@ de: next: 'Nächste »' blacklight: - application_name: 'Blacklight' - header_links: login: 'Anmelden' logout: 'Ausloggen' diff --git a/config/locales/blacklight.en.yml b/config/locales/blacklight.en.yml index d81bea750f..515413abbf 100644 --- a/config/locales/blacklight.en.yml +++ b/config/locales/blacklight.en.yml @@ -13,7 +13,6 @@ en: blacklight: application_name: 'Blacklight' - header_links: login: 'Login' logout: 'Log Out' diff --git a/config/locales/blacklight.es.yml b/config/locales/blacklight.es.yml index 99d5e9891c..e1f1bbf12b 100644 --- a/config/locales/blacklight.es.yml +++ b/config/locales/blacklight.es.yml @@ -12,8 +12,6 @@ es: next: 'Siguiente »' blacklight: - application_name: 'Blacklight' - header_links: login: 'Entrar' logout: 'Salir' diff --git a/config/locales/blacklight.fr.yml b/config/locales/blacklight.fr.yml index d70af87304..1a3335aa8f 100755 --- a/config/locales/blacklight.fr.yml +++ b/config/locales/blacklight.fr.yml @@ -12,8 +12,6 @@ fr: next: 'Suivante »' blacklight: - application_name: 'Blacklight' - header_links: login: 'Mon compte' logout: 'Me déconnecter' diff --git a/config/locales/blacklight.it.yml b/config/locales/blacklight.it.yml index 4b5764a3e3..3e9b872916 100644 --- a/config/locales/blacklight.it.yml +++ b/config/locales/blacklight.it.yml @@ -12,8 +12,6 @@ it: next: 'Pagina successiva »' blacklight: - application_name: 'Blacklight' - header_links: login: 'Login' logout: 'Log out' diff --git a/config/locales/blacklight.pt-BR.yml b/config/locales/blacklight.pt-BR.yml index 12108fa4c2..5255703300 100644 --- a/config/locales/blacklight.pt-BR.yml +++ b/config/locales/blacklight.pt-BR.yml @@ -12,8 +12,6 @@ pt-BR: next: 'próx »' blacklight: - application_name: 'Blacklight' - header_links: login: 'Acessar' logout: 'Sair' diff --git a/config/locales/blacklight.sq.yml b/config/locales/blacklight.sq.yml index 7bd3a29cf7..5a2e77ead4 100644 --- a/config/locales/blacklight.sq.yml +++ b/config/locales/blacklight.sq.yml @@ -12,8 +12,6 @@ sq: next: 'Tjetra »' blacklight: - application_name: 'Blacklight' - header_links: login: 'Hyr' logout: 'Dil' diff --git a/spec/helpers/blacklight_helper_spec.rb b/spec/helpers/blacklight_helper_spec.rb index db21aa784d..c7810db251 100644 --- a/spec/helpers/blacklight_helper_spec.rb +++ b/spec/helpers/blacklight_helper_spec.rb @@ -8,9 +8,37 @@ end describe "#application_name" do + before do + allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::NullStore.new) + end it "defaults to 'Blacklight'" do expect(application_name).to eq "Blacklight" end + + context "when the language is not english " do + around do |example| + I18n.locale = :de + example.run + I18n.locale = :en + end + + context "and no translation exists for that language" do + it "defaults to 'Blacklight'" do + expect(application_name).to eq "Blacklight" + end + end + + context "and a translation exists for that language" do + around do |example| + I18n.backend.store_translations(:de, 'blacklight' => { 'application_name' => 'Schwarzlicht' } ) + example.run + I18n.backend.reload! + end + it "uses the provided value" do + expect(application_name).to eq "Schwarzlicht" + end + end + end end describe "#render_page_title" do