Class: Qa::LinkedData::LanguageService

Inherits:
Object
  • Object
show all
Defined in:
app/services/qa/linked_data/language_service.rb

Constant Summary collapse

WILDCARD =
'*'.freeze

Class Method Summary collapse

Class Method Details

.literal_has_language_marker?(literal) ⇒ Boolean

Returns true if literal has a language tag; otherwise, false.

Parameters:

  • the (RDF::Literal)

    literal to check

Returns:

  • (Boolean)

    true if literal has a language tag; otherwise, false



23
24
25
26
# File 'app/services/qa/linked_data/language_service.rb', line 23

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

.preferred_language(user_language: nil, authority_language: nil) ⇒ Array<Symbol>

Note:

Precedence from high to low:

  • user_language (with URL parameter preferred over URL header)

  • authority_language (defined in authority config)

  • site default_language (defined in QA initializer)

Returns the selected language(s) normalized as an array of symbols (e.g. [:en, :fr]).

Parameters:

  • user_langauge (Symbol|String)

    the language code (e.g. :en, :fr) specified as URL parameter or on URL header

  • authority_language (Symbol|String|Array<Symbol|String>) (defaults to: nil)

    the default language specified in the authority’s configuration file

Returns:

  • (Array<Symbol>)

    the selected language(s) normalized as an array of symbols (e.g. [:en, :fr])



15
16
17
18
19
# File 'app/services/qa/linked_data/language_service.rb', line 15

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