Class: Alchemy::Language
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- Alchemy::Language
- 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
-
.current_root_page ⇒ Object
The root page of the current language.
-
.default ⇒ Object
Default language for current site.
- .on_current_site ⇒ Object
- .on_site(site) ⇒ Object
Instance Method Summary collapse
- #available_menu_names ⇒ Object
- #label(attrib) ⇒ Object
-
#matching_locales ⇒ Array
All available locales matching this language.
Methods included from Code
Methods included from ConfigMissing
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.
70 71 72 |
# File 'app/models/alchemy/language.rb', line 70 def current_root_page Current.language&.pages&.language_roots&.first end |
.default ⇒ Object
Default language for current site
75 76 77 |
# File 'app/models/alchemy/language.rb', line 75 def default on_current_site.find_by(default: true) end |
.on_current_site ⇒ Object
65 66 67 |
# File 'app/models/alchemy/language.rb', line 65 def on_current_site on_site(Current.site) end |
.on_site(site) ⇒ Object
61 62 63 |
# File 'app/models/alchemy/language.rb', line 61 def on_site(site) site ? where(site_id: site.id) : all end |
Instance Method Details
#available_menu_names ⇒ Object
102 103 104 |
# File 'app/models/alchemy/language.rb', line 102 def Alchemy::Node. - nodes.reject(&:parent_id).map(&:menu_type) end |
#label(attrib) ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/models/alchemy/language.rb', line 80 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
96 97 98 99 100 |
# File 'app/models/alchemy/language.rb', line 96 def matching_locales @_matching_locales ||= ::I18n.available_locales.select do |locale| locale.to_s.split("-")[0] == language_code end end |