jekyll-multiple-languages-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe3855f441762da2b1d4a9737a2e273bac6a639d
4
- data.tar.gz: aab8762a89829c8b565831f9727ff7c02710784c
3
+ metadata.gz: 6187612df275e2d51d0e6f5f99963febe2333679
4
+ data.tar.gz: fc44bb0d56f3e24b2f56fc01b7aa0d13518c36c7
5
5
  SHA512:
6
- metadata.gz: c696bf500206369ab839d2649dfa7a44f268c0897ac61a4dce146c4467de208fe42efe660be6254ea44fbb0683e2442810d82bb0cce904148253e20052abd0ef
7
- data.tar.gz: 5564ef20925fa8cbdadd669aae6db1a9b51d8d7d34c6d9036d4e0f23afbe1d569f558c6a393eabe6e88c094df66fb99b515e8b557db1057a940fc5d6bd4cfa7e
6
+ metadata.gz: 8e1f9008fb309d343c0134f780cecefac777f0f063d35d20f4ec248ab0747a689ec12fba7919c05141339ac8ef61b9881d2fc16514fd03df672871e8461d18e7
7
+ data.tar.gz: d7ed899954f8d9c65e6b70c47ce4dcc078862d741bd9c54e880f801031418c0d21a148ba8676e40a15140a98cb9b79be9050f277631fc5bef1f2ea50fd6198a0
data/README.md CHANGED
@@ -12,19 +12,19 @@ This plugin is available as a Rubygem, https://rubygems.org/gems/jekyll-multiple
12
12
 
13
13
  Add this line to your application's Gemfile:
14
14
 
15
- gem 'jekyll-multiple-languages-plugin'
16
-
17
- And then execute:
18
-
19
- $ bundle
15
+ ```
16
+ gem 'jekyll-multiple-languages-plugin'
17
+ ```
20
18
 
21
- Or install it yourself as:
19
+ And then execute: `$ bundle`
22
20
 
23
- $ gem install jekyll-multiple-languages-plugin
21
+ Or install it yourself as: `$ gem install jekyll-multiple-languages-plugin`
24
22
 
25
23
  To activate the plugin add this line in to a *.rb file in the _plugins directory:
26
-
27
- require 'jekyll/multiple/languages/plugin'
24
+
25
+ ```ruby
26
+ require 'jekyll/multiple/languages/plugin'
27
+ ```
28
28
 
29
29
 
30
30
  ### Submodule
@@ -33,18 +33,22 @@ manage your plugins by utilizing git submodules.
33
33
 
34
34
  To install this plugin as a git submodule:
35
35
 
36
- git submodule add git://github.com/screeninteraction/jekyll-multiple-languages-plugin.git _plugins/multiple-languages
36
+ ```sh
37
+ $ git submodule add git://github.com/screeninteraction/jekyll-multiple-languages-plugin.git _plugins/multiple-languages
38
+ ```
37
39
 
38
40
  To update:
39
41
 
40
- cd _plugins/multiple-languages
41
- git pull origin master
42
+ ```sh
43
+ $ cd _plugins/multiple-languages
44
+ $ git pull origin master
45
+ ```
42
46
 
43
47
 
44
48
  ### Copy file
45
49
  Copy or link the file `lib/jekyll/multiple/languages/plugin.rb` into your `_plugins` folder for your Jekyll project.
46
50
 
47
-
51
+
48
52
  ##Features
49
53
  * Supports multiple languages with the same code base.
50
54
  * Supports all template languages that your Liquid pipeline supports.
@@ -56,6 +60,8 @@ Copy or link the file `lib/jekyll/multiple/languages/plugin.rb` into your `_plug
56
60
  * Supports translated template files
57
61
 
58
62
  ##Changelog
63
+ 1.2.3
64
+ Much, much, much faster compilation when lots of translated strings.
59
65
  * 1.2.2
60
66
  * Supports translated posts in Octopress
61
67
  * 1.2.1
@@ -77,7 +83,7 @@ Copy or link the file `lib/jekyll/multiple/languages/plugin.rb` into your `_plug
77
83
  ###Configuration
78
84
  Add the i18n configuration to your _config.yml:
79
85
 
80
- ```yaml
86
+ ```yaml
81
87
  languages: ["sv", "en", "de", "fr"]
82
88
  ```
83
89
 
@@ -97,12 +103,12 @@ Create this folder structure in your Jekyll project as an example:
97
103
 
98
104
  To add a string to your site use one of these
99
105
 
100
- ```liquid
106
+ ```liquid
101
107
  {% t key %}
102
- or
108
+ or
103
109
  {% translate key %}
104
110
  ```
105
-
111
+
106
112
  Liquid tags. This will pick the correct string from the `language.yml` file during compilation.
107
113
 
108
114
  The language.yml files are written in YAML syntax which caters for a simple grouping of strings.
@@ -115,31 +121,31 @@ pages:
115
121
  home: Home
116
122
  work: Work
117
123
  ```
118
-
124
+
119
125
  To access the english key, use this tag:
120
126
 
121
- ```liquid
122
- {% t global.english %}
123
- or
127
+ ```liquid
128
+ {% t global.english %}
129
+ or
124
130
  {% translate global.english %}
125
131
  ```
126
-
127
- The plugin also supports using different markdown files for different languages using the
128
132
 
129
- ```liquid
130
- {% tf pagename/blockname.md %}
131
- or
133
+ The plugin also supports using different markdown files for different languages using the
134
+
135
+ ```liquid
136
+ {% tf pagename/blockname.md %}
137
+ or
132
138
  {% translate_file pagename/blockname.md %}
