Class: Jekyll::LocalizeTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::LocalizeTag
- Defined in:
- lib/jekyll/multiple/languages/plugin.rb
Instance Method Summary collapse
-
#initialize(tag_name, key, tokens) ⇒ LocalizeTag
constructor
A new instance of LocalizeTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, key, tokens) ⇒ LocalizeTag
Returns a new instance of LocalizeTag.
57 58 59 60 |
# File 'lib/jekyll/multiple/languages/plugin.rb', line 57 def initialize(tag_name, key, tokens) super @key = key.strip end |
Instance Method Details
#render(context) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jekyll/multiple/languages/plugin.rb', line 62 def render(context) if "#{context[@key]}" != "" #Check for page variable key = "#{context[@key]}" else key = @key end lang = context.registers[:site].config['lang'] unless Jekyll.langs.has_key?(lang) puts "Loading translation from file #{context.registers[:site].source}/_i18n/#{lang}.yml" Jekyll.langs[lang] = YAML.load_file("#{context.registers[:site].source}/_i18n/#{lang}.yml") end translation = Jekyll.langs[lang].access(key) if key.is_a?(String) if translation.empty? puts "Missing i18n key: #{lang}:#{key}" "*#{lang}:#{key}*" else translation end end |