Module: Bridgetown::Localizable

Included in:
GeneratedPage, Resource::Base
Defined in:
bridgetown-core/lib/bridgetown-core/concerns/localizable.rb

Instance Method Summary collapse

Instance Method Details

#all_localesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'bridgetown-core/lib/bridgetown-core/concerns/localizable.rb', line 5

def all_locales
  result_set = case self
               when Bridgetown::Resource::Base
                 collection.resources
               when Bridgetown::GeneratedPage
                 site.generated_pages
               else
                 []
               end

  matching_resources = result_set.select do |item|
    matches_resource?(item)
  end

  matching_resources.sort_by do |item|
    site.config.available_locales.index item.data.locale
  end
end

#localeless_pathObject



32
33
34
# File 'bridgetown-core/lib/bridgetown-core/concerns/localizable.rb', line 32

def localeless_path
  relative_path.gsub(%r{\A#{data.locale}/}, "")
end

#matches_resource?(item) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'bridgetown-core/lib/bridgetown-core/concerns/localizable.rb', line 24

def matches_resource?(item)
  if item.relative_path.is_a?(String)
    item.localeless_path == localeless_path
  else
    item.relative_path.parent == relative_path.parent
  end && item.data.slug == data.slug
end