Class: Alchemy::Language

Inherits:
BaseRecord
  • Object
show all
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

Instance Method Summary collapse

Methods included from Code

#code, #code=

Methods included from SearchableResource

#ransackable_associations, #ransackable_attributes, #ransortable_attributes

Class Method Details

.currentObject

Deprecated.

Use Current#language instead.

Current language from current thread or default.



83
84
85
# File 'app/models/alchemy/language.rb', line 83

def current
  Current.language
end

.current=(language) ⇒ Object

Deprecated.

Use Current#language= instead.

Store the current language in the current thread.



76
77
78
# File 'app/models/alchemy/language.rb', line 76

def current=(language)
  Current.language = language
end

.current_root_pageObject

The root page of the current language.



89
90
91
# File 'app/models/alchemy/language.rb', line 89

def current_root_page
  Current.language&.pages&.language_roots&.first
end

.defaultObject

Default language for current site



94
95
96
# File 'app/models/alchemy/language.rb', line 94

def default
  on_current_site.find_by(default: true)
end

.on_current_siteObject



70
71
72
# File 'app/models/alchemy/language.rb', line 70

def on_current_site
  on_site(Current.site)
end

.on_site(site) ⇒ Object



66
67
68
# File 'app/models/alchemy/language.rb', line 66

def on_site(site)
  site ? where(site_id: site.id) : all
end

Instance Method Details

#available_menu_namesObject



121
122
123
# File 'app/models/alchemy/language.rb', line 121

def available_menu_names
  Alchemy::Node.available_menu_names - nodes.reject(&:parent_id).map(&:menu_type)
end

#label(attrib) ⇒ Object



99
100
101
102
103
104
105
# File 'app/models/alchemy/language.rb', line 99

def label(attrib)
  if attrib.to_sym == :code
    code
  else
    Alchemy.t(code, default: name)
  end
end

#matching_localesArray

All available locales matching this language

Matching either the code (language_code + country_code) or the language_code

Returns:

  • (Array)


115
116
117
118
119
# File 'app/models/alchemy/language.rb', line 115

def matching_locales
  @_matching_locales ||= ::I18n.available_locales.select do |locale|
    locale.to_s.split("-")[0] == language_code
  end
end