jekyll-language-plugin 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/jekyll-language-plugin.rb +10 -6
- data/lib/jekyll/language-plugin/date_localizer.rb +7 -6
- data/lib/jekyll/language-plugin/filters/language_date.rb +1 -4
- data/lib/jekyll/language-plugin/language_data.rb +33 -10
- data/lib/jekyll/language-plugin/liquid_context.rb +52 -13
- data/lib/jekyll/language-plugin/loaders/base_loader.rb +9 -6
- data/lib/jekyll/language-plugin/loaders/builtin_data_loader.rb +1 -0
- data/lib/jekyll/language-plugin/tags/language.rb +6 -8
- data/lib/jekyll/language-plugin/version.rb +1 -1
- data/lib/jekyll/language_page.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 474a7a7e024e8fdae812794d6970da82887655c2
|
4
|
+
data.tar.gz: 4a8f30df701b2530cda2ce3339a95bb234983a25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b029db16f1aa3a05c7e4d60a0d60d849bdac2ca87541cdea1d71308c71d5c336b841642f750b52261e62e11438f75026d4cd242e54fbdb27ead31789fee6d635
|
7
|
+
data.tar.gz: 5146e49851e0bd2e50bc124e446c4ee41faae2cf992f1854784cac6d848c0637746fe440b43b2e7680b3978bc8cf99aeab5577ce3b557abcaef8b2daf71319cd
|
data/README.md
CHANGED
@@ -17,6 +17,7 @@ This plugin has been developed with user-simplicity in mind. It does not require
|
|
17
17
|
* Supports localized URLs
|
18
18
|
* Works with `jekyll serve --watch`
|
19
19
|
* Supports includes translated into multiple languages
|
20
|
+
* Includes language and date translations for 27 languages
|
20
21
|
|
21
22
|
## Installation
|
22
23
|
|
@@ -22,12 +22,8 @@ module Jekyll
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class << self
|
25
|
-
def loaders
|
26
|
-
@loaders ||= []
|
27
|
-
end
|
28
|
-
|
29
25
|
def register_loader(loader)
|
30
|
-
|
26
|
+
LanguageData.register_loader(loader)
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -41,9 +37,17 @@ require 'jekyll/language-plugin/loaders/builtin_data_loader.rb'
|
|
41
37
|
Dir[File.join(File.dirname(__FILE__), 'jekyll/language-plugin/tags/*.rb')].each{ |f| require f }
|
42
38
|
require 'jekyll/language-plugin/filters/language_date.rb'
|
43
39
|
|
44
|
-
# replace Jekyll::Reader upon page reset with Jekyll::LanguageReader extension
|
45
40
|
Jekyll::Hooks.register :site, :after_reset do |site|
|
41
|
+
# replace Jekyll::Reader with Jekyll::LanguageReader extension
|
46
42
|
site.reader = Jekyll::LanguageReader.new(site)
|
43
|
+
|
44
|
+
# add dynamic languageData property
|
45
|
+
unless site.respond_to?(:languageData) && site.respond_to?(:languageData=)
|
46
|
+
site.class.module_eval { attr_accessor :languageData }
|
47
|
+
end
|
48
|
+
|
49
|
+
# create new language data instance
|
50
|
+
site.languageData = Jekyll::LanguagePlugin::LanguageData.new(site)
|
47
51
|
end
|
48
52
|
|
49
53
|
# monkey patch URL.sanitize_url for handling of triple slashes
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module LanguagePlugin
|
3
|
-
|
4
|
-
|
5
|
-
language_data = Jekyll::LanguagePlugin::LiquidContext.get_language_data(context)
|
6
|
-
translation = language_data.get('date')
|
3
|
+
class DateLocalizer
|
4
|
+
attr_reader :translation
|
7
5
|
|
8
|
-
|
6
|
+
def initialize(translation)
|
7
|
+
@translation = translation
|
8
|
+
end
|
9
9
|
|
10
|
+
def localize_date(date, format)
|
10
11
|
# validate language translation
|
11
12
|
if !['abbr_daynames', 'daynames', 'abbr_monthnames', 'monthnames'].all? {|s| translation.key?(s) && translation[s].is_a?(Array) } ||
|
12
13
|
translation['abbr_daynames'].size < 7 || translation['daynames'].size < 7 ||
|
13
14
|
translation['abbr_monthnames'].size < 12 || translation['monthnames'].size < 12
|
14
|
-
raise Jekyll::LanguagePlugin::PluginError.new('Invalid
|
15
|
+
raise Jekyll::LanguagePlugin::PluginError.new('Invalid date translation.')
|
15
16
|
end
|
16
17
|
|
17
18
|
date.strftime(
|
@@ -19,10 +19,7 @@ module Jekyll
|
|
19
19
|
end
|
20
20
|
|
21
21
|
return "" if !date.is_a?(Time)
|
22
|
-
|
23
|
-
return "" if format.nil?
|
24
|
-
|
25
|
-
Jekyll::LanguagePlugin::DateLocalizer.localize_date(date, format, @context).to_s
|
22
|
+
LiquidContext.get_localized_date(@context, date, fkey)
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
@@ -1,23 +1,46 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module LanguagePlugin
|
3
3
|
class LanguageData
|
4
|
-
attr_reader :language
|
4
|
+
attr_reader :site, :language
|
5
5
|
|
6
|
-
def initialize(site
|
7
|
-
@
|
8
|
-
@
|
6
|
+
def initialize(site)
|
7
|
+
@site = site
|
8
|
+
@l_inst_ary = Array.new
|
9
9
|
end
|
10
10
|
|
11
|
-
def get(key)
|
12
|
-
|
13
|
-
loader.
|
14
|
-
|
11
|
+
def get(key, language)
|
12
|
+
inject_loaders(language) do |result, loader|
|
13
|
+
loader.get(key, language)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_with_placeholders(key, tokens, language)
|
18
|
+
inject_loaders(language) do |result, loader|
|
19
|
+
loader.get_with_placeholders(key, tokens, language)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def inject_loaders(language)
|
24
|
+
self.class.loaders.inject(nil) do |result, loader|
|
25
|
+
unless l_inst = @l_inst_ary.detect { |l| l.is_a?(loader) }
|
26
|
+
l_inst = loader.new(@site)
|
27
|
+
@l_inst_ary.push(l_inst)
|
28
|
+
end
|
29
|
+
|
30
|
+
l_inst.load(language) unless l_inst.loaded?(language)
|
31
|
+
result = yield result, l_inst
|
15
32
|
break result unless result.nil?
|
16
33
|
end
|
17
34
|
end
|
18
35
|
|
19
|
-
|
20
|
-
|
36
|
+
class << self
|
37
|
+
def loaders
|
38
|
+
@loaders ||= []
|
39
|
+
end
|
40
|
+
|
41
|
+
def register_loader(loader)
|
42
|
+
loaders.push(loader)
|
43
|
+
end
|
21
44
|
end
|
22
45
|
end
|
23
46
|
end
|
@@ -2,38 +2,77 @@ module Jekyll
|
|
2
2
|
module LanguagePlugin
|
3
3
|
module LiquidContext
|
4
4
|
def self.get_language_data(context)
|
5
|
-
|
6
|
-
|
7
|
-
end
|
5
|
+
context.registers[:site].languageData
|
6
|
+
end
|
8
7
|
|
8
|
+
def self.get_language(context)
|
9
9
|
language = context.registers[:page]['language']
|
10
|
+
|
10
11
|
if language.to_s.empty?
|
11
12
|
raise Jekyll::LanguagePlugin::PluginError.new('No language specified for current page or post.')
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
context.registers[:language_data] = LanguageData.new(site, language)
|
15
|
+
language
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.get_language_string(context, key)
|
18
|
+
def self.get_language_string(context, key, tokens=nil)
|
19
19
|
language_data = self.get_language_data(context)
|
20
|
+
language = self.get_language(context)
|
20
21
|
|
21
22
|
subset = context.registers[:page]['subset']
|
22
|
-
str = language_data.get([subset, key]) unless subset.to_s.empty?
|
23
|
-
str ||= language_data.get(key)
|
24
23
|
|
25
|
-
|
24
|
+
if tokens.is_a?(Array) && tokens.length > 0
|
25
|
+
unless subset.to_s.empty?
|
26
|
+
str = language_data.get_with_placeholders([subset, key], tokens, language)
|
27
|
+
end
|
28
|
+
str ||= language_data.get_with_placeholders(key, tokens, language)
|
29
|
+
else
|
30
|
+
unless subset.to_s.empty?
|
31
|
+
str = language_data.get([subset, key], language)
|
32
|
+
end
|
33
|
+
str ||= language_data.get(key, language)
|
34
|
+
end
|
35
|
+
|
36
|
+
if str.nil?
|
37
|
+
raise Jekyll::LanguagePlugin::PluginError.new("Key #{key} not found in translation.")
|
38
|
+
end
|
39
|
+
|
26
40
|
str
|
27
41
|
end
|
28
42
|
|
43
|
+
def self.get_localized_date(context, date, format_key)
|
44
|
+
language_data = self.get_language_data(context)
|
45
|
+
language = self.get_language(context)
|
46
|
+
|
47
|
+
subset = context.registers[:page]['subset']
|
48
|
+
format_str = language_data.get([subset, format_key], language) unless subset.to_s.empty?
|
49
|
+
format_str ||= language_data.get(format_key, language)
|
50
|
+
|
51
|
+
if format_str.nil?
|
52
|
+
raise Jekyll::LanguagePlugin::PluginError.new("Date format key #{key} not found in translation.")
|
53
|
+
end
|
54
|
+
|
55
|
+
date_translation = language_data.get('date', language)
|
56
|
+
|
57
|
+
if date_translation.nil?
|
58
|
+
raise Jekyll::LanguagePlugin::PluginError.new('No localized date available for translation.')
|
59
|
+
end
|
60
|
+
|
61
|
+
date_localizer = DateLocalizer.new(date_translation)
|
62
|
+
date_localizer.localize_date(date, format_str)
|
63
|
+
end
|
64
|
+
|
29
65
|
def self.get_language_name(context, name)
|
30
66
|
language_data = self.get_language_data(context)
|
31
|
-
|
67
|
+
language = self.get_language(context)
|
32
68
|
|
33
|
-
|
34
|
-
!translation.key?(name)
|
69
|
+
str = language_data.get(['lang', name])
|
35
70
|
|
36
|
-
|
71
|
+
if str.nil?
|
72
|
+
raise Jekyll::LanguagePlugin::PluginError.new("Language name #{name} not found in translation.")
|
73
|
+
end
|
74
|
+
|
75
|
+
str
|
37
76
|
end
|
38
77
|
end
|
39
78
|
end
|
@@ -10,7 +10,7 @@ module Jekyll
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def loaded?(language)
|
13
|
-
|
13
|
+
true
|
14
14
|
end
|
15
15
|
|
16
16
|
def load(language)
|
@@ -21,13 +21,16 @@ module Jekyll
|
|
21
21
|
nil
|
22
22
|
end
|
23
23
|
|
24
|
+
def get_with_placeholders(key, tokens, language)
|
25
|
+
res = get(key, language)
|
26
|
+
return nil if res.nil?
|
27
|
+
res.gsub(/%%/).with_index { |m, i| tokens[i] || m }
|
28
|
+
end
|
29
|
+
|
24
30
|
def traverse_hash(hash, keys)
|
25
31
|
for key in keys
|
26
|
-
|
27
|
-
|
28
|
-
elsif !hash.key?(key)
|
29
|
-
return nil
|
30
|
-
end
|
32
|
+
return hash unless hash.is_a?(Hash)
|
33
|
+
return nil unless hash.key?(key)
|
31
34
|
hash = hash[key]
|
32
35
|
end
|
33
36
|
hash
|
@@ -13,20 +13,18 @@ module Jekyll
|
|
13
13
|
key = context.evaluate(name)
|
14
14
|
raise Liquid::SyntaxError.new("Invalid language key expression: #{exp}") if key.nil?
|
15
15
|
|
16
|
-
|
17
|
-
str = Jekyll::LanguagePlugin::LiquidContext.get_language_string(context, key)
|
18
|
-
|
16
|
+
tokens = Array.new
|
19
17
|
if p.consume?(:colon)
|
20
18
|
loop do
|
21
19
|
arg = Liquid::Expression.parse(exp = p.expression)
|
22
|
-
|
23
|
-
raise Liquid::SyntaxError.new("Invalid parameter expression: #{exp}") if
|
24
|
-
|
25
|
-
str.sub!("%%", argstr)
|
20
|
+
token = context.evaluate(arg)
|
21
|
+
raise Liquid::SyntaxError.new("Invalid parameter expression: #{exp}") if token.nil?
|
22
|
+
tokens.push(token)
|
26
23
|
break if !p.consume?(:comma)
|
27
24
|
end
|
28
25
|
end
|
29
|
-
|
26
|
+
|
27
|
+
Jekyll::LanguagePlugin::LiquidContext.get_language_string(context, key, tokens)
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
data/lib/jekyll/language_page.rb
CHANGED
@@ -17,9 +17,9 @@ module Jekyll
|
|
17
17
|
})
|
18
18
|
|
19
19
|
if !language.nil? && !subset.nil?
|
20
|
-
|
20
|
+
language_data = @site.languageData || LanguagePlugin::LanguageData.new(@site)
|
21
21
|
|
22
|
-
data =
|
22
|
+
data = language_data.get(subset, language)
|
23
23
|
|
24
24
|
if !data.nil?
|
25
25
|
filtered = data.reject{ |k, v| v.is_a?(Enumerable) }
|
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.2.
|
4
|
+
version: 1.2.3
|
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-12-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|