Class: Jekyll::LocalizeTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::LocalizeTag
- Includes:
- FastGettext::Translation
- Defined in:
- lib/jekyll/gettext/plugin.rb
Instance Method Summary collapse
- #add_localization_to_dependency(site, language, path) ⇒ Object
-
#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.
182 183 184 185 |
# File 'lib/jekyll/gettext/plugin.rb', line 182 def initialize(tag_name, key, tokens) super @key = key.strip end |
Instance Method Details
#add_localization_to_dependency(site, language, path) ⇒ Object
207 208 209 210 211 212 213 |
# File 'lib/jekyll/gettext/plugin.rb', line 207 def add_localization_to_dependency(site, language, path) po_file = site.pot_localization_plugin.po_file(language) site.regenerator.add_dependency( site.in_source_dir(path), po_file ) end |
#render(context) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/jekyll/gettext/plugin.rb', line 187 def render(context) site = context.registers[:site] page = context.registers[:page] language = page["language"] if language.nil? default_language = page["default_language"].to_s raise ("Missing language! Either put 'language: " + default_language + "' or 'translate: true' into the header") end add_localization_to_dependency(site, language, page["path"]) if page.key?("path") FastGettext.locale = language candidate = _(@key) if candidate == "" candidate = @key end candidate end |