Sha256: 9c0a7c0f40ddfccfc5c75e937fa77e70308d1cde18323f8b825fa6bb45856050

Contents?: true

Size: 1.26 KB

Versions: 76

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

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

76 entries across 76 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.3.5 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.3.4 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.3.3 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.3.2 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.3.1 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.3.0 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.2.0 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.1.2 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.1.1 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.1.0 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.0.3 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.0.2 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.0.1 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-4.0.0 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.6.0.beta10 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.6.0.beta9 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.6.0.beta8 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.5.0.4 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.6.0.beta7 app/helpers/spotlight/languages_helper.rb