Module: Wakari::Proxy::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/wakari/models/proxy/model.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#available_langsObject



56
57
58
# File 'lib/wakari/models/proxy/model.rb', line 56

def available_langs
  possible_langs - used_langs
end

#current_translationObject



80
81
82
# File 'lib/wakari/models/proxy/model.rb', line 80

def current_translation
   translation?(current_locale)||translations.first
end

#default_translationObject



60
61
62
# File 'lib/wakari/models/proxy/model.rb', line 60

def default_translation
  translations.min_by {|t| t.position}
end

#detect_current_translationObject



84
85
86
# File 'lib/wakari/models/proxy/model.rb', line 84

def detect_current_translation
  detect_translation(current_locale)
end

#detect_translation(locale) ⇒ Object



76
77
78
# File 'lib/wakari/models/proxy/model.rb', line 76

def detect_translation(locale)
  find_or_build_translation(:locale => locale)
end

#possible_langsObject



48
49
50
# File 'lib/wakari/models/proxy/model.rb', line 48

def possible_langs
  translations.klass._locales
end

#to_s(locale = nil) ⇒ Object



88
89
90
# File 'lib/wakari/models/proxy/model.rb', line 88

def to_s(locale = nil)
  (locale ? translation?(locale) : current_translation).try(:to_s)
end

#translation(locale) ⇒ Object



64
65
66
# File 'lib/wakari/models/proxy/model.rb', line 64

def translation(locale)
  find_translation(:locale => locale)
end

#translation?(locale) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/wakari/models/proxy/model.rb', line 68

def translation?(locale)
  begin
    translation(locale)
  rescue TranslationNotFound
    nil
  end
end

#translations_attributesObject



40
41
42
43
44
45
46
# File 'lib/wakari/models/proxy/model.rb', line 40

def translations_attributes
  Hash[translations.map do |t|
         if (lang = t.lang) && (attributes = t.meta_attributes).present?
           [lang.to_method, attributes]
         end
       end.compact]
end

#used_langsObject



52
53
54
# File 'lib/wakari/models/proxy/model.rb', line 52

def used_langs
  translations.map {|t| t.lang}
end