Skip to content

Commit

Permalink
Provide a default application_name
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne authored and carolyncole committed Mar 29, 2018
1 parent 68affcf commit 5216223
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 14 deletions.
8 changes: 7 additions & 1 deletion app/helpers/blacklight/blacklight_helper_behavior.rb
Expand Up @@ -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

##
Expand Down
2 changes: 0 additions & 2 deletions config/locales/blacklight.de.yml
Expand Up @@ -12,8 +12,6 @@ de:
next: 'Nächste »'

blacklight:
application_name: 'Blacklight'

header_links:
login: 'Anmelden'
logout: 'Ausloggen'
Expand Down
1 change: 0 additions & 1 deletion config/locales/blacklight.en.yml
Expand Up @@ -13,7 +13,6 @@ en:

blacklight:
application_name: 'Blacklight'

header_links:
login: 'Login'
logout: 'Log Out'
Expand Down
2 changes: 0 additions & 2 deletions config/locales/blacklight.es.yml
Expand Up @@ -12,8 +12,6 @@ es:
next: 'Siguiente »'

blacklight:
application_name: 'Blacklight'

header_links:
login: 'Entrar'
logout: 'Salir'
Expand Down
2 changes: 0 additions & 2 deletions config/locales/blacklight.fr.yml
Expand Up @@ -12,8 +12,6 @@ fr:
next: 'Suivante »'

blacklight:
application_name: 'Blacklight'

header_links:
login: 'Mon compte'
logout: 'Me déconnecter'
Expand Down
2 changes: 0 additions & 2 deletions config/locales/blacklight.it.yml
Expand Up @@ -12,8 +12,6 @@ it:
next: 'Pagina successiva »'

blacklight:
application_name: 'Blacklight'

header_links:
login: 'Login'
logout: 'Log out'
Expand Down
2 changes: 0 additions & 2 deletions config/locales/blacklight.pt-BR.yml
Expand Up @@ -12,8 +12,6 @@ pt-BR:
next: 'próx »'

blacklight:
application_name: 'Blacklight'

header_links:
login: 'Acessar'
logout: 'Sair'
Expand Down
2 changes: 0 additions & 2 deletions config/locales/blacklight.sq.yml
Expand Up @@ -12,8 +12,6 @@ sq:
next: 'Tjetra »'

blacklight:
application_name: 'Blacklight'

header_links:
login: 'Hyr'
logout: 'Dil'
Expand Down
28 changes: 28 additions & 0 deletions spec/helpers/blacklight_helper_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 5216223

Please sign in to comment.