Class: Alchemy::Language
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- 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=(v) ⇒ 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
Class Method Details
.current ⇒ Object
Current language from current thread or default.
67 68 69 |
# File 'app/models/alchemy/language.rb', line 67 def current RequestStore.store[:alchemy_current_language] || default end |
.current=(v) ⇒ Object
Store the current language in the current thread.
62 63 64 |
# File 'app/models/alchemy/language.rb', line 62 def current=(v) RequestStore.store[:alchemy_current_language] = v end |
.current_root_page ⇒ Object
The root page of the current language.
72 73 74 |
# File 'app/models/alchemy/language.rb', line 72 def current_root_page current.pages.language_roots.first end |
.default ⇒ Object
Default language for current site
77 78 79 |
# File 'app/models/alchemy/language.rb', line 77 def default on_current_site.find_by(default: true) end |
Instance Method Details
#label(attrib) ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/models/alchemy/language.rb', line 82 def label(attrib) if attrib.to_sym == :code code else Alchemy.t(code, default: name) end end |
#layout_root_page ⇒ Object
Layout root page
98 99 100 |
# File 'app/models/alchemy/language.rb', line 98 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
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 |
#root_page ⇒ Object
Root page
93 94 95 |
# File 'app/models/alchemy/language.rb', line 93 def root_page @root_page ||= pages.language_roots.first end |