Module: Blacklight::LocalePicker::LocaleHelper
- Defined in:
- app/helpers/blacklight/locale_picker/locale_helper.rb
Overview
Helpers for building the locale picker
Instance Method Summary collapse
-
#additional_locale_routing_scopes ⇒ Object
Returns an array of routing scopes (e.g. mounted engines) to attempt to use for switching locale-specific routes.
-
#available_locales ⇒ Object
Locales to display in the locale picker; by default, it picks up the information from the engine configuration.
-
#current_page_for_locale(locale) ⇒ Object
Returns the url for the current page in the new locale.
Instance Method Details
#additional_locale_routing_scopes ⇒ Object
Returns an array of routing scopes (e.g. mounted engines) to attempt to use for switching locale-specific routes. This is likely overridden in complex applications to add scopes for additional mounted engines
27 28 29 |
# File 'app/helpers/blacklight/locale_picker/locale_helper.rb', line 27 def additional_locale_routing_scopes [blacklight] end |
#available_locales ⇒ Object
Locales to display in the locale picker; by default, it picks up the information from the engine configuration
5 6 7 |
# File 'app/helpers/blacklight/locale_picker/locale_helper.rb', line 5 def available_locales Blacklight::LocalePicker::Engine.config.available_locales end |
#current_page_for_locale(locale) ⇒ Object
Returns the url for the current page in the new locale. This may be overridden in downstream applications where our naive use of ‘url_for` is insufficient to generate the expected routes
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/blacklight/locale_picker/locale_helper.rb', line 12 def current_page_for_locale(locale) initial_exception = nil ([self] + additional_locale_routing_scopes).each do |scope| return scope.public_send(:url_for, locale: locale) rescue ActionController::UrlGenerationError => e initial_exception ||= e end raise initial_exception end |