octopress-multilingual 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +11 -2
- data/lib/octopress-multilingual/hooks.rb +14 -8
- data/lib/octopress-multilingual/version.rb +1 -1
- data/lib/octopress-multilingual.rb +40 -7
- 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: 981b8a85ae89b0b5e014752f4a7aa40f91e7fb57
|
4
|
+
data.tar.gz: f072ab8273a2e0768b726c6fd842d67bd3df279d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca81dc779eca08eee26031d3a211916c13f8c0a4b5b7702abfc190c01215c9804b6e53e3fdb4ae70cd343bbd57d3ef89bae1c85f8465389517c69da112314404
|
7
|
+
data.tar.gz: 372f2fff3287ce3498303f0cc9af335d1638d43ea0c593cab5665e07a4b2fe44701284d671fb93c5ae3b42c41c0fa6e1e87849969629005da42834970f7015a9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,7 @@ Add multiple language features to your Jekyll site. This plugin makes it easy to
|
|
7
7
|
- Use language in your permalinks.
|
8
8
|
- Cross-post a single post to all languages.
|
9
9
|
- Add translation dictionaries to simplify site templates.
|
10
|
+
- Tag and category indexes are automatically filtered by language.
|
10
11
|
|
11
12
|
[![Build Status](http://img.shields.io/travis/octopress/multilingual.svg)](https://travis-ci.org/octopress/multilingual)
|
12
13
|
[![Gem Version](http://img.shields.io/gem/v/octopress-multilingual.svg)](https://rubygems.org/gems/octopress-multilingual)
|
@@ -43,13 +44,20 @@ Note: First-party Octopress plugins are designed to support multilingual sites b
|
|
43
44
|
|
44
45
|
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/).
|
45
46
|
|
47
|
+
## Helpful Plugins
|
48
|
+
|
49
|
+
These plugins automatically add multilingual features to your site when used with Octopress Multilingual.
|
50
|
+
|
51
|
+
- [Octopress Linkblog](https://github.com/octopress/linkblog) adds link-blogging indexes (articles-only, links-only) and feeds for each language.
|
52
|
+
- [Octopress Feeds](https://github.com/octopress/feeds) adds RSS feeds for each language.
|
53
|
+
|
46
54
|
## Setup
|
47
55
|
|
48
56
|
When adding this plugin to your site, you will need to:
|
49
57
|
|
50
58
|
1. Configure your site's main language, e.g. `lang: en`.
|
51
59
|
2. Add a language to the YAML front-matter of your posts, e.g. `lang: de`.
|
52
|
-
3. Add
|
60
|
+
3. Add post indexes and RSS feeds for secondary languages.
|
53
61
|
|
54
62
|
First, be sure to configure your Jekyll site's main language. An site written primarily in English would add this to its Jekyll configuration:
|
55
63
|
|
@@ -112,7 +120,8 @@ lang: en
|
|
112
120
|
If your default post index is at `/index.html` you should create additional indexes for each secondary language. If you also write in German, you can create a posts index at `/de/index.html`. This approach will work for post archives and RSS feeds, though if you are using [octopress-feeds](https://github.com/octopress/feeds), RSS feeds for each language will be generated automatically.
|
113
121
|
|
114
122
|
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
|
115
|
-
have its posts filtered to display only matching languages.
|
123
|
+
have its posts filtered to display only matching languages. This also works for `site.categories` and `site.tags`.
|
124
|
+
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.
|
116
125
|
|
117
126
|
## Site template language dictionaries
|
118
127
|
|
@@ -12,14 +12,12 @@ module Octopress
|
|
12
12
|
|
13
13
|
# Add translation page data to each page or post.
|
14
14
|
#
|
15
|
-
[site.pages, site.posts].flatten.each do |item|
|
16
|
-
|
17
|
-
|
18
|
-
item.
|
19
|
-
|
20
|
-
|
21
|
-
})
|
22
|
-
end
|
15
|
+
[site.pages, site.posts].flatten.select(&:translated).each do |item|
|
16
|
+
# Access array of translated items via (post/page).translations
|
17
|
+
item.data.merge!({
|
18
|
+
'translations' => item.translations,
|
19
|
+
'translated' => item.translated
|
20
|
+
})
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
@@ -45,6 +43,14 @@ module Octopress
|
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
46
|
+
# Override deep_merge to prevent categories and tags from being combined when they shouldn't
|
47
|
+
#
|
48
|
+
def deep_merge_payload(page_payload, hook_payload)
|
49
|
+
%w{site page}.each do |key|
|
50
|
+
hook_payload[key] = page_payload[key].merge(hook_payload[key] || {})
|
51
|
+
end
|
52
|
+
hook_payload
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
@@ -134,12 +134,43 @@ module Octopress
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
def metadata_index_by_language(index)
|
138
|
+
# Get site categories or tags
|
139
|
+
site_indexes = site.send(index)
|
140
|
+
|
141
|
+
indexes = {}
|
142
|
+
|
143
|
+
# Filter indexes for each language
|
144
|
+
languages.each do |lang|
|
145
|
+
indexes[lang] = {}
|
146
|
+
site_indexes.each do |index, posts|
|
147
|
+
posts = posts.select do |p|
|
148
|
+
p.lang == lang || (lang == main_language && p.lang.nil?) || p.crosspost_languages
|
149
|
+
end
|
150
|
+
|
151
|
+
indexes[lang][index] = posts unless posts.empty?
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
indexes
|
156
|
+
end
|
157
|
+
|
158
|
+
def categories_by_language
|
159
|
+
@categories ||= metadata_index_by_language(:categories)
|
160
|
+
end
|
161
|
+
|
162
|
+
def tags_by_language
|
163
|
+
@tags ||= metadata_index_by_language(:tags)
|
164
|
+
end
|
165
|
+
|
137
166
|
def page_payload(lang)
|
138
167
|
payload = {
|
139
168
|
'site' => {
|
140
|
-
'posts'
|
141
|
-
'linkposts'
|
142
|
-
'articles'
|
169
|
+
'posts' => posts_by_language[lang],
|
170
|
+
'linkposts' => linkposts_by_language[lang],
|
171
|
+
'articles' => articles_by_language[lang],
|
172
|
+
'categories' => categories_by_language[lang],
|
173
|
+
'tags' => tags_by_language[lang]
|
143
174
|
},
|
144
175
|
'lang' => lang_dict[lang]
|
145
176
|
}
|
@@ -155,10 +186,12 @@ module Octopress
|
|
155
186
|
if main_language
|
156
187
|
@payload ||= {
|
157
188
|
'site' => {
|
158
|
-
'posts_by_language'
|
159
|
-
'linkposts_by_language'
|
160
|
-
'articles_by_language'
|
161
|
-
'
|
189
|
+
'posts_by_language' => posts_by_language,
|
190
|
+
'linkposts_by_language' => linkposts_by_language,
|
191
|
+
'articles_by_language' => articles_by_language,
|
192
|
+
'categories_by_language' => categories_by_language,
|
193
|
+
'tags_by_language' => tags_by_language,
|
194
|
+
'languages' => languages
|
162
195
|
},
|
163
196
|
'lang' => lang_dict[main_language]
|
164
197
|
}
|
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: 1.0
|
4
|
+
version: 1.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-02-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octopress-hooks
|