Class: Lolita::Translation::Locales

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/lolita-translation/locales.rb

Instance Method Summary collapse

Constructor Details

#initialize(locale_names) ⇒ Locales

Returns a new instance of Locales.



9
10
11
# File 'lib/lolita-translation/locales.rb', line 9

def initialize(locale_names)
  @locale_names = locale_names
end

Instance Method Details

#activeObject



41
42
43
# File 'lib/lolita-translation/locales.rb', line 41

def active
  self.detect{|locale| locale.active?}
end

#by_resource_locale(resource) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lolita-translation/locales.rb', line 20

def by_resource_locale(resource)
  r_locale = resource_locale(resource)
  self.inject([]) do |result, locale|
    if r_locale.to_s == locale.name.to_s
      result.unshift(locale)
    else
      result.push(locale)
    end
    result
  end
end

#eachObject



13
14
15
16
17
18
# File 'lib/lolita-translation/locales.rb', line 13

def each
  populate_locales!
  @locales.each do |locale|
    yield locale
  end
end

#locale_namesObject



32
33
34
35
36
37
38
39
# File 'lib/lolita-translation/locales.rb', line 32

def locale_names
  l_names = if @locale_names.respond_to?(:call)
    @locale_names.call
  else
    @locale_names
  end
  l_names.sort
end