Sha256: 24846456e0e9558819d5233feb501f81bf98a46ac8cf680f89c8026679484292

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

# Service to determine which language to use for sorting and filtering.
module Qa
  module LinkedData
    class LanguageService
      class << self
        def preferred_language(user_language: nil, authority_language: nil)
          return normalize_language(user_language) if user_language.present?
          return normalize_language(authority_language) if authority_language.present?
          normalize_language(Qa.config.default_language)
        end

        def literal_has_language_marker?(literal)
          return false unless literal.respond_to?(:language)
          literal.language.present?
        end

        private

          # Normalize language
          # @param [String | Symbol | Array] language for filtering graph (e.g. "en" OR :en OR ["en", "fr"] OR [:en, :fr])
          # @return [Array<Symbol>] an array of languages encoded as symbols (e.g. [:en] OR [:en, :fr])
          def normalize_language(language)
            return language if language.blank?
            language = [language] unless language.is_a? Array
            language.map(&:to_sym)
          end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
qa-4.0.0 app/services/qa/linked_data/language_service.rb
qa-4.0.0.rc3 app/services/qa/linked_data/language_service.rb
qa-4.0.0.rc2 app/services/qa/linked_data/language_service.rb
qa-4.0.0.rc1 app/services/qa/linked_data/language_service.rb