jekyll-language-plugin 1.1.4 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll-language-plugin.rb +24 -25
- data/lib/jekyll/language-plugin/date_localizer.rb +41 -0
- data/lib/jekyll/language-plugin/filters/language_date.rb +32 -0
- data/lib/jekyll/language-plugin/liquid_context.rb +62 -0
- data/lib/jekyll/language-plugin/plugin_error.rb +6 -0
- data/lib/jekyll/language-plugin/tags/language.rb +36 -0
- data/lib/jekyll/language-plugin/tags/language_include.rb +21 -0
- data/lib/jekyll/language-plugin/tags/language_name.rb +24 -0
- data/lib/jekyll/language-plugin/version.rb +5 -0
- metadata +10 -9
- data/lib/jekyll-language-plugin/date_localizer.rb +0 -39
- data/lib/jekyll-language-plugin/liquid_context.rb +0 -60
- data/lib/jekyll-language-plugin/plugin_exception.rb +0 -4
- data/lib/jekyll/filters/language_date.rb +0 -30
- data/lib/jekyll/tags/language.rb +0 -34
- data/lib/jekyll/tags/language_include.rb +0 -19
- data/lib/jekyll/tags/language_name.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76a39471fe7e6ad748b7ddf255a6c254e4cb11c4
|
4
|
+
data.tar.gz: 7a1af5612ba9cc46c054bc19344bbefdcf1b2b0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88d6e2795d11668a803166accdc6b167f290464ffd94202ccbc5bd96f7671d289b05607c051a574706205ae26e059256d60788764ec35f9cc20ba6200ed54fcb
|
7
|
+
data.tar.gz: 1e9cdec599cf6801c27446668424b9893f0250b3d924298c4f04aafadbc7e72ccd26b17747beb0bf1cb2efad13e98b04cdf7f3b2f67e2b3ba3bb799c233e8041
|
@@ -1,18 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
# internal requires for plugin
|
4
|
+
autoload :LanguageReader, 'jekyll/language_reader.rb'
|
5
|
+
autoload :LanguagePage, 'jekyll/language_page.rb'
|
6
|
+
autoload :LanguageDocument, 'jekyll/language_document.rb'
|
7
|
+
autoload :LanguagePageReader, 'jekyll/readers/language_page_reader.rb'
|
8
|
+
autoload :LanguagePostReader, 'jekyll/readers/language_post_reader.rb'
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
module LanguagePlugin
|
11
|
+
|
12
|
+
# plugin requires
|
13
|
+
autoload :PluginError, 'jekyll/language-plugin/plugin_error.rb'
|
14
|
+
autoload :LiquidContext, 'jekyll/language-plugin/liquid_context.rb'
|
15
|
+
autoload :DateLocalizer, 'jekyll/language-plugin/date_localizer.rb'
|
16
|
+
autoload :VERSION, 'jekyll/language-plugin/version'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# require liquid tags and filters
|
21
|
+
Dir[File.join(File.dirname(__FILE__), 'jekyll/language-plugin/tags/*.rb')].each{ |f| require f }
|
22
|
+
require 'jekyll/language-plugin/filters/language_date.rb'
|
16
23
|
|
17
24
|
# replace Jekyll::Reader upon page reset with Jekyll::LanguageReader extension
|
18
25
|
Jekyll::Hooks.register :site, :after_reset do |site|
|
@@ -22,17 +29,9 @@ end
|
|
22
29
|
# monkey patch URL.sanitize_url for handling of triple slashes
|
23
30
|
module Jekyll
|
24
31
|
class URL
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
.split('/').reject{ |s| s.empty? || s =~ /^\.+$/ }.join('/') \
|
29
|
-
# Always add a leading slash
|
30
|
-
.gsub(/\A([^\/])/, '/\1')
|
31
|
-
|
32
|
-
# Append a trailing slash to the URL if the unsanitized URL had one
|
33
|
-
url << "/" if in_url.end_with?("/")
|
34
|
-
|
35
|
-
url
|
32
|
+
# optimized version by Jordon Bedwell
|
33
|
+
def sanitize_url(str)
|
34
|
+
"/" + str.gsub(/\/{2,}/, "/").gsub(%r!\.+\/|\A/+!, "")
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module LanguagePlugin
|
3
|
+
module DateLocalizer
|
4
|
+
def self.localize_date(date, format, context)
|
5
|
+
translation = Jekyll::LanguagePlugin::LiquidContext.get_language_data(context, 'date')
|
6
|
+
|
7
|
+
# validate language translation
|
8
|
+
raise Jekyll::LanguagePlugin::PluginError.new('Localized date is missing translation.') if translation.nil? ||
|
9
|
+
!['abbr_daynames', 'daynames', 'abbr_monthnames', 'monthnames'].all? {|s| translation.key?(s) && translation[s].is_a?(Array) } ||
|
10
|
+
translation['abbr_daynames'].size < 7 || translation['daynames'].size < 7 ||
|
11
|
+
translation['abbr_monthnames'].size < 12 || translation['monthnames'].size < 12
|
12
|
+
|
13
|
+
#convert to extended Time class
|
14
|
+
date2 = JLPTime.at(date.to_i)
|
15
|
+
date2.strftime_translate(format, translation)
|
16
|
+
end
|
17
|
+
|
18
|
+
class JLPTime < Time
|
19
|
+
def strftime_translate(format = '%F', translation)
|
20
|
+
result = self.strftime(
|
21
|
+
#...you replaced the language dependent parts.
|
22
|
+
format.gsub(/%([aAbB])/){ |m|
|
23
|
+
case $1
|
24
|
+
when 'a'; translation['abbr_daynames'][self.wday]
|
25
|
+
when 'A'; translation['daynames'][self.wday]
|
26
|
+
when 'b'; translation['abbr_monthnames'][self.mon-1]
|
27
|
+
when 'B'; translation['monthnames'][self.mon-1]
|
28
|
+
else
|
29
|
+
raise Jekyll::LanguagePlugin::PluginError.new('Internal error.')
|
30
|
+
end
|
31
|
+
})
|
32
|
+
if defined? @@encoding_converter
|
33
|
+
@@encoding_converter.iconv(result)
|
34
|
+
else
|
35
|
+
result
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module LanguagePlugin
|
3
|
+
module Filters
|
4
|
+
module LanguageDateFilter
|
5
|
+
def tdate(input, fkey)
|
6
|
+
if ((input.is_a?(String) && !/^\d+$/.match(input).nil?) || input.is_a?(Integer)) && input.to_i > 0
|
7
|
+
date = Time.at(input.to_i)
|
8
|
+
elsif input.is_a?(String)
|
9
|
+
case input.downcase
|
10
|
+
when 'now', 'today'
|
11
|
+
date = Time.now
|
12
|
+
else
|
13
|
+
date = Time.parse(input)
|
14
|
+
end
|
15
|
+
elsif input.is_a?(Time)
|
16
|
+
date = input
|
17
|
+
else
|
18
|
+
date = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
return "" if !date.is_a?(Time)
|
22
|
+
format = LiquidContext.get_language_string(@context, fkey)
|
23
|
+
return "" if format.nil?
|
24
|
+
|
25
|
+
Jekyll::LanguagePlugin::DateLocalizer.localize_date(date, format, @context).to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Liquid::Template.register_filter(Jekyll::LanguagePlugin::Filters::LanguageDateFilter)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module LanguagePlugin
|
3
|
+
module LiquidContext
|
4
|
+
def self.get_language_data(context, keys = nil)
|
5
|
+
site = context.registers[:site]
|
6
|
+
language_data = site.config['language_data'].to_s || 'data.lang.%%'
|
7
|
+
|
8
|
+
page_language = context.registers[:page]['language']
|
9
|
+
return nil if page_language.to_s.empty?
|
10
|
+
|
11
|
+
keys2 = language_data.gsub("%%", page_language).split('.')
|
12
|
+
language_data = site.send(keys2.shift)
|
13
|
+
language_data = self.traverse_hash(language_data, keys2)
|
14
|
+
raise Jekyll::LanguagePlugin::PluginError.new('Invalid language data configuration.') if language_data.nil?
|
15
|
+
|
16
|
+
return language_data if keys.to_s.empty? # can also return nil
|
17
|
+
|
18
|
+
language_data = self.traverse_hash(language_data, keys)
|
19
|
+
raise Jekyll::LanguagePlugin::PluginError.new("Language subset #{keys.to_s} not found.") if language_data.nil?
|
20
|
+
language_data
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get_language_string(context, key)
|
24
|
+
data = self.get_language_data(context)
|
25
|
+
return "" if data.nil?
|
26
|
+
|
27
|
+
language_subset = context.registers[:page]['subset']
|
28
|
+
if (!language_subset.to_s.empty? &&
|
29
|
+
!(str = traverse_hash(traverse_hash(data, language_subset), key)).to_s.empty?) ||
|
30
|
+
!(str = traverse_hash(data, key)).to_s.empty?
|
31
|
+
return str
|
32
|
+
end
|
33
|
+
|
34
|
+
raise Jekyll::LanguagePlugin::PluginError.new("Language string #{key} not found.")
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.get_language_name(context, name)
|
38
|
+
translation = self.get_language_data(context, 'lang')
|
39
|
+
|
40
|
+
raise Jekyll::LanguagePlugin::PluginError.new('Language name not found in translation.') if translation.nil? ||
|
41
|
+
!translation.key?(name)
|
42
|
+
|
43
|
+
translation[name]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.traverse_hash(hash, keys)
|
47
|
+
return nil if hash.nil? || keys.to_s.empty?
|
48
|
+
keys = keys.split('.') if keys.is_a?(String)
|
49
|
+
|
50
|
+
for key in keys
|
51
|
+
if !hash.is_a?(Hash)
|
52
|
+
return hash
|
53
|
+
elsif !hash.key?(key)
|
54
|
+
return nil
|
55
|
+
end
|
56
|
+
hash = hash[key]
|
57
|
+
end
|
58
|
+
hash
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module LanguagePlugin
|
3
|
+
module Tags
|
4
|
+
class LanguageTag < Liquid::Tag
|
5
|
+
def initialize(tag_name, markup, tokens)
|
6
|
+
super
|
7
|
+
@markup = markup
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(context)
|
11
|
+
p = Liquid::Parser.new(@markup)
|
12
|
+
name = Liquid::Expression.parse(exp = p.expression)
|
13
|
+
key = context.evaluate(name)
|
14
|
+
raise Liquid::SyntaxError.new("Invalid language key expression: #{exp}") if key.nil?
|
15
|
+
|
16
|
+
# get language string from evaluated key
|
17
|
+
str = Jekyll::LanguagePlugin::LiquidContext.get_language_string(context, key)
|
18
|
+
|
19
|
+
if p.consume?(:colon)
|
20
|
+
loop do
|
21
|
+
arg = Liquid::Expression.parse(exp = p.expression)
|
22
|
+
argstr = context.evaluate(arg)
|
23
|
+
raise Liquid::SyntaxError.new("Invalid parameter expression: #{exp}") if argstr.nil?
|
24
|
+
raise Jekyll::LanguagePlugin::PluginError.new("Language string is lacking parameter placeholder.") unless str.include?("%%")
|
25
|
+
str.sub!("%%", argstr)
|
26
|
+
break if !p.consume?(:comma)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
str
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Liquid::Template.register_tag('t', Jekyll::LanguagePlugin::Tags::LanguageTag)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module LanguagePlugin
|
3
|
+
module Tags
|
4
|
+
class LanguageIncludeTag < Jekyll::Tags::IncludeTag
|
5
|
+
def tag_includes_dir(context)
|
6
|
+
(context.registers[:site].config['language_includes_dir'].to_s || '_i18n').freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
def page_language(context)
|
10
|
+
context.registers[:page].nil? ? "." : context.registers[:page]["language"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def resolved_includes_dir(context)
|
14
|
+
File.join(context.registers[:site].in_source_dir(@includes_dir), page_language(context))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Liquid::Template.register_tag('tinclude', Jekyll::LanguagePlugin::Tags::LanguageIncludeTag)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module LanguagePlugin
|
3
|
+
module Tags
|
4
|
+
class LanguageNameTag < Liquid::Tag
|
5
|
+
def initialize(tag_name, markup, tokens)
|
6
|
+
super
|
7
|
+
@markup = markup
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(context)
|
11
|
+
p = Liquid::Parser.new(@markup)
|
12
|
+
name = Liquid::Expression.parse(exp = p.expression)
|
13
|
+
key = context.evaluate(name)
|
14
|
+
raise Liquid::SyntaxError.new("Invalid language key expression: #{exp}") if key.nil?
|
15
|
+
|
16
|
+
# get language name string from evaluated key
|
17
|
+
Jekyll::LanguagePlugin::LiquidContext.get_language_string(context, "lang.#{key}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Liquid::Template.register_tag('tl', Jekyll::LanguagePlugin::Tags::LanguageNameTag)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-language-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Wochnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -74,18 +74,19 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- lib/jekyll-language-plugin.rb
|
77
|
-
- lib/jekyll/
|
77
|
+
- lib/jekyll/language-plugin/date_localizer.rb
|
78
|
+
- lib/jekyll/language-plugin/filters/language_date.rb
|
79
|
+
- lib/jekyll/language-plugin/liquid_context.rb
|
80
|
+
- lib/jekyll/language-plugin/plugin_error.rb
|
81
|
+
- lib/jekyll/language-plugin/tags/language.rb
|
82
|
+
- lib/jekyll/language-plugin/tags/language_include.rb
|
83
|
+
- lib/jekyll/language-plugin/tags/language_name.rb
|
84
|
+
- lib/jekyll/language-plugin/version.rb
|
78
85
|
- lib/jekyll/language_document.rb
|
79
86
|
- lib/jekyll/language_page.rb
|
80
87
|
- lib/jekyll/language_reader.rb
|
81
88
|
- lib/jekyll/readers/language_page_reader.rb
|
82
89
|
- lib/jekyll/readers/language_post_reader.rb
|
83
|
-
- lib/jekyll/tags/language.rb
|
84
|
-
- lib/jekyll/tags/language_include.rb
|
85
|
-
- lib/jekyll/tags/language_name.rb
|
86
|
-
- lib/jekyll-language-plugin/date_localizer.rb
|
87
|
-
- lib/jekyll-language-plugin/liquid_context.rb
|
88
|
-
- lib/jekyll-language-plugin/plugin_exception.rb
|
89
90
|
- README.md
|
90
91
|
- LICENSE.md
|
91
92
|
homepage: https://github.com/vwochnik/jekyll-language-plugin
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module JekyllLanguagePlugin
|
2
|
-
module DateLocalizer
|
3
|
-
def self.localize_date(date, format, context)
|
4
|
-
translation = JekyllLanguagePlugin::LiquidContext.get_language_data(context, 'date')
|
5
|
-
|
6
|
-
# validate language translation
|
7
|
-
raise JekyllLanguagePlugin::PluginError.new('Localized date is missing translation.') if translation.nil? ||
|
8
|
-
!['abbr_daynames', 'daynames', 'abbr_monthnames', 'monthnames'].all? {|s| translation.key?(s) && translation[s].is_a?(Array) } ||
|
9
|
-
translation['abbr_daynames'].size < 7 || translation['daynames'].size < 7 ||
|
10
|
-
translation['abbr_monthnames'].size < 12 || translation['monthnames'].size < 12
|
11
|
-
|
12
|
-
#convert to extended Time class
|
13
|
-
date2 = JLPTime.at(date.to_i)
|
14
|
-
date2.strftime_translate(format, translation)
|
15
|
-
end
|
16
|
-
|
17
|
-
class JLPTime < Time
|
18
|
-
def strftime_translate(format = '%F', translation)
|
19
|
-
result = self.strftime(
|
20
|
-
#...you replaced the language dependent parts.
|
21
|
-
format.gsub(/%([aAbB])/){ |m|
|
22
|
-
case $1
|
23
|
-
when 'a'; translation['abbr_daynames'][self.wday]
|
24
|
-
when 'A'; translation['daynames'][self.wday]
|
25
|
-
when 'b'; translation['abbr_monthnames'][self.mon-1]
|
26
|
-
when 'B'; translation['monthnames'][self.mon-1]
|
27
|
-
else
|
28
|
-
raise JekyllLanguagePlugin::PluginError.new('Internal error.')
|
29
|
-
end
|
30
|
-
})
|
31
|
-
if defined? @@encoding_converter
|
32
|
-
@@encoding_converter.iconv(result)
|
33
|
-
else
|
34
|
-
result
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module JekyllLanguagePlugin
|
2
|
-
module LiquidContext
|
3
|
-
def self.get_language_data(context, keys = nil)
|
4
|
-
site = context.registers[:site]
|
5
|
-
language_data = site.config['language_data'].to_s || 'data.lang.%%'
|
6
|
-
|
7
|
-
page_language = context.registers[:page]['language']
|
8
|
-
return nil if page_language.to_s.empty?
|
9
|
-
|
10
|
-
keys2 = language_data.gsub("%%", page_language).split('.')
|
11
|
-
language_data = site.send(keys2.shift)
|
12
|
-
language_data = self.traverse_hash(language_data, keys2)
|
13
|
-
raise JekyllLanguagePlugin::PluginError.new('Invalid language data configuration.') if language_data.nil?
|
14
|
-
|
15
|
-
return language_data if keys.to_s.empty? # can also return nil
|
16
|
-
|
17
|
-
language_data = self.traverse_hash(language_data, keys)
|
18
|
-
raise JekyllLanguagePlugin::PluginError.new("Language subset #{keys.to_s} not found.") if language_data.nil?
|
19
|
-
language_data
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.get_language_string(context, key)
|
23
|
-
data = self.get_language_data(context)
|
24
|
-
return "" if data.nil?
|
25
|
-
|
26
|
-
language_subset = context.registers[:page]['subset']
|
27
|
-
if (!language_subset.to_s.empty? &&
|
28
|
-
!(str = traverse_hash(traverse_hash(data, language_subset), key)).to_s.empty?) ||
|
29
|
-
!(str = traverse_hash(data, key)).to_s.empty?
|
30
|
-
return str
|
31
|
-
end
|
32
|
-
|
33
|
-
raise JekyllLanguagePlugin::PluginError.new("Language string #{key} not found.")
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.get_language_name(context, name)
|
37
|
-
translation = self.get_language_data(context, 'lang')
|
38
|
-
|
39
|
-
raise JekyllLanguagePlugin::PluginError.new('Language name not found in translation.') if translation.nil? ||
|
40
|
-
!translation.key?(name)
|
41
|
-
|
42
|
-
translation[name]
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.traverse_hash(hash, keys)
|
46
|
-
return nil if hash.nil? || keys.to_s.empty?
|
47
|
-
keys = keys.split('.') if keys.is_a?(String)
|
48
|
-
|
49
|
-
for key in keys
|
50
|
-
if !hash.is_a?(Hash)
|
51
|
-
return hash
|
52
|
-
elsif !hash.key?(key)
|
53
|
-
return nil
|
54
|
-
end
|
55
|
-
hash = hash[key]
|
56
|
-
end
|
57
|
-
hash
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Jekyll
|
2
|
-
module Filters
|
3
|
-
module LanguageDate
|
4
|
-
def tdate(input, fkey)
|
5
|
-
if ((input.is_a?(String) && !/^\d+$/.match(input).nil?) || input.is_a?(Integer)) && input.to_i > 0
|
6
|
-
date = Time.at(input.to_i)
|
7
|
-
elsif input.is_a?(String)
|
8
|
-
case input.downcase
|
9
|
-
when 'now', 'today'
|
10
|
-
date = Time.now
|
11
|
-
else
|
12
|
-
date = Time.parse(input)
|
13
|
-
end
|
14
|
-
elsif input.is_a?(Time)
|
15
|
-
date = input
|
16
|
-
else
|
17
|
-
date = nil
|
18
|
-
end
|
19
|
-
|
20
|
-
return "" if !date.is_a?(Time)
|
21
|
-
format = JekyllLanguagePlugin::LiquidContext.get_language_string(@context, fkey)
|
22
|
-
return "" if format.nil?
|
23
|
-
|
24
|
-
JekyllLanguagePlugin::DateLocalizer.localize_date(date, format, @context).to_s
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
Liquid::Template.register_filter(Jekyll::Filters::LanguageDate)
|
data/lib/jekyll/tags/language.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Jekyll
|
2
|
-
module Tags
|
3
|
-
class LanguageTag < Liquid::Tag
|
4
|
-
def initialize(tag_name, markup, tokens)
|
5
|
-
super
|
6
|
-
@markup = markup
|
7
|
-
end
|
8
|
-
|
9
|
-
def render(context)
|
10
|
-
p = Liquid::Parser.new(@markup)
|
11
|
-
name = Liquid::Expression.parse(exp = p.expression)
|
12
|
-
key = context.evaluate(name)
|
13
|
-
raise Liquid::SyntaxError.new("Invalid language key expression: #{exp}") if key.nil?
|
14
|
-
|
15
|
-
# get language string from evaluated key
|
16
|
-
str = JekyllLanguagePlugin::LiquidContext.get_language_string(context, key)
|
17
|
-
|
18
|
-
if p.consume?(:colon)
|
19
|
-
loop do
|
20
|
-
arg = Liquid::Expression.parse(exp = p.expression)
|
21
|
-
argstr = context.evaluate(arg)
|
22
|
-
raise Liquid::SyntaxError.new("Invalid parameter expression: #{exp}") if argstr.nil?
|
23
|
-
raise JekyllLanguagePlugin::PluginError.new("Language string is lacking parameter placeholder.") unless str.include?("%%")
|
24
|
-
str.sub!("%%", argstr)
|
25
|
-
break if !p.consume?(:comma)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
str
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Liquid::Template.register_tag('t', Jekyll::Tags::LanguageTag)
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Jekyll
|
2
|
-
module Tags
|
3
|
-
class LanguageIncludeTag < IncludeTag
|
4
|
-
def tag_includes_dir(context)
|
5
|
-
(context.registers[:site].config['language_includes_dir'].to_s || '_i18n').freeze
|
6
|
-
end
|
7
|
-
|
8
|
-
def page_language(context)
|
9
|
-
context.registers[:page].nil? ? "en" : context.registers[:page]["language"]
|
10
|
-
end
|
11
|
-
|
12
|
-
def resolved_includes_dir(context)
|
13
|
-
File.join(context.registers[:site].in_source_dir(@includes_dir), page_language(context))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Liquid::Template.register_tag('tinclude', Jekyll::Tags::LanguageIncludeTag)
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Jekyll
|
2
|
-
module Tags
|
3
|
-
class LanguageNameTag < Liquid::Tag
|
4
|
-
def initialize(tag_name, markup, tokens)
|
5
|
-
super
|
6
|
-
@markup = markup
|
7
|
-
end
|
8
|
-
|
9
|
-
def render(context)
|
10
|
-
p = Liquid::Parser.new(@markup)
|
11
|
-
name = Liquid::Expression.parse(exp = p.expression)
|
12
|
-
key = context.evaluate(name)
|
13
|
-
raise Liquid::SyntaxError.new("Invalid language key expression: #{exp}") if key.nil?
|
14
|
-
|
15
|
-
# get language name string from evaluated key
|
16
|
-
JekyllLanguagePlugin::LiquidContext.get_language_string(context, "lang.#{key}")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
Liquid::Template.register_tag('tl', Jekyll::Tags::LanguageNameTag)
|