Class: Alchemy::Language

Inherits:
BaseRecord
  • 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=

Methods inherited from BaseRecord

#active_record_5_1?

Class Method Details

.currentObject

Current language from current thread or default.



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

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

.current=(language) ⇒ Object

Store the current language in the current thread.



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

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

.current_root_pageObject

The root page of the current language.



83
84
85
# File 'app/models/alchemy/language.rb', line 83

def current_root_page
  current.pages.language_roots.first
end

.defaultObject

Default language for current site



88
89
90
# File 'app/models/alchemy/language.rb', line 88

def default
  on_current_site.find_by(default: true)
end

.on_current_siteObject



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

def on_current_site
  on_site(Site.current)
end

.on_site(site) ⇒ Object



64
65
66
# File 'app/models/alchemy/language.rb', line 64

def on_site(site)
  site ? where(site_id: site.id) : all
end

Instance Method Details

#label(attrib) ⇒ Object



93
94
95
96
97
98
99
# File 'app/models/alchemy/language.rb', line 93

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

#layout_root_pageObject

Layout root page



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

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)


119
120
121
122
123
# File 'app/models/alchemy/language.rb', line 119

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

#root_pageObject

Root page



104
105
106
# File 'app/models/alchemy/language.rb', line 104

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