jekyll-multiple-languages-plugin 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -4
- data/lib/jekyll-multiple-languages-plugin.rb +76 -17
- data/lib/plugin/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f3a2a500acf67ad5bea871232433bab2c4fee41366f0d59864e09256121eecf
|
4
|
+
data.tar.gz: 2c9a1a596557ecd8aea38c07e0607d5e104e4c755b1f41c01fd14b9355d75f30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f94a3062d46cbcfe28d878073e539ebf675494021e16d0bb96297878720a9c8b449f7d4a12b1d04bfc8a717178eb828bf7a15428842e5772412643099d5dbdfd
|
7
|
+
data.tar.gz: 9e11ecf14870bbf6655d0ed407d83409ce87c57880e5ceac803d0236bc56c222b7d1af9cba901861edf23303b3db8a92dcdcc3ef50e3260dfde766a757f71c39
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ Table of Contents
|
|
19
19
|
-----------------
|
20
20
|
- [Jekyll Multiple Languages Plugin](#jekyll-multiple-languages-plugin)
|
21
21
|
- [Badges](#badges)
|
22
|
-
- [!! We are looking for more maintainers !!](
|
22
|
+
- [!! We are looking for more maintainers !!](#-we-are-looking-for-more-maintainers-)
|
23
23
|
- [Table of Contents](#table-of-contents)
|
24
24
|
- [1. Current Release Notice](#1-current-release-notice)
|
25
25
|
- [2. Features](#2-features)
|
@@ -28,7 +28,7 @@ Table of Contents
|
|
28
28
|
- [3.2. Manually](#32-manually)
|
29
29
|
- [3.3. As a Git Submodule](#33-as-a-git-submodule)
|
30
30
|
- [4. Configuration](#4-configuration)
|
31
|
-
- [4.1. _config.yml](#41-
|
31
|
+
- [4.1. _config.yml](#41-_configyml)
|
32
32
|
- [4.2. Folder structure](#42-folder-structure)
|
33
33
|
- [5. Usage](#5-usage)
|
34
34
|
- [5.1. Translating strings](#51-translating-strings)
|
@@ -141,6 +141,12 @@ In code, these specific files should be referenced via `baseurl_root`. E.g.
|
|
141
141
|
<link rel="stylesheet" href="{{ "/css/bootstrap.css" | prepend: site.baseurl_root }}"/>
|
142
142
|
```
|
143
143
|
|
144
|
+
If you wish to avoid having the default_lang built into the root of your website, use:
|
145
|
+
|
146
|
+
```yaml
|
147
|
+
default_locale_in_subfolder: true
|
148
|
+
```
|
149
|
+
|
144
150
|
### 4.2. Folder structure
|
145
151
|
Create a folder called `_i18n` and add sub-folders for each language, using the same names used on the `languages` setting on the `_config.yml`:
|
146
152
|
|
@@ -186,14 +192,36 @@ or
|
|
186
192
|
{% translate global.english %}
|
187
193
|
```
|
188
194
|
|
189
|
-
You can also access translated strings by accessing the `site.translations` hash, this allows you to loop through your translations within Liquid:
|
195
|
+
You can also access translated strings by accessing the `site.translations` hash, this allows you to loop through your translations within Liquid using the translated string's index:
|
190
196
|
|
191
197
|
```liquid
|
192
|
-
{% for item in site.translations[site.lang]
|
198
|
+
{% for item in site.translations[site.lang].my_nested_yaml_collection %}
|
193
199
|
<p>{{ item[0] }} -> {{ item[1] }}</p>
|
194
200
|
{% endfor %}
|
195
201
|
```
|
196
202
|
|
203
|
+
or the translated string's assignment:
|
204
|
+
|
205
|
+
```yaml
|
206
|
+
my_nested_yaml_collection:
|
207
|
+
-
|
208
|
+
title: First
|
209
|
+
message: Message
|
210
|
+
-
|
211
|
+
title: Second
|
212
|
+
message: Message
|
213
|
+
|
214
|
+
```
|
215
|
+
|
216
|
+
```liquid
|
217
|
+
{% for item in site.translations[site.lang].my_nested_yaml_collection %}
|
218
|
+
<li>
|
219
|
+
<h2>{{ item["title"] }}</h2>
|
220
|
+
<p>{{ item["message"] }}</p>
|
221
|
+
</li>
|
222
|
+
{% endfor %}
|
223
|
+
```
|
224
|
+
|
197
225
|
### 5.2. Including translated files
|
198
226
|
The plugin also supports using different markdown files for different languages using the liquid tag:
|
199
227
|
|
@@ -369,6 +397,11 @@ Then, create a file named `about.md` under `_i18n/en` with the English content.
|
|
369
397
|
|
370
398
|
|
371
399
|
## 8. Changelog
|
400
|
+
* 1.7.0
|
401
|
+
* Option to build the default language into a subfolder
|
402
|
+
* Configurable verbosity
|
403
|
+
* Improved documentation
|
404
|
+
* Removed deprecation warning
|
372
405
|
* 1.6.1
|
373
406
|
* Improved testing
|
374
407
|
* Support for Jekyll 4
|
@@ -24,6 +24,46 @@ module Jekyll
|
|
24
24
|
puts "Loading translation from file #{site.source}/_i18n/#{lang}.yml"
|
25
25
|
site.parsed_translations[lang] = YAML.load_file("#{site.source}/_i18n/#{lang}.yml")
|
26
26
|
end
|
27
|
+
|
28
|
+
#*****************************************************************************
|
29
|
+
# :site, :post_write hook
|
30
|
+
#*****************************************************************************
|
31
|
+
Jekyll::Hooks.register :site, :post_write do |site|
|
32
|
+
|
33
|
+
# Moves excluded paths from the default lang subfolder to the root folder
|
34
|
+
#===========================================================================
|
35
|
+
default_lang = site.config["default_lang"]
|
36
|
+
current_lang = site.config["lang"]
|
37
|
+
exclude_paths = site.config["exclude_from_localizations"]
|
38
|
+
|
39
|
+
if (default_lang == current_lang && site.config["default_locale_in_subfolder"])
|
40
|
+
files = Dir.glob(File.join("_site/" + current_lang + "/", "*"))
|
41
|
+
files.each do |file_path|
|
42
|
+
parts = file_path.split('/')
|
43
|
+
f_path = parts[2..-1].join('/')
|
44
|
+
if (f_path == 'base.html')
|
45
|
+
new_path = parts[0] + "/index.html"
|
46
|
+
puts "Moving '" + file_path + "' to '" + new_path + "'"
|
47
|
+
File.rename file_path, new_path
|
48
|
+
else
|
49
|
+
exclude_paths.each do |exclude_path|
|
50
|
+
if (exclude_path == f_path)
|
51
|
+
new_path = parts[0] + "/" + f_path
|
52
|
+
puts "Moving '" + file_path + "' to '" + new_path + "'"
|
53
|
+
if (Dir.exists?(new_path))
|
54
|
+
FileUtils.rm_r new_path
|
55
|
+
end
|
56
|
+
File.rename file_path, new_path
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
#===========================================================================
|
64
|
+
|
65
|
+
end
|
66
|
+
|
27
67
|
Jekyll::Hooks.register :site, :post_render do |site, payload|
|
28
68
|
|
29
69
|
# Removes all static files that should not be copied to translated sites.
|
@@ -34,10 +74,12 @@ module Jekyll
|
|
34
74
|
static_files = payload["site"]["static_files"]
|
35
75
|
exclude_paths = payload["site"]["exclude_from_localizations"]
|
36
76
|
|
77
|
+
default_locale_in_subfolder = site.config["default_locale_in_subfolder"]
|
37
78
|
|
38
79
|
if default_lang != current_lang
|
39
80
|
static_files.delete_if do |static_file|
|
40
|
-
|
81
|
+
next true if (static_file.name == 'base.html' && default_locale_in_subfolder)
|
82
|
+
|
41
83
|
# Remove "/" from beginning of static file relative path
|
42
84
|
if static_file.instance_variable_get(:@relative_path) != nil
|
43
85
|
static_file_r_path = static_file.instance_variable_get(:@relative_path).dup
|
@@ -81,6 +123,8 @@ module Jekyll
|
|
81
123
|
self.parsed_translations ||= {}
|
82
124
|
|
83
125
|
self.config['exclude_from_localizations'] ||= []
|
126
|
+
|
127
|
+
self.config['default_locale_in_subfolder'] ||= false
|
84
128
|
|
85
129
|
if ( !self.config['languages'] or
|
86
130
|
self.config['languages'].empty? or
|
@@ -108,26 +152,20 @@ module Jekyll
|
|
108
152
|
self.config['baseurl_root'] = baseurl_org # Baseurl of website root (without the appended language code)
|
109
153
|
self.config['translations'] = self.parsed_translations # Hash that stores parsed translations read from YAML files. Exposes this hash to Liquid.
|
110
154
|
|
111
|
-
|
112
|
-
# Build the website for default language
|
113
|
-
#-------------------------------------------------------------------------
|
114
|
-
puts "Building site for default language: \"#{self.config['lang']}\" to: #{self.dest}"
|
115
|
-
|
116
|
-
process_org
|
117
|
-
|
118
|
-
|
119
|
-
# Build the website for the other languages
|
155
|
+
# Build the website for all languages
|
120
156
|
#-------------------------------------------------------------------------
|
121
157
|
|
122
158
|
# Remove .htaccess file from included files, so it wont show up on translations folders.
|
123
159
|
self.include -= [".htaccess"]
|
124
160
|
|
125
|
-
languages.
|
161
|
+
languages.each do |lang|
|
126
162
|
|
127
163
|
# Language specific config/variables
|
128
|
-
|
129
|
-
|
130
|
-
|
164
|
+
if lang != self.config['default_lang'] || self.config['default_locale_in_subfolder']
|
165
|
+
@dest = dest_org + "/" + lang
|
166
|
+
self.config['baseurl'] = baseurl_org + "/" + lang
|
167
|
+
self.config['lang'] = lang
|
168
|
+
end
|
131
169
|
|
132
170
|
puts "Building site for language: \"#{self.config['lang']}\" to: #{self.dest}"
|
133
171
|
|
@@ -324,8 +362,10 @@ module Jekyll
|
|
324
362
|
if translation.nil? or translation.empty?
|
325
363
|
translation = site.parsed_translations[site.config['default_lang']].access(key)
|
326
364
|
|
327
|
-
|
328
|
-
|
365
|
+
if site.config["verbose"]
|
366
|
+
puts "Missing i18n key: #{lang}:#{key}"
|
367
|
+
puts "Using translation '%s' from default language: %s" %[translation, site.config['default_lang']]
|
368
|
+
end
|
329
369
|
end
|
330
370
|
|
331
371
|
translation
|
@@ -400,6 +440,25 @@ module Jekyll
|
|
400
440
|
end
|
401
441
|
end
|
402
442
|
end
|
443
|
+
|
444
|
+
# Override of core Jekyll functionality, to get rid of deprecation
|
445
|
+
# warning. See https://github.com/jekyll/jekyll/pull/7117 for more
|
446
|
+
# details.
|
447
|
+
class PostComparer
|
448
|
+
def initialize(name)
|
449
|
+
@name = name
|
450
|
+
|
451
|
+
all, @path, @date, @slug = *name.sub(%r!^/!, "").match(MATCHER)
|
452
|
+
unless all
|
453
|
+
raise Jekyll::Errors::InvalidPostNameError,
|
454
|
+
"'#{name}' does not contain valid date and/or title."
|
455
|
+
end
|
456
|
+
|
457
|
+
escaped_slug = Regexp.escape(slug)
|
458
|
+
@name_regex = %r!_posts/#{path}#{date}-#{escaped_slug}\.[^.]+|
|
459
|
+
^#{path}_posts/?#{date}-#{escaped_slug}\.[^.]+!x
|
460
|
+
end
|
461
|
+
end
|
403
462
|
end
|
404
463
|
|
405
464
|
|
@@ -444,7 +503,7 @@ module Jekyll
|
|
444
503
|
pages = site.pages
|
445
504
|
url = "";
|
446
505
|
|
447
|
-
if default_lang != lang
|
506
|
+
if default_lang != lang || site.config['default_locale_in_subfolder']
|
448
507
|
baseurl = baseurl + "/" + lang
|
449
508
|
end
|
450
509
|
|
data/lib/plugin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-multiple-languages-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Kurtsson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,16 +43,16 @@ dependencies:
|
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 12.3.3
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 12.3.3
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: jekyll
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|