Sha256: 8b7a98dc0d04a5cd4cf28f2381940ad4e431aad50672e0244eed69bab84afaa3

Contents?: true

Size: 1013 Bytes

Versions: 2

Compression:

Stored size: 1013 Bytes

Contents

# Frozen-string-literal: true
# Encoding: utf-8

module Jekyll
  module LanguagePlugin
    module Tags
      class NativeLanguageNameTag < Liquid::Tag
        def initialize(tag_name, markup, tokens)
          super
          @markup = markup
        end

        def render(context)
          p = Liquid::Parser.new(@markup)
          name = Liquid::Expression.parse(exp = p.expression)
          key = context.evaluate(name)
          raise Liquid::SyntaxError.new("Invalid language key expression: #{exp}") if key.nil?

          # get language name string from evaluated key
          oldLanguage = context.registers[:page]['language']
          context.registers[:page]['language'] = key
          translation = Jekyll::LanguagePlugin::LiquidContext.get_language_string(context, "lang.#{key}")
          context.registers[:page]['language'] = oldLanguage
          translation
        end
      end
    end
  end
end

Liquid::Template.register_tag('tln', Jekyll::LanguagePlugin::Tags::NativeLanguageNameTag)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-language-plugin-1.3.5 lib/jekyll/language-plugin/tags/language_name_native.rb
jekyll-language-plugin-1.3.4 lib/jekyll/language-plugin/tags/language_name_native.rb