Class: Alchemy::Language

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

Defined Under Namespace

Modules: Code

Constant Summary

Constants included from SearchableResource

SearchableResource::SEARCHABLE_COLUMN_TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Code

#code, #code=

Methods included from ConfigMissing

#const_missing

Methods included from SearchableResource

#ransackable_associations, #ransackable_attributes, #ransackable_scopes, #ransortable_attributes

Class Method Details

.current_root_page ⇒ Object

The root page of the current language.



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

def current_root_page
  Current.language&.pages&.language_roots&.first
end

.default ⇒ Object

Default language for current site



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

def default
  on_current_site.find_by(default: true)
end

.on_current_site ⇒ Object



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

def on_current_site
  on_site(Current.site)
end

.on_site(site) ⇒ Object



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

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

Instance Method Details

#available_menu_names ⇒ Object



114
115
116
# File 'app/models/alchemy/language.rb', line 114

def available_menu_names
  Alchemy::Node.available_menu_names - nodes.reject(&:parent_id).map(&:menu_type)
end

#label(attrib) ⇒ Object



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

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

#matching_locales ⇒ Array

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