class Jekyll::LocalizeTag

class LocalizeTag

Localization by getting localized text from YAML files. User must use the “t” or “translate” liquid tags.

Public Class Methods

new(tag_name, key, tokens) click to toggle source
initialize
Calls superclass method
# File lib/jekyll-multiple-languages-plugin.rb, line 337
def initialize(tag_name, key, tokens)
  super
  @key = key.strip
end

Public Instance Methods

render(context) click to toggle source
render
# File lib/jekyll-multiple-languages-plugin.rb, line 347
def render(context)
  if      "#{context[@key]}" != "" # Check for page variable
    key = "#{context[@key]}"
  else
    key =            @key
  end
  
  key = Liquid::Template.parse(key).render(context)  # Parses and renders some Liquid syntax on arguments (allows expansions)
  
  site = context.registers[:site] # Jekyll site object
  
  lang = site.config['lang']
  
  translation = site.parsed_translations[lang].access(key) if key.is_a?(String)
  
  if translation.nil? or translation.empty?
     translation = site.parsed_translations[site.config['default_lang']].access(key)
    
    if site.config["verbose"]
      puts "Missing i18n key: #{lang}:#{key}"
      puts "Using translation '%s' from default language: %s" %[translation, site.config['default_lang']]
    end
  end
  
  translation
end