octopress-multilingual 0.0.9 → 0.1.0

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: 93762ea4b72fa9617cb1a1e6517f07c7286bc84f
4
- data.tar.gz: cec1457c4daaf7614f0baccd33aa100f623e760b
3
+ metadata.gz: d574450d03a50e29229defe0ea43f9aa62c8052f
4
+ data.tar.gz: 1a3203980d28af20e8bf76494680d069f3eec942
5
5
  SHA512:
6
- metadata.gz: 778acd242ccea05e7f555d84e820613a6156b0c41399d2e1c5af0714645b9f687094260511cb59bd5699372f54f946d8db3b82da9527f6e2a99235ebc35f1a95
7
- data.tar.gz: e74201756fed2707d1a499b1d3d26ea30fe66e4b7f866f6593955bf33d34ab3114f4954b0b7a1a091725c67b83d3585f6ddc36cfa404b7e404f0ec863d892f1b
6
+ metadata.gz: 12682c041d6f53e83c69ec5f42de3494efa574a472c5e4e6a09b717bbb82b03d19f32dcc8228df1ea9d6dc6ea578bd19a18a62eaf462c2356902341c8cad8952
7
+ data.tar.gz: 18361af1f5d6b236060a2314c9390121566908b36939c78ae70c53aa0dd10368ff38577d71a032d7d633ad1635629b728b3edb3fec7524d3dc0e21cc63465c78
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.1.0 (2015-01-30)
4
+ - Change: No longer filters `site.posts` at all.
5
+ - Change: Posts are automatically filtered based on `page.lang`.
6
+ - Docs have been improved quite a bit.
7
+
3
8
  ### 0.0.9 (2015-01-25)
