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-3.0.3 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.2 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.1 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.rc6 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.rc5 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.rc4 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.rc3 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.rc2 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.rc1 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.10 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.9 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.8 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.7 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.6 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.5 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.4 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.3 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.2 app/helpers/spotlight/languages_helper.rb
blacklight-spotlight-3.0.0.alpha.1 app/helpers/spotlight/languages_helper.rb