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
- #label(attrib) ⇒ Object
-
#layout_root_page ⇒ Object
Layout root page.
-
#matching_locales ⇒ Array
All available locales matching this language.
-
#root_page ⇒ Object
Root page.
Methods included from Code
Methods inherited from BaseRecord
Class Method Details
.current ⇒ Object
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_page ⇒ Object
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 |
.default ⇒ Object
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_site ⇒ Object
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_page ⇒ Object
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_locales ⇒ Array
All available locales matching this language
Matching either the code (language_code
+ country_code
) or the language_code
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_page ⇒ Object
Root page
104 105 106 |
# File 'app/models/alchemy/language.rb', line 104 def root_page @root_page ||= pages.language_roots.first end |