133
139
  ```
134
140
 
135
141
  This plugin have exactly the same support and syntax as the built in
136
142
 
137
- ```liquid
143
+ ```liquid
138
144
  {% include file %}
139
145
  ```
140
146
 
141
147
  tag, so plugins that extends its functionality should be picked up by this plugin as well.
142
-
148
+
143
149
  ###i18n in templates
144
150
  Sometimes it is convenient to add keys even in template files. This works in the exact same way as in ordinary files, however sometimes it can be useful to include different string in different pages even if they use the same template.
145
151
 
@@ -152,34 +158,34 @@ A perfect example is this:
152
158
  </head>
153
159
  </html>
154
160
  ```
155
-
161
+
156
162
  So how can I add different translated titles to all pages? Don't worry, it's easy. The Multiple Languages plugin supports Liguid variables as well as strings so define a page variable in your page definition
157
163
 
158
164
  ```yaml
159
- ---
165
+ ---
160
166
  layout: default
161
167
  title: titles.home
162
- ---
163
- ```
164
-
168
+ ---
169
+ ```
170
+
165
171
  and `<title>{% t page.title %}</title>` will pick up the `titles.home` key from `language.yml`
166
172
 
167
- ```yaml
173
+ ```yaml
168
174
  titles:
169
175
  home: "Home"
170
176
  ```
171
-
177
+
172
178
  ##Link between languages
173
179
  This plugin gives you the variables
174
-
180
+
175
181
  ```liquid
176
182
  {{ page.lang }}
177
-
183
+
178
184
  and
179
-
185
+
180
186
  {{ site.baseurl_root }}
181
187
  ```
182
-
188
+
183
189
  to play with in your template files.
184
190
 
185
191
  This allows you to create solutions like this:
@@ -16,7 +16,7 @@ module Jekyll
16
16
  #Loop
17
17
  self.config['lang'] = languages.first
18
18
  puts
19
- puts "Building site for default language: \"#{self.config['lang']}\" to: " + self.dest
19
+ puts "Building site for default language: \"#{self.config['lang']}\" to: #{self.dest}"
20
20
  process_org
21
21
  languages.drop(1).each do |lang|
22
22
 
@@ -24,7 +24,7 @@ module Jekyll
24
24
  self.dest = self.dest + "/" + lang
25
25
  self.config['baseurl'] = self.config['baseurl'] + "/" + lang
26
26
  self.config['lang'] = lang
27
- puts "Building site for language: \"#{self.config['lang']}\" to: " + self.dest
27
+ puts "Building site for language: \"#{self.config['lang']}\" to: #{self.dest}"
28
28
  process_org
29
29
 
30
30
  #Reset variables for next language
@@ -33,7 +33,7 @@ module Jekyll
33
33
  end
34
34
  puts 'Build complete'
35
35
  end
36
-
36
+
37
37
  alias :read_posts_org :read_posts
38
38
  def read_posts(dir)
39
39
  if dir == ''
@@ -49,6 +49,7 @@ module Jekyll
49
49
  def initialize(tag_name, key, tokens)
50
50
  super
51
51
  @key = key.strip
52
+ @@langs ||= {}
52
53
  end
53
54
 
54
55
  def render(context)
@@ -58,21 +59,16 @@ module Jekyll
58
59
  key = @key
59
60
  end
60
61
  lang = context.registers[:site].config['lang']
61
- candidate = YAML.load_file(context.registers[:site].source + "/_i18n/#{lang}.yml")
62
- path = key.split(/\./) if key.is_a?(String)
63
- while !path.empty?
64
- key = path.shift
65
- if candidate[key]
66
- candidate = candidate[key]
67
- else
68
- candidate = ""
69
- end
62
+ unless @@langs.has_key?(lang)
63
+ puts "Loading translation from file #{context.registers[:site].source}/_i18n/#{lang}.yml"
64
+ @@langs[lang] = YAML.load_file("#{context.registers[:site].source}/_i18n/#{lang}.yml")
70
65
  end
71
- if candidate == ""
72
- puts "Missing i18n key: " + lang + ":" + key
73
- "*" + lang + ":" + key + "*"
66
+ translation = @@langs[lang].access(key) if key.is_a?(String)
67
+ if translation.empty?
68
+ puts "Missing i18n key: #{lang}:#{key}"
69
+ "*#{lang}:#{key}*"
74
70
  else
75
- candidate
71
+ translation
76
72
  end
77
73
  end
78
74
  end
@@ -121,6 +117,23 @@ module Jekyll
121
117
  end
122
118
  end
123
119
 
120
+ unless Hash.method_defined? :access
121
+ class Hash
122
+ def access(path)
123
+ ret = self
124
+ path.split('.').each do |p|
125
+ if p.to_i.to_s == p
126
+ ret = ret[p.to_i]
127
+ else
128
+ ret = ret[p.to_s] || ret[p.to_sym]
129
+ end
130
+ break unless ret
131
+ end
132
+ ret
133
+ end
134
+ end
135
+ end
136
+
124
137
  Liquid::Template.register_tag('t', Jekyll::LocalizeTag)
125
138
  Liquid::Template.register_tag('translate', Jekyll::LocalizeTag)
126
139
  Liquid::Template.register_tag('tf', Jekyll::Tags::LocalizeInclude)
@@ -2,7 +2,7 @@ module Jekyll
2
2
  module Multiple
3
3
  module Languages
4
4
  module Plugin
5
- VERSION = "1.2.2"
5
+ VERSION = "1.2.3"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-multiple-languages-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Kurtsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-05 00:00:00.000000000 Z
11
+ date: 2014-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.2.0
103
+ rubygems_version: 2.2.2
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: I18n plugin for Jekyll and Octopress