jekyll-language-plugin 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b6c261bef7ca88520afb58ec4a1760617681229
4
- data.tar.gz: fd4978a18ea984aacdccafb8b43b6c8b20cb6323
3
+ metadata.gz: 2a1bb3cff51451bb186fcf8ed868ca7d16163f5b
4
+ data.tar.gz: 85b13baa23d8917c28c2c5b0ecc61af64641a227
5
5
  SHA512:
6
- metadata.gz: 1528ab446fa8b5446dfa068aa377f669d8933aa4fae6faab3f021fc9c502d1a9b53134398a6fa15e8490a150a3b8f2f1d101da30ad0c119427d20f4900e75986
7
- data.tar.gz: 1782d0f93101c1a2dfceaf5783eaf859138f201153dceb0e8f486c2242e246b66106bc0b5bab28969b1c1bb90c7a2c585ecd6d981a337ab921a0d9b8ecba24ec
6
+ metadata.gz: 7a454dd37cfadf074becdb4554f5511b43d77b5b40f2390aafd226da7dfe5f03b64b6cff78b9f3f5c0a0c6aa394b165ac1a29a6ed7b11d23444febfa68051c0a
7
+ data.tar.gz: bad803fc855229a0ced531494dbe8b15884f5f9c21df72baa2c57f463f05c6b6946a6a4caeef8615231c4e75fa82fa3ef33d092ddc4929102ae2ee8d519c0e85
data/README.md CHANGED
@@ -62,10 +62,10 @@ This is a page optimized for the language plugin, `home.html`:
62
62
  ```
63
63
  ---
64
64
  layout: default
65
- subset: home
66
65
  languages:
67
66
  - en
68
67
  - de
68
+ subset: home
69
69
  ---
70
70
  <h1>{% t title %}</h1>
71
71
  <p>{% t description %}</p>
@@ -127,6 +127,8 @@ If you now run `jekyll build`, you will obtain two separate `home.html` files in
127
127
 
128
128
  Similar to pages, posts can also have the `languages` or `language` keys as well as the `subset` key in its YAML front-matter. You can use all supported liquid tags and filters to translate posts but you can also create multiple posts, one for each language.
129
129
 
130
+ It is recommended not to make excessive use of the liquid tags in posts but instead create a post for each translation.
131
+
130
132
  ## Liquid tags
131
133
 
132
134
  Currently, there are two liquid tags provided by this plugin.
@@ -11,6 +11,7 @@ require 'jekyll/readers/language_page_reader.rb'
11
11
  require 'jekyll/readers/language_post_reader.rb'
12
12
  require 'jekyll/filters/language_date.rb'
13
13
  require 'jekyll/tags/language.rb'
14
+ require 'jekyll/tags/language_name.rb'
14
15
  require 'jekyll/tags/language_include.rb'
15
16
 
16
17
  # replace Jekyll::Reader upon page reset with Jekyll::LanguageReader extension
@@ -33,6 +33,15 @@ module JekyllLanguagePlugin
33
33
  raise JekyllLanguagePlugin::PluginError.new("Language string #{key} not found.")
34
34
  end
35
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
+
36
45
  def self.traverse_hash(hash, keys)
37
46
  return nil if hash.nil? || keys.to_s.empty?
38
47
  keys = keys.split('.') if keys.is_a?(String)
@@ -3,15 +3,28 @@ module Jekyll
3
3
  class LanguageTag < Liquid::Tag
4
4
  def initialize(tag_name, markup, tokens)
5
5
  super
6
- @params = markup.gsub(/\s+/m, ' ').strip.split(" ")
7
- @lkey = @params.shift
6
+ @markup = markup
8
7
  end
9
8
 
10
9
  def render(context)
11
- str = JekyllLanguagePlugin::LiquidContext.get_language_string(context, @lkey)
12
- return "" if str.nil?
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?
13
14
 
14
- @params.each { |p| str.sub!("%%", p) }
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
15
28
  str
16
29
  end
17
30
  end
@@ -0,0 +1,22 @@
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)
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.2
4
+ version: 1.1.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-11-17 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -82,6 +82,7 @@ files:
82
82
  - lib/jekyll/readers/language_post_reader.rb
83
83
  - lib/jekyll/tags/language.rb
84
84
  - lib/jekyll/tags/language_include.rb
85
+ - lib/jekyll/tags/language_name.rb
85
86
  - lib/jekyll-language-plugin/date_localizer.rb
86
87
  - lib/jekyll-language-plugin/liquid_context.rb
87
88
  - lib/jekyll-language-plugin/plugin_exception.rb