4
9
  - Fix: Language cross-posts are now properly sorted. Thanks @drallgood, via [#6](https://github.com/octopress/multilingual/pull/6).
5
10
 
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Octopress Multilingual
2
2
 
3
- Add multiple language features to your Jekyll site.
3
+ Add multiple language features to your Jekyll site. This plugin makes it easy to:
4
+
5
+ - Add language-specific post indexes, archives, and RSS feeds.
6
+ - Set language based permalinks.
7
+ - Cross-post between languages.
4
8
 
5
9
  [![Build Status](http://img.shields.io/travis/octopress/multilingual.svg)](https://travis-ci.org/octopress/multilingual)
6
10
  [![Gem Version](http://img.shields.io/gem/v/octopress-multilingual.svg)](https://rubygems.org/gems/octopress-multilingual)
@@ -30,11 +34,15 @@ Then add the gem to your Jekyll configuration.
30
34
 
31
35
  ## An important note
32
36
 
33
- **There is not a Jekyll standard for multilingual sites** and many plugins will not work properly with this setup. Octopress and it's
37
+ **There is no Jekyll standard for multilingual sites** and many plugins will not work properly with this setup. Octopress and it's
34
38
  plugins are being designed to support multilingual features, but without a standard, some use-cases may be overlooked. If you have a
35
39
  problem with an Octopress plugin supporting your multilingual site, please file an issue and we'll do our best to address it.
36
40
 
37
- ## Setting up a multilingual site
41
+ Note: First-party Octopress plugins are designed to support multilingual sites but other plugins may not work how you'd expect on multilingual sites. Modifying plugins is beyond the scope of this guide.
42
+
43
+ Also, if you are using flags to represent languages on your site, you might like to read, [Why flags do not represent language](http://flagsarenotlanguages.com/blog/why-flags-do-not-represent-language/).
44
+
45
+ ## Setup
38
46
 
39
47
  When adding this plugin to your site, you will need to:
40
48
 
@@ -42,14 +50,6 @@ When adding this plugin to your site, you will need to:
42
50
  2. Add a language to the YAML front-matter of your posts, e.g. `lang: de`.
43
51
  3. Add new RSS feeds and post indexes for secondary languages.
44
52
 
45
- Read on and I'll try to walk you through setting up your multilingual site.
46
-
47
- Note: This guide will only cover the steps listed above. Your site may still have some plugins which are not designed for multilingual sites. If you are using plugins (like a category index generator) which create pages from your site's posts, they may need to be modified or removed. Modifying plugins is beyond the scope of this guide.
48
-
49
- ## Configuration
50
-
51
- You can for standard language codes.
52
-
53
53
  First, be sure to configure your Jekyll site's main language. An site written primarily in English would add this to its Jekyll configuration:
54
54
 
55
55
  ```yaml
@@ -57,36 +57,86 @@ lang: en
57
57
  ```
58
58
 
59
59
  Here we are setting the default language to English. Posts without a defined language will be treated as English posts.
60
- For a list of standard language codes, refer to [ISO 639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
60
+ For a list of standard language codes, refer to [ISO 639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). You can also use
61
+ the [language]-[region] method of setting your site's language, like `en-us` for American English or `de-at` for Austrian German.
61
62
 
62
- ## Defining a post's language
63
+ ### Setting a language for pages or posts
63
64
 
64
- Posts should specify their language in the YAML front matter.
65
+ Specify a page or post's language in the YAML front matter.
65
66
 
66
67
  ```yaml
67
68
  title: "Ein nachdenklicher Beitrag"
68
69
  lang: de
69
70
  ```
70
71
 
71
- If you are using Octopress, you can easily create a new post with the language already site like this:
72
+ With Octopress, you can do this automatically from the command line when creating posts, drafts, or pages.
72
73
 
73
74
  ```
74
75
  $ octopress new post "Some title" --lang en
76
+ $ octopress new draft "Some title" --lang en
77
+ $ octopress new page de/index.html --lang de
78
+ ```
79
+
80
+ This command will set the language (in the YAML front-matter) and posts will be created in `_posts/[lang]/[post-file]`.
81
+
82
+ ## Indexes, RSS feeds and Archives.
83
+
84
+ If you are writing English and German posts, you'll want an English-only and a German-only post index. To do that, just set the
85
+ language in the YAML front-matter of your post-index.
86
+
87
+ For example, this will loop through only German posts:
88
+
89
+ ```
90
+ ---
91
+ lang: de
92
+ ---
93
+ {% for post in site.posts %} ... {% endfor %}
94
+ ```
95
+
96
+ And this will loop through only English posts:
97
+
98
+ ```
99
+ ---
100
+ lang: en
101
+ ---
102
+ {% for post in site.posts %} ... {% endfor %}
75
103
  ```
76
104
 
77
- This command will set the post language (in the YAML front-matter) and add it to the `_posts/en` directory.
105
+ If your default post index is at `/index.html` you should create additional indexes for each secondary language. If your secondary language is German, create a posts index at `/de/index.html`.
106
+
107
+ How does it work? First this plugin groups all of your posts by language. Then at build time, any page with a language defined will
108
+ have its posts filtered to display only matching languages. If your site uses [octopress-linkblog](https://github.com/octopress/linkblog) to publish link-posts, your `site.articles` and `site.linkposts` will be filtered as well.
109
+
110
+ This same approach will let you create language-specific RSS feeds and post archives. If you are using [octopress-feeds](https://github.com/octopress/feeds), the default RSS feeds will automatically use your default `site.lang` defined language and you can easily create additional RSS feeds for additional languages.
111
+
112
+ ## Reference posts by language
113
+
114
+ All posts are grouped by language and can be accessed directly with `site.posts_by_language`. For example:
115
+
116
+ ```
117
+ {% for post in site.posts_by_language.de %} # German posts
118
+ {% for post in site.posts_by_language.en %} # English posts
119
+ ```
120
+
121
+ If you have [octopress-linkblog](https://github.com/octopress/linkblog) installed, you can access groups of link-posts and articles too.
122
+
123
+ ```
124
+ {% for post in site.linkposts_by_language.de %} # German linkposts
125
+ {% for post in site.articles_by_language.de %} # German articles
126
+ ```
78
127
 
79
128
  ### Cross-posting languages
80
129
 
81
- Occasionally you may wish to write a post in a single language and have it show up in other languages indexes and feeds. This can be done in your post's YAML front-matter:
130
+ If you would like to write a post which shows up in indexes and feeds for every language, set `lang: all` in your post's YAML
131
+ front-matter.
82
132
 
83
133
  ```
84
134
  title: "Ein nachdenklicher Beitrag"
85
- lang: de
86
- crosspost_languages: true
135
+ lang: all
87
136
  ```
88
137
 
89
- If your site has language-specific feeds or post indexes, a post with this setting will show up in all of them. However, it isn't duplicated. It will still have one canonical URL.
138
+ This post will show up with every language. However, it will be treated exactly like a post written in your
139
+ site's default language and will have one canonical URL. Even `{{ post.lang }}` will return your default language instead of `all`.
90
140
 
91
141
  ### Language in permalinks
92
142
 
@@ -118,100 +168,39 @@ ordinal => /:lang/:categories/:year/:y_day/:title.html
118
168
 
119
169
  If you don't want language to appear in your URLs, you must configure your own permalinks without `:lang`.
120
170
 
121
- ## Changing language scope
122
171
 
123
- This plugin modifies your site's post list. The `site.posts` array **will not contain every post**, but only posts defined with your site's main language or with no language defined.
172
+ ## Temporary language scoping
124
173
 
125
174
  Using the `set_lang` liquid block, you can temporarily switch languages while rendering a portion of your site. For example:
126
175
 
127
176
  ```
128
- {{ site.lang }} # => 'en'
129
- {{ site.posts }} # => English posts
177
+ {{ page.lang }} # => 'en'
178
+ {{ site.posts }} # => All posts
130
179
 
131
180
  {% set_lang de %}
132
- {{ site.lang }} # => 'de'
181
+ {{ page.lang }} # => 'de'
133
182
  {{ site.posts }} # => German posts
134
183
  {% endset_lang %}
135
184
 
136
- {{ site.lang }} # => 'en'
137
- {{ site.posts }} # => English posts
185
+ {{ page.lang }} # => 'en'
186
+ {{ site.posts }} # => All posts
138
187
  ```
139
188
 
140
- If you have the [octopress-linkblog](https://github.com/octopress/linkblog) plugin installed, this will also change scope for your
141
- `site.articles` and `site.linkposts` loops.
189
+ The `set_lang` tag will also accept variables, for example:
142
190
 
143
- ## Post Indexes and RSS Feeds
144
-
145
- To add multilingual post indexes you can use the `set_lang` tag like this:
146
-
147
- ```
148
- {% set_lang de %}
149
- {% for post in site.posts %}...{% endfor %}
150
- {% endset_lang %}
151
191
  ```
192
+ {% assign lang = 'de' %}
193
+ {% set_lang lang %} # equivilent to {% set_lang de %}
152
194
 
153
- If your default post index is at `/index.html` you should create additional indexes for each secondary language. If you're also writing in German, create a posts index at `/de/index.html`.
154
-
155
- DRY up your templates by putting post loops in an include, for
156
- example, `_includes/post-index.html`. It might look this:
157
-
158
- <!-- title:"From _includes/post-index.html" -->
159
- ```
160
- {% set_lang page.lang %}
161
- {% for post in site.posts %}...{% endfor %}
162
- {% endset_lang %}
163
- ```
164
-
165
- Set the page language to German and include the same partial.
166
-
167
- <!-- title:"From /de/index.html" -->
168
- ```
169
- ---
170
- lang: de
171
- ---
172
- {% include post-index.html %}
173
- ```
174
-
175
- The `set_lang` tag will read the `page.lang` setting and
176
- convert the post loop to use German. If `page.lang` were
177
- `nil` the default language will be used.
178
-
179
- If you don't want to set the `lang` for a page, but want to
180
- use `{% set_lang %}`, that's fine too. It will also work like
181
- this:
195
+ # On some page
196
+ {% include some_partial.html lang='de' %}
182
197
 
198
+ # In _includes/some_partial.html
199
+ {% set_lang include.lang %} # equivilent to {% set_lang de %}
183
200
  ```
184
- {% include post-index.html lang='de' %}
185
201
 
186
- # Then in the included partial
187
- {% set_lang include.lang %}
188
- ...
189
- ```
190
-
191
- Or even just use a normal post loop on your included file and
192
- set the language when including the partial.
193
-
194
- ```
195
- {% set_lang de %}{% include post-index.html %}{% endset_lang %}
196
- ```
197
-
198
- There are lots of ways to use this, but this approach should work for RSS feeds or any template system which works with the post loop.
199
-
200
- ## Reference posts by language
201
-
202
- You may also access secondary languages directly with `site.posts_by_language`.
203
-
204
- For example, to loop through the posts written in your main language (or those with no defined language) you would do this:
205
-
206
- ```
207
- {% for post in site.posts %}
208
- ```
209
-
210
- If you want to loop through the posts from a secondary language — in this case, German — you would want to do this:
211
-
212
- ```
213
- {% for post in site.posts_by_language.de %}
214
- ```
202
+ If you have the [octopress-linkblog](https://github.com/octopress/linkblog) plugin installed, this will also change languages for your
203
+ `site.articles` and `site.linkposts` loops.
215
204
 
216
205
  ## Contributing
217
206
 
@@ -1,11 +1,14 @@
1
+ require 'octopress-hooks'
2
+
1
3
  require "octopress-multilingual/version"
2
4
  require "octopress-multilingual/set_lang-tag"
3
- require 'octopress-hooks'
5
+ require "octopress-multilingual/hooks"
6
+ require "octopress-multilingual/jekyll"
4
7
 
5
8
  module Octopress
6
9
  module Multilingual
7
10
  extend self
8
- attr_accessor :site, :posts
11
+ attr_accessor :site
9
12
 
10
13
  def main_language
11
14
  if @lang ||= site.config['lang']
@@ -16,18 +19,19 @@ module Octopress
16
19
  << " lang: en\n\n"
17
20
  end
18
21
  end
19
-
22
+
20
23
  def languages
21
24
  posts_by_language.keys
22
25
  end
23
26
 
24
27
  def posts_by_language
25
- @posts_by_language ||= begin
26
- posts = site.posts.reverse.select(&:lang).group_by(&:lang) \
28
+ @posts_by_language ||= begin
29
+ posts = site.posts.reverse.select(&:lang).group_by(&:lang)
27
30
  ## Add posts that crosspost to all languages
28
- .each do |lang, posts|
31
+
32
+ posts.each do |lang, lang_posts|
29
33
  if lang != main_language
30
- posts.concat(crossposts).sort_by!(&:date).reverse!
34
+ lang_posts.concat(crossposts).sort_by!(&:date).reverse!
31
35
  end
32
36
  end
33
37
 
@@ -37,17 +41,13 @@ module Octopress
37
41
  end
38
42
  end
39
43
 
40
- def main_language_posts
41
- site.posts.reverse.reject do |post|
42
- post.lang && post.lang != main_language
43
- end
44
+ def crossposts
45
+ site.posts.select(&:language_crosspost)
44
46
  end
45
47
 
46
- def crossposts
47
- @cross_posts ||= begin
48
- posts = site.posts.reverse.select do |post|
49
- post.data['crosspost_languages']
50
- end
48
+ def main_language_posts
49
+ site.posts.reverse.select do |post|
50
+ post.lang.nil? || post.lang == main_language
51
51
  end
52
52
  end
53
53
 
@@ -55,34 +55,8 @@ module Octopress
55
55
  @posts_without_lang ||= site.reject(&:lang)
56
56
  end
57
57
 
58
- def site_payload
59
- if defined?(Octopress::Docs) && Octopress::Docs.enabled?
60
- {}
61
- else
62
- return unless main_language
63
-
64
- @payload ||= begin
65
- payload = {
66
- 'posts' => main_language_posts,
67
- 'posts_by_language' => posts_by_language,
68
- 'languages' => languages
69
- }
70
-
71
- if defined? Octopress::Linkblog
72
- payload.merge!({
73
- 'linkposts' => linkposts_by_language[main_language],
74
- 'articles' => articles_by_language[main_language],
75
- 'linkposts_by_language' => linkposts_by_language,
76
- 'articles_by_language' => articles_by_language
77
- })
78
- end
79
- payload
80
- end
81
- end
82
- end
83
-
84
58
  def articles_by_language
85
- @articles_by_language ||= begin
59
+ @articles_by_language ||= begin
86
60
  articles = {}
87
61
 
88
62
  languages.each do |lang|
@@ -96,7 +70,7 @@ module Octopress
96
70
  end
97
71
 
98
72
  def linkposts_by_language
99
- @linkposts_by_language ||= begin
73
+ @linkposts_by_language ||= begin
100
74
  linkposts = {}
101
75
 
102
76
  languages.each do |lang|
@@ -109,97 +83,45 @@ module Octopress
109
83
  end
110
84
  end
111
85
 
112
- class SiteHookRead < Hooks::Site
113
- priority :high
114
- # Generate site_payload so other plugins can access
115
- def post_read(site)
116
- Octopress::Multilingual.site = site
117
- end
118
- end
119
-
120
- class SiteHook < Hooks::Site
121
- priority :low
122
-
123
- def merge_payload(payload, site)
124
-
125
- # Group posts by language, { 'en_post' => [posts,..] }
126
- #
127
-
128
- # Ensure that posts without an assigned language
129
- # appear in each language's feed
130
- #
131
-
132
- {
133
- 'site' => Octopress::Multilingual.site_payload,
134
- }
135
- end
136
- end
137
- end
138
- end
139
-
140
- module Jekyll
141
- class URL
142
- def generate_url(template)
143
- @placeholders.inject(template) do |result, token|
144
- break result if result.index(':').nil?
145
- if token.last.nil?
146
- result.gsub(/\/:#{token.first}/, '')
147
- else
148
- result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
149
- end
150
- end
151
- end
152
- end
153
-
154
- class Post
155
- alias :template_orig :template
156
- alias :url_placeholders_orig :url_placeholders
157
-
158
- def template
159
- template = template_orig
86
+ def page_payload(lang)
87
+ payload = { 'posts' => posts_by_language[lang] }
160
88
 
161
- if [:pretty, :none, :date, :ordinal].include? site.permalink_style
162
- template = File.join('/:lang', template)
89
+ # If the octopress-linkblog plugin is installed swap out articles and linkposts
90
+ #
91
+ if defined? Octopress::Linkblog
92
+ payload['linkposts'] = linkposts_by_language[lang]
93
+ payload['articles'] = articles_by_language[lang]
163
94
  end
164
95
 
165
- template
96
+ payload
166
97
  end
167
98
 
168
- def lang
169
- data['lang'].downcase if data['lang']
170
- end
99
+ def site_payload
100
+ # Skip when when showing documentation site
101
+ if defined?(Octopress::Docs) && Octopress::Docs.enabled?
102
+ {}
103
+ else
104
+ return unless main_language
171
105
 
172
- def url_placeholders
173
- url_placeholders_orig.merge({
174
- :lang => lang
175
- })
176
- end
106
+ @payload ||= begin
107
+ payload = {
108
+ 'posts_by_language' => posts_by_language,
109
+ 'languages' => languages
110
+ }
177
111
 
178
- def next
179
- language = lang || site.config['lang']
180
- posts = Octopress::Multilingual.posts_by_language[language]
181
- pos = posts.index {|post| post.equal?(self) }
182
- if pos && pos < posts.length - 1
183
- posts[pos + 1]
184
- else
185
- nil
186
- end
187
- end
112
+ if defined? Octopress::Linkblog
113
+ payload['linkposts_by_language'] = linkposts_by_language
114
+ payload['articles_by_language'] = articles_by_language
115
+ end
188
116
 
189
- def previous
190
- language = lang || site.config['lang']
191
- posts = Octopress::Multilingual.posts_by_language[language]
192
- pos = posts.index {|post| post.equal?(self) }
193
- if pos && pos > 0
194
- posts[pos - 1]
195
- else
196
- nil
117
+ payload
118
+ end
197
119
  end
198
120
  end
199
-
200
121
  end
201
122
  end
202
123
 
124
+
203
125
  if defined? Octopress::Docs
204
126
  Octopress::Docs.add({
205
127
  name: "Octopress Multilingual",
@@ -0,0 +1,34 @@
1
+ module Octopress
2
+ module Multilingual
3
+ class SiteHookRead < Hooks::Site
4
+ priority :high
5
+ # Generate site_payload so other plugins can access
6
+ def post_read(site)
7
+ Octopress::Multilingual.site = site
8
+ end
9
+ end
10
+
11
+ class SiteHook < Hooks::Site
12
+ # Use a low priority so that other hooks can act on posts
13
+ # without having to be designed for mutlilingual sites.
14
+ priority :high
15
+
16
+ #
17
+ def merge_payload(payload, site)
18
+ { 'site' => Octopress::Multilingual.site_payload }
19
+ end
20
+ end
21
+
22
+ class PagePayloadHook < Hooks::All
23
+ priority :high
24
+
25
+ # Swap out post arrays with posts of the approrpiate language
26
+ #
27
+ def merge_payload(payload, item)
28
+ if item.lang
29
+ { 'site' => Octopress::Multilingual.page_payload(item.lang) }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,94 @@
1
+ module Jekyll
2
+ class URL
3
+ def generate_url(template)
4
+ @placeholders.inject(template) do |result, token|
5
+ break result if result.index(':').nil?
6
+ if token.last.nil?
7
+ result.gsub(/\/:#{token.first}/, '')
8
+ else
9
+ result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ class Document
16
+ def lang
17
+ if data['lang']
18
+ data['lang'].downcase
19
+ end
20
+ end
21
+ end
22
+
23
+ class Page
24
+ def lang
25
+ if data['lang']
26
+ if data['lang'].downcase == 'default'
27
+ data['lang'] == site.lang
28
+ end
29
+ data['lang'].downcase
30
+ end
31
+ end
32
+ end
33
+
34
+ class Post
35
+ alias :template_orig :template
36
+ alias :url_placeholders_orig :url_placeholders
37
+
38
+ def template
39
+ template = template_orig
40
+
41
+ if [:pretty, :none, :date, :ordinal].include? site.permalink_style
42
+ template = File.join('/:lang', template)
43
+ end
44
+
45
+ template
46
+ end
47
+
48
+ def lang
49
+ if data['lang']
50
+ if data['lang'].downcase == 'all'
51
+ @language_crosspost = true
52
+ data['lang'] = site.config['lang']
53
+ end
54
+ data['lang'].downcase
55
+ end
56
+ end
57
+
58
+ def language_crosspost
59
+ @language_crosspost if lang
60
+ end
61
+
62
+ def url_placeholders
63
+
64
+ url_placeholders_orig.merge({
65
+ :lang => lang
66
+ })
67
+ end
68
+
69
+ def next
70
+ language = lang || site.config['lang']
71
+ posts = Octopress::Multilingual.posts_by_language[language]
72
+
73
+ pos = posts.index {|post| post.equal?(self) }
74
+ if pos && pos < posts.length - 1
75
+ posts[pos + 1]
76
+ else
77
+ nil
78
+ end
79
+ end
80
+
81
+ def previous
82
+ language = lang || site.config['lang']
83
+ posts = Octopress::Multilingual.posts_by_language[language]
84
+
85
+ pos = posts.index {|post| post.equal?(self) }
86
+ if pos && pos > 0
87
+ posts[pos - 1]
88
+ else
89
+ nil
90
+ end
91
+ end
92
+ end
93
+ end
94
+
@@ -9,35 +9,33 @@ module Octopress
9
9
  end
10
10
 
11
11
  def render(context)
12
- @context = context
13
- @languages = @context['site.languages']
14
- @lang_posts = @context['site.posts_by_language']
15
- main_lang = @context['site.lang']
12
+ @context = context
13
+ @languages = @context['site.languages']
16
14
 
17
- # Render with new posts context
18
- if lang
15
+ # If a language is defined
16
+ if lang && lang != @context['page.lang']
19
17
 
20
- # Set to specified language
21
- set_post_lang lang
22
- set_current_lang(lang)
23
-
24
- # Render
25
- content = super(context)
26
-
27
- # Reset to main language
28
- set_post_lang main_lang
29
- set_current_lang(main_lang)
18
+ store_state # Store current language and post arrays
19
+ set_lang lang # Set to specified language
20
+ content = super(context) # Render
21
+ restore_state # Restore language and post arrays
30
22
 
31
23
  content
32
24
  else
33
- # Tell scope it's in the main
25
+ # If the language argument resovles to nil
26
+ # this will render contents normally
27
+ #
34
28
  super(context)
35
29
  end
36
30
  end
37
31
 
38
- def set_post_lang(lang)
32
+ # Swap out site.posts, site.linkposts, and site.articles with
33
+ # arrays filtered by the selected language
34
+ #
35
+ def set_lang(lang)
36
+ @context.environments.first['page']['lang'] = lang
39
37
  site = @context.environments.first['site']
40
- site['posts'] = @lang_posts[lang]
38
+ site['posts'] = site['posts_by_language'][lang]
41
39
 
42
40
  if defined? Octopress::Linkblog
43
41
  site['linkposts'] = site['linkposts_by_language'][lang]
@@ -45,14 +43,36 @@ module Octopress
45
43
  end
46
44
  end
47
45
 
48
- def set_current_lang(lang)
49
- @context.environments.first['site']['lang'] = lang
46
+ def store_state
47
+ @current_lang = @context['page.lang']
48
+ @posts = @context['site.posts']
49
+
50
+ if defined? Octopress::Linkblog
51
+ @articles = @context['site.articles']
52
+ @links = @context['site.linkposts']
53
+ end
54
+ end
55
+
56
+ def restore_state
57
+ @context.environments.first['page']['lang'] = @current_lang
58
+ site = @context.environments.first['site']
59
+ site['posts'] = @posts
60
+
61
+ if defined? Octopress::Linkblog
62
+ site['linkposts'] = @links
63
+ site['articles'] = @articles
64
+ end
50
65
  end
51
66
 
52
67
  def lang
53
- # If lang is a local variable, read it from the context
54
- lang = [@lang, @context[@lang]].select{|l| @languages.include?(l)}.first
55
- if !lang.nil?
68
+
69
+ # Read tag arguments as a string first, if that fails,
70
+ # Look at the local context, to see if it is a variable
71
+ #
72
+ if lang = [@lang, @context[@lang]].select do |l|
73
+ @languages.include?(l)
74
+ end.first
75
+
56
76
  lang.downcase
57
77
  end
58
78
  end
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Multilingual
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-multilingual
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2015-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octopress-hooks
@@ -119,6 +119,8 @@ files:
119
119
  - LICENSE.txt
120
120
  - README.md
121
121
  - lib/octopress-multilingual.rb
122
+ - lib/octopress-multilingual/hooks.rb
123
+ - lib/octopress-multilingual/jekyll.rb
122
124
  - lib/octopress-multilingual/set_lang-tag.rb
123
125
  - lib/octopress-multilingual/version.rb
124
126
  homepage: https://github.com/octopress/multilingual