Class: Alchemy::Language

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Code
Defined in:
app/models/alchemy/language.rb

Defined Under Namespace

Modules: Code

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Code

#code, #code=

Class Method Details

.currentObject

Current language from current thread or default.



67
68
69
# File 'app/models/alchemy/language.rb', line 67

def current
  RequestStore.store[:alchemy_current_language] || default
end

.current=(v) ⇒ Object

Store the current language in the current thread.



62
63
64
# File 'app/models/alchemy/language.rb', line 62

def current=(v)
  RequestStore.store[:alchemy_current_language] = v
end

.current_root_pageObject

The root page of the current language.



72
73
74
# File 'app/models/alchemy/language.rb', line 72

def current_root_page
  current.pages.language_roots.first
end

.defaultObject

Default language for current site



77
78
79
# File 'app/models/alchemy/language.rb', line 77

def default
  on_current_site.find_by(default: true)
end

Instance Method Details

#label(attrib) ⇒ Object



82
83
84
85
86
87
88
# File 'app/models/alchemy/language.rb', line 82

def label(attrib)
  if attrib.to_sym == :code
    code
  else
    Alchemy.t(code, default: name)
  end
end

#layout_root_pageObject

Layout root page



98
99
100
# File 'app/models/alchemy/language.rb', line 98

def layout_root_page
  @layout_root_page ||= Page.layout_root_for(id)
end

#matching_localesArray

All available locales matching this language

Matching either the code (language_code + country_code) or the language_code

Returns:

  • (Array)


108
109
110
111
112
# File 'app/models/alchemy/language.rb', line 108

def matching_locales
  @_matching_locales ||= ::I18n.available_locales.select do |locale|
    locale.to_s.split('-')[0] == language_code
  end
end

#root_pageObject

Root page



93
94
95
# File 'app/models/alchemy/language.rb', line 93

def root_page
  @root_page ||= pages.language_roots.first
end