Sha256: d9c80d7dcd2b5cc7e1661a0ccd9d91770cbde6eb34fd4d0fabdd15489a09efaf

Contents?: true

Size: 1.22 KB

Versions: 11

Compression:

Stored size: 1.22 KB

Contents

module Spotlight
  ##
  # Helpers for the Language form and UI elements
  module LanguagesHelper
    def add_exhibit_language_dropdown_options
      non_default_or_current_exhibit_languages = I18n.available_locales.reject do |locale|
        locale == I18n.default_locale || current_exhibit.available_locales.include?(locale.to_s)
      end

      non_default_or_current_exhibit_languages_with_labels = non_default_or_current_exhibit_languages.map do |locale|
        [t("locales.#{locale}"), locale]
      end

      non_default_or_current_exhibit_languages_with_labels.sort_by { |label, _locale| label }
    end

    def locale_selecter_dropown_options
      languages = current_exhibit.languages.accessible_by(current_ability).to_a << Spotlight::Language.default_instance

      # String#casecmp returns 0 when the two strings compared are identical (ignoring case)
      languages.reject { |language| language.locale.to_s.casecmp(I18n.locale.to_s).zero? }.sort_by(&:to_native)
    end

    ##
    # Can determine whether the current page is using the application's default
    # locale
    # @return [Boolean]
    def default_language?
      return true unless params[:locale]
      params[:locale].to_s == I18n.default_locale.to_s
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
blacklight-spotlight-2.2.1 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.2.0 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.1.0 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.0.2 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.0.1 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.0.0 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.0.0.rc6 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.0.0.rc5 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.0.0.rc4 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.0.0.rc3 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-2.0.0.rc2 app/helpers/spotlight/languages_helper.rb