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.
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.
70 71 72 |
# File 'app/models/alchemy/language.rb', line 70 def current RequestStore.store[:alchemy_current_language] || default end |
.current=(language) ⇒ Object
Store the current language in the current thread.
65 66 67 |
# File 'app/models/alchemy/language.rb', line 65 def current=(language) RequestStore.store[:alchemy_current_language] = language end |
.current_root_page ⇒ Object
The root page of the current language.
75 76 77 |
# File 'app/models/alchemy/language.rb', line 75 def current_root_page current.pages.language_roots.first end |
.default ⇒ Object
Default language for current site
80 81 82 |
# File 'app/models/alchemy/language.rb', line 80 def default on_current_site.find_by(default: true) end |
Instance Method Details
#label(attrib) ⇒ Object
85 86 87 88 89 90 91 |
# File 'app/models/alchemy/language.rb', line 85 def label(attrib) if attrib.to_sym == :code code else Alchemy.t(code, default: name) end end |
#layout_root_page ⇒ Object
Layout root page
101 102 103 |
# File 'app/models/alchemy/language.rb', line 101 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
111 112 113 114 115 |
# File 'app/models/alchemy/language.rb', line 111 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
96 97 98 |
# File 'app/models/alchemy/language.rb', line 96 def root_page @root_page ||= pages.language_roots.first end |