Module: Jekyll::Language

Defined in:
lib/fenton-jekyll-plugin/jb_liquid_language.rb

Constant Summary collapse

@@lang =
nil

Instance Method Summary collapse

Instance Method Details

#t(section, item) ⇒ Object

Supplies translated text

Usage: ‘author’ | t: ‘recent_articles’ }


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fenton-jekyll-plugin/jb_liquid_language.rb', line 11

def t(section, item)
  site = @context.registers[:site]

  if site.data['language'] == nil
    Jekyll.logger.warn 'Liquid Language:', 'No _data/language file found. ' + 
      site.data.keys.join(', ')
  end

  if @@lang == nil
    # Access this fewer times by keeping it as a module variable
    @@lang = Jekyll.configuration({})['language']
  end
  
  # Find text in the site language (for example 'fr-be')
  text = site.data['language'][section][item][@@lang]

  # Fall back to a more general version of the language (for example 'fr')
  if text == nil and @@lang.include? '-'
    fallback_lang = @@lang.split('-')[0];
    text = site.data['language'][section][item][fallback_lang]
  end

  if text == nil
    # Fallback to English text
    text = site.data['language'][section][item]['en']
  end

  return text
end