Module: Kalimba::LocalizedAttributes

Extended by:
ActiveSupport::Concern
Included in:
Resource
Defined in:
lib/kalimba/localized_attributes.rb

Overview

This module handles localized literals of RDF such that:

1. they are presented as normal "single" attributes,
2. storing the attribute in the same language overwrites
   only the attribute value in that language and does not
   delete this attribute values in other languages,

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#retrieve_localizable_property(name, predicate) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/kalimba/localized_attributes.rb', line 18

def retrieve_localizable_property(name, predicate)
  localized_names = send "localized_#{name.pluralize}"
  Kalimba.repository.statements.each(:subject => subject, :predicate => predicate) do |statement|
    value = statement.object.value
    lang = value.respond_to?(:lang) ? value.lang : nil
    localized_names[lang] = value
  end
  localized_names[I18n.locale] || localized_names[nil]
end

#store_localizable_property(name, value, predicate, datatype) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/kalimba/localized_attributes.rb', line 28

def store_localizable_property(name, value, predicate, datatype)
  localized_names = send "localized_#{name.pluralize}"
  lang = value.respond_to?(:lang) ? value.lang : nil
  localized_names.merge!(lang => value).all? do |_, v|
    store_single_value(v, predicate, datatype)
  end
end