jekyll-language-plugin 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +2 -0
- data/README.md +8 -126
- data/lib/jekyll-language-plugin.rb +18 -0
- data/lib/jekyll/language_document.rb +4 -6
- data/lib/jekyll/language_page.rb +4 -6
- data/lib/jekyll/readers/language_post_reader.rb +2 -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: ffc4661d6aa87c92218872d982a6930d69132d1b
|
4
|
+
data.tar.gz: 4248aeb04ae839ce437c3fb25d1cd97c886317ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcb4dd807bdecbbbd307a2efd1d78caa3b28d8af0301609750f8f5554509cb7a6de8c7aa76414d26c1e5a4d6844018e3b10ea90acce97fe209e8c886abc7d3f0
|
7
|
+
data.tar.gz: b22e65ac61d034a2fddbaff5f704cb8ae2a122dedc803f7031fca2805bc49240844ed265d25822d4a80fc7c6d2aecaff71b9d20192bf8d05453694b814afb435
|
data/LICENSE.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
+
Copyright (c) 2015 Vincent Wochnik.
|
4
|
+
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
5
7
|
in the Software without restriction, including without limitation the rights
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ And then execute the `bundle` command to install the gem.
|
|
30
30
|
Alternatively, you can also manually install the gem using the following command:
|
31
31
|
|
32
32
|
```
|
33
|
-
$ gem install jekyll-language-plugin
|
33
|
+
$ gem install jekyll-language-plugin
|
34
34
|
```
|
35
35
|
|
36
36
|
After the plugin has been installed successfully, add the following lines to your `_config.yml` in order to tell Jekyll to use the plugin:
|
@@ -40,130 +40,9 @@ gems:
|
|
40
40
|
- jekyll-language-plugin
|
41
41
|
```
|
42
42
|
|
43
|
-
##
|
43
|
+
## Getting Started
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
```
|
48
|
-
language_data: data.lang.%%
|
49
|
-
language_includes_dir: _i18n
|
50
|
-
```
|
51
|
-
|
52
|
-
The first key, `language_data`, tells the plugin where it can find the translation data used by the liquid tag. `%%` is a placeholder for the language name. So, if the language is `en`, the plugin will look into `data.lang.en`. It is entirely up to you how you are structuring your Jekyll data. You can have a file `lang.yml` inside your `_data` directory or you can have a `lang` subdirectory inside your `_data` directory containing `en.yml` or `en.json`.
|
53
|
-
|
54
|
-
## Usage
|
55
|
-
|
56
|
-
Every page or post, that needs to be translated must either have a `language` key or a `languages` array inside its YAML front-matter. Additionally, it may also have an `subset` key which tells the plugin to traverse one step further into the language data. So for example, if `subset` is `home` and the `language_data` configuration setting is `data.lang.%%` and the language is `en`, the plugin will look into `data.lang.en.home` for the translation keys used by the liquid tag. Of course, only pages and layouts can use the translation liquid tag but layouts used by posts can therefore benefit from an `subset`.
|
57
|
-
|
58
|
-
### Example
|
59
|
-
|
60
|
-
This is a page optimized for the language plugin, `home.html`:
|
61
|
-
|
62
|
-
```
|
63
|
-
---
|
64
|
-
layout: default
|
65
|
-
languages:
|
66
|
-
- en
|
67
|
-
- de
|
68
|
-
subset: home
|
69
|
-
---
|
70
|
-
<h1>{% t title %}</h1>
|
71
|
-
<p>{% t description %}</p>
|
72
|
-
```
|
73
|
-
|
74
|
-
`t` is the translation tag. In this case, it will look for `data.lang.en.home.title` and `data.lang.en.home.description` for the English language or `data.lang.de.home.title` and `data.lang.de.home.description` for the German language.
|
75
|
-
|
76
|
-
To have more of a structure for larger projects, languages are divided into subdirectories. For the English language, the data file `_data/lang/en.yml` will look similar to this:
|
77
|
-
|
78
|
-
```
|
79
|
-
---
|
80
|
-
home:
|
81
|
-
title: My example home page
|
82
|
-
description: This is my example home page powered by the Jekyll language plugin.
|
83
|
-
```
|
84
|
-
|
85
|
-
And respectively, the German language data file, `_data/lang/de.yml` looks similar to this:
|
86
|
-
|
87
|
-
```
|
88
|
-
---
|
89
|
-
home:
|
90
|
-
title: Meine Beispielhomepage
|
91
|
-
description: Dies ist meine Beispielhomepage getrieben vom Jekyll-Sprachplugin.
|
92
|
-
```
|
93
|
-
|
94
|
-
Create a new file `_layouts/default.html` which will contain the default layout:
|
95
|
-
|
96
|
-
```
|
97
|
-
<!DOCTYPE html>
|
98
|
-
<html>
|
99
|
-
<head{% if page.language %} lang="{{ page.language }}"{% endif %}>
|
100
|
-
<meta charset="utf-8">
|
101
|
-
<title>{% t title %} | {{ site.title }}</title>
|
102
|
-
</head>
|
103
|
-
<body>
|
104
|
-
{{ content }}
|
105
|
-
<p><small>{% t footnote %} | <a href="{{ site.baseurl }}/en/" title="English">en</a> | <a href="{{ site.baseurl }}/de/" title="German">de</a></small></p>
|
106
|
-
</body>
|
107
|
-
</html>
|
108
|
-
```
|
109
|
-
|
110
|
-
As a side note, if a `subset` is given and the translation liquid tag can not find a key within the given subset of the specified language, it will perform another lookup without the given subset.
|
111
|
-
|
112
|
-
So if `footnote` is common to all pages and posts, it can be placed within the root of each language file. For the English language, add the following to `_data/lang/en.yml`:
|
113
|
-
|
114
|
-
```
|
115
|
-
footnote: Copyright (c) Example home page 2015. All rights reserved.
|
116
|
-
```
|
117
|
-
|
118
|
-
For the German language, add the following line to `_data/lang/de.yml`:
|
119
|
-
|
120
|
-
```
|
121
|
-
footnote: Copyright (c) Beispielhomepage. Alle Rechte vorbehalten.
|
122
|
-
```
|
123
|
-
|
124
|
-
If you now run `jekyll build`, you will obtain two separate `home.html` files in your `_site` directory within the `en` and `de` subdirectories, respectively.
|
125
|
-
|
126
|
-
### Posts
|
127
|
-
|
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
|
-
|
130
|
-
It is recommended not to make excessive use of the liquid tags in posts but instead create a post for each translation.
|
131
|
-
|
132
|
-
## Liquid tags
|
133
|
-
|
134
|
-
Currently, there are two liquid tags provided by this plugin.
|
135
|
-
|
136
|
-
### Translation Liquid tag
|
137
|
-
|
138
|
-
The `t` liquid tag provides a convenient way of accessing language-specific translations from the language data referred to in the configuration file.
|
139
|
-
|
140
|
-
If a `subset` is given by the page's or post's front-matter, `t` will look into the given `subset` of the language specified. Only if the key cannot be found there, it will perform another lookup without traversing into the given subset. This can be useful for common translations like a copyright notice. The key can also be a dot-notation of cascaded keys which are traversed upon lookup.
|
141
|
-
|
142
|
-
*Example*: `{% t homepage_welcome %}` or `{% t homepage.welcome %}`
|
143
|
-
|
144
|
-
### Language-Specific Include Tag
|
145
|
-
|
146
|
-
The `tinclude` liquid tag works just like the Jekyll-standard `include` tag. But unlike `include`, `tinclude` will not look into the `_includes` directory. Instead it will look into the directory specified by the `language_includes_dir` configuration setting, here `_i18n`. Then it travels one subdirectory down for the language name. If you `{% tinclude lorem.txt %}`, `tinclude` will look for the file in `_i18n/en/lorem.txt` if the language is English.
|
147
|
-
|
148
|
-
*Example*: `{% tinclude imprint.html %}`
|
149
|
-
|
150
|
-
### Language-Specific Date Filter
|
151
|
-
|
152
|
-
The `tdate` liquid filter provides localized date-formatting using the day and month names specified in the language data for each language. Note that if you are using this filter, a `date` key must be present for every supported language.
|
153
|
-
|
154
|
-
The `tdate` filter takes one argument, the date format language key. A lookup is performed just like the `t` tag does.
|
155
|
-
|
156
|
-
The following excerpt shows the english date translation:
|
157
|
-
|
158
|
-
```
|
159
|
-
date:
|
160
|
-
abbr_daynames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
161
|
-
daynames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
162
|
-
abbr_monthnames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
163
|
-
monthnames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
164
|
-
```
|
165
|
-
|
166
|
-
*Example*: `{{ post.date | tdate: 'post_date_format' }}`
|
45
|
+
The [repository's wiki][wiki] contains detailed information on how to get [started using the plugin][getting-started].
|
167
46
|
|
168
47
|
# Example Site
|
169
48
|
|
@@ -171,12 +50,15 @@ This repository contains a ready-to-use example site using this plugin in the `e
|
|
171
50
|
|
172
51
|
# Contribute
|
173
52
|
|
174
|
-
Fork this repository, make your changes and then issue a pull request. If you find bugs or have new ideas that you do not want to implement yourself, file
|
53
|
+
Fork this repository, make your changes and then issue a pull request. If you find bugs or have new ideas that you do not want to implement yourself, file a bug report.
|
175
54
|
|
176
55
|
# Copyright
|
177
56
|
|
178
|
-
Copyright (c) Vincent Wochnik
|
57
|
+
Copyright (c) 2015 Vincent Wochnik.
|
58
|
+
|
179
59
|
License: MIT
|
180
60
|
|
181
61
|
[jekyll]: https://github.com/mojombo/jekyll
|
182
62
|
[ruby-gem]: https://rubygems.org/gems/jekyll-language-plugin
|
63
|
+
[wiki]: //github.com/vwochnik/jekyll-language-plugin/wiki
|
64
|
+
[getting-started]: //github.com/vwochnik/jekyll-language-plugin/wiki/Getting-Started
|
@@ -18,3 +18,21 @@ require 'jekyll/tags/language_include.rb'
|
|
18
18
|
Jekyll::Hooks.register :site, :after_reset do |site|
|
19
19
|
site.reader = Jekyll::LanguageReader.new(site)
|
20
20
|
end
|
21
|
+
|
22
|
+
# monkey patch URL.sanitize_url for handling of triple slashes
|
23
|
+
module Jekyll
|
24
|
+
class URL
|
25
|
+
def sanitize_url(in_url)
|
26
|
+
url = in_url \
|
27
|
+
# Remove empty URL segments and every URL segment that consists solely of dots
|
28
|
+
.split('/').reject{ |s| s.empty? || s =~ /^\.+$/ }.join('/') \
|
29
|
+
# Always add a leading slash
|
30
|
+
.gsub(/\A([^\/])/, '/\1')
|
31
|
+
|
32
|
+
# Append a trailing slash to the URL if the unsanitized URL had one
|
33
|
+
url << "/" if in_url.end_with?("/")
|
34
|
+
|
35
|
+
url
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -14,16 +14,14 @@ module Jekyll
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def url_template
|
17
|
-
if language
|
18
|
-
return "/:language" + url_template_orig
|
19
|
-
end
|
17
|
+
return "/:language" + url_template_orig if !language.nil?
|
20
18
|
url_template_orig
|
21
19
|
end
|
22
20
|
|
23
21
|
def url_placeholders
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
url_placeholders_orig.merge!({
|
23
|
+
language: language
|
24
|
+
})
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
data/lib/jekyll/language_page.rb
CHANGED
@@ -14,16 +14,14 @@ module Jekyll
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def template
|
17
|
-
if language
|
18
|
-
return "/:language" + template_orig
|
19
|
-
end
|
17
|
+
return "/:language" + template_orig if !language.nil?
|
20
18
|
template_orig
|
21
19
|
end
|
22
20
|
|
23
21
|
def url_placeholders
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
url_placeholders_orig.merge!({
|
23
|
+
language: language
|
24
|
+
})
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -8,13 +8,8 @@ module Jekyll
|
|
8
8
|
ldocument.read
|
9
9
|
|
10
10
|
languages = ldocument.languages.is_a?(Enumerable) ? ldocument.languages : []
|
11
|
-
if ldocument.language && !languages.include?(ldocument.language)
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
if languages.size == 0
|
16
|
-
return [document]
|
17
|
-
end
|
11
|
+
languages.push(ldocument.language) if ldocument.language && !languages.include?(ldocument.language)
|
12
|
+
return [document] if languages.size == 0
|
18
13
|
|
19
14
|
languages.map do |language|
|
20
15
|
ldocument2 = LanguageDocument.new(document.path, { site: @site, collection: @site.posts })
|
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.
|
4
|
+
version: 1.1.4
|
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-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|