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
Class Method Summary collapse
-
.current ⇒ Object
Current language from current thread or default.
-
.current=(language) ⇒ Object
Store the current language in the current thread.
-
.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
Class Method Details
.current ⇒ Object
Current language from current thread or default.
83 84 85 |
# File 'app/models/alchemy/language.rb', line 83 def current RequestStore.store[:alchemy_current_language] || default end |
.current=(language) ⇒ Object
Store the current language in the current thread.
78 79 80 |
# File 'app/models/alchemy/language.rb', line 78 def current=(language) RequestStore.store[:alchemy_current_language] = language end |
.current_root_page ⇒ Object
The root page of the current language.
88 89 90 91 92 |
# File 'app/models/alchemy/language.rb', line 88 def current_root_page return unless current current.pages.language_roots.first end |
.default ⇒ Object
Default language for current site
95 96 97 |
# File 'app/models/alchemy/language.rb', line 95 def default on_current_site.find_by(default: true) end |
.on_current_site ⇒ Object
73 74 75 |
# File 'app/models/alchemy/language.rb', line 73 def on_current_site on_site(Site.current) end |
.on_site(site) ⇒ Object
69 70 71 |
# File 'app/models/alchemy/language.rb', line 69 def on_site(site) site ? where(site_id: site.id) : all end |
Instance Method Details
#available_menu_names ⇒ Object
122 123 124 |
# File 'app/models/alchemy/language.rb', line 122 def Alchemy::Node. - nodes.reject(&:parent_id).map(&:menu_type) end |
#label(attrib) ⇒ Object
100 101 102 103 104 105 106 |
# File 'app/models/alchemy/language.rb', line 100 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
116 117 118 119 120 |
# File 'app/models/alchemy/language.rb', line 116 def matching_locales @_matching_locales ||= ::I18n.available_locales.select do |locale| locale.to_s.split("-")[0] == language_code end end |