jekyll-polyglot 1.7.0 → 1.8.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
  SHA256:
3
- metadata.gz: ab5c70c038d85dbe9936e2a3bd021d75f860a01c272c2650eb6f77e8b386d141
4
- data.tar.gz: 8d4e4656cbd532277bf708f71fabc3c2b63ee042110862c3aea64ea570434b78
3
+ metadata.gz: 55de36ccc381edcf3d22e5f275b99ceb59a4e684bb528516157963c8ebb41cac
4
+ data.tar.gz: 8bdcc86093ad1c3af1133a05e3993317dc7ced60e74f596acf6934d5a92b7792
5
5
  SHA512:
6
- metadata.gz: 508f349097b516f5d4d7f5e794e1e367ba1a64035191793b184314da8f3b35708047df73bc469a740a6042571b97d91802149f259e81581d741ff88a44bcd389
7
- data.tar.gz: e88b634466df95b6b11c7cc04c8a3b5e1b157bfa1740094e1f2bfae14f1797c1e6d1d40cf80d787a5c8070874f6bf929aa3b86c0607a10811cc09017cd424908
6
+ metadata.gz: fb5bc80fda64369a25f465704993bc914af411ab8f285ee4bf5651ab7f7b036ff495426de44f4c3550aa75fd5d1b85cb21119389c031c36c44c6601daddc73b2
7
+ data.tar.gz: c4f560e754305637589ae43c90d8dbf101ef3283761177db0be579ff3e1d3139e19f1c003d3b3b7f61b7b543a93598a41b1595ec3f6a2dbb7196c59b497e5c14
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/jekyll-polyglot.svg)](https://badge.fury.io/rb/jekyll-polyglot)
4
4
  [![CircleCI](https://circleci.com/gh/untra/polyglot/tree/master.svg?style=svg)](https://circleci.com/gh/untra/polyglot/?branch=master)
5
5
 
6
- __Polyglot__ is a fast, painless, open-source internationalization plugin for [Jekyll](http://jekyllrb.com) blogs. Polyglot is easy to setup and use with any Jekyll project, and it scales to the languages you want to support. With fallback support for missing content, automatic url relativization, and powerful SEO tools, Polyglot allows any multi-language jekyll blog to focus on content without the cruft.
6
+ __Polyglot__ is a fast, painless, open-source internationalization plugin for [Jekyll](http://jekyllrb.com) blogs. Polyglot is easy to set up and use with any Jekyll project, and it scales to the languages you want to support. With fallback support for missing content, automatic url relativization, and powerful SEO tools, Polyglot allows any multi-language jekyll blog to focus on content without the cruft.
7
7
 
8
8
  ## Why?
9
9
  Jekyll doesn't provide native support for multi-language blogs. This plugin was modeled after the [jekyll-multiple-languages-plugin](https://github.com/screeninteraction/jekyll-multiple-languages-plugin), whose implementation I liked, but execution I didn't.
@@ -34,7 +34,7 @@ These configuration preferences indicate
34
34
  - what i18n languages you wish to support
35
35
  - what is your default "fallback" language for your content
36
36
  - what root level files/folders are excluded from localization, based
37
- on if their paths start with any of the excluded regexp substrings. (this is different than the jekyll `exclude: [ .gitignore ]` ; you should `exclude` files and directories in your repo you dont want in your built site at all, and `exclude_from_localization` files and directories you want to see in your built site, but not in your sublanguage sites.)
37
+ on if their paths start with any of the excluded regexp substrings. (this is different from the jekyll `exclude: [ .gitignore ]` ; you should `exclude` files and directories in your repo you dont want in your built site at all, and `exclude_from_localization` files and directories you want to see in your built site, but not in your sublanguage sites.)
38
38
  - whether to run language processing in parallel or serial
39
39
 
40
40
  The optional `lang_from_path: true` option enables getting page
@@ -50,7 +50,7 @@ or whatever appropriate [I18n language code](https://developer.chrome.com/websto
50
50
  the page should build for. And you're done. Ideally, when designing your site, you should
51
51
  organize files by their relative urls.
52
52
 
53
- You can see how the live polyglot website [configures and supports multiple languages](https://github.com/untra/polyglot/blob/master/site/_config.yml#L28-L37), and examples of [community](https://github.com/untra/polyglot/pull/155) [language](https://github.com/untra/polyglot/pull/167) [contributions](https://github.com/untra/polyglot/pull/177).
53
+ You can see how the live Polyglot website [configures and supports multiple languages](https://github.com/untra/polyglot/blob/master/site/_config.yml#L28-L37), and examples of [community](https://github.com/untra/polyglot/pull/155) [language](https://github.com/untra/polyglot/pull/167) [contributions](https://github.com/untra/polyglot/pull/177).
54
54
 
55
55
  Polyglot works by associating documents with similar permalinks to the `lang` specified in their frontmatter. Files that correspond to similar routes should have identical permalinks. If you don't provide a permalink for a post, ___make sure you are consistent___ with how you place and name corresponding files:
56
56
  ```
@@ -59,7 +59,7 @@ _posts/2010-03-01-salad-recipes-sv.md
59
59
  _posts/2010-03-01-salad-recipes-fr.md
60
60
  ```
61
61
 
62
- Organized names will generate consistent permalinks when the post is rendered, and polyglot will know to build seperate language versions of
62
+ Organized names will generate consistent permalinks when the post is rendered, and Polyglot will know to build separate language versions of
63
63
  the website using only the files with the correct `lang` variable in the front matter.
64
64
 
65
65
  In short:
@@ -68,12 +68,27 @@ In short:
68
68
  * Don't overthink it, :wink:
69
69
 
70
70
 
71
+ ### Translation permalink information in page
72
+ _New in 1.8.0_
73
+
74
+ Whenever `page_id` frontmatter properties are used to identify translations, permalink information for the available languages is available in `permalink_lang`.
75
+ This is useful in order to generate language menus and even localization meta information without redirects!
76
+
77
+ Sample code for meta link generation:
78
+ ```
79
+ {% for lang in site.languages %}
80
+ {% capture lang_href %}{{site.baseurl}}/{% if lang != site.default_lang %}{{ lang }}/{% endif %}{% if page.permalink_lang[lang] != '/' %}{{page.permalink_lang[lang]}}{% endif %}{% endcapture %}
81
+ <link rel="alternate" hreflang="{{ lang }}" {% static_href %}href="{{ lang_href }}"{% endstatic_href %} />
82
+ {% endfor %}
83
+ ```
84
+
85
+
71
86
  #### Using different permalinks per language
72
87
  _New in 1.7.0_
73
88
 
74
89
  Optionally, for those who may want different URLs on different languages, translations may be identified by specifying a `page_id` in the frontmatter.
75
90
 
76
- If available, polyglot will use `page_id` to identify the page, and will default to the `permalink` otherwise.
91
+ If available, Polyglot will use `page_id` to identify the page, and will default to the `permalink` otherwise.
77
92
 
78
93
  As an example, you may have an about page located in `/about/` while being in `/acerca-de/` in Spanish just by changing the permalink and specifying a `page_id` that will link the files as translations:
79
94
  ```md
@@ -105,8 +120,8 @@ Lets say you are building your website. You have an `/about/` page written in *e
105
120
 
106
121
  No worries. Polyglot ensures the sitemap of your *english* site matches your *french* site, matches your *swedish* and *german* sites too. In this case, because you specified a `default_lang` variable in your `_config.yml`, all sites missing their languages' counterparts will fallback to your `default_lang`, so content is preserved across different languages of your site.
107
122
 
108
- #### Relativized Local Urls
109
- No need to meticulously manage anchor tags to link to your correct language. Polyglot modifies how pages get written to the site so your *french* links keep vistors on your *french* blog.
123
+ ### Relativized Local Urls
124
+ No need to meticulously manage anchor tags to link to your correct language. Polyglot modifies how pages get written to the site so your *french* links keep visitors on your *french* blog.
110
125
  ```md
111
126
  ---
112
127
  title: au sujet de notre entreprise
@@ -129,8 +144,8 @@ Notice the link `<a href="/fr/menu/">...` directs to the french website.
129
144
 
130
145
  Even if you are falling back to `default_lang` page, relative links built on the *french* site will still link to *french* pages.
131
146
 
132
- #### Relativized Absolute Urls
133
- If you defined a site `url` in your `_config.yaml`, polyglot will automatically relativize absolute links pointing to your website directory:
147
+ ### Relativized Absolute Urls
148
+ If you defined a site `url` in your `_config.yaml`, Polyglot will automatically relativize absolute links pointing to your website directory:
134
149
 
135
150
  ```md
136
151
  ---
@@ -143,7 +158,7 @@ becomes
143
158
  <p>Cliquez <a href="https://mywebsite.com/fr/">ici</a> pour aller à l'entrée du site.
144
159
  ```
145
160
 
146
- #### Disabling Url Relativizing
161
+ ### Disabling Url Relativizing
147
162
  _New in 1.4.0_
148
163
  If you dont want a href attribute to be relativized (such as for making [a language switcher](https://github.com/untra/polyglot/blob/master/site/_includes/sidebar.html#L40)), you can use the block tag:
149
164
 
@@ -159,11 +174,10 @@ that will generate `<a href="/about">click this static link</a>` which is what y
159
174
 
160
175
  Combine with a [html minifier](https://github.com/digitalsparky/jekyll-minifier) for a polished and production ready website.
161
176
 
162
- #### Exclusive site language generation
177
+ ### Exclusive site language generation
163
178
  _New in 1.4.0_
164
179
 
165
- If you want to control which languages a document can be generated for, you can specify `lang-exclusive: [ ]` frontmatter.
166
- If you include this frontmatter in your post, it will only generate for the specified site languages.
180
+ If you want to control which languages a document can be generated for, you can specify `lang-exclusive: [ ]` frontmatter. If you include this frontmatter in your post, it will only generate for the specified site languages.
167
181
 
168
182
  For Example, the following frontmatter will only generate in the `en` and `fr` site language builds:
169
183
  ```
@@ -172,29 +186,73 @@ lang-exclusive: ['en', 'fr']
172
186
  ---
173
187
  ```
174
188
 
175
- #### Machine-aware site building
176
- _New in 1.5.0_
189
+ ### Localized site.data
190
+ There are cases where you may want to have a list of `key: value` pairs of translated content. For example, instead of creating a complete separate file for each language containing the layout structure and localized content, you can create a single file with the layout that will be shared among pages, and then create a language-specific file with the localized content that will be used.
177
191
 
178
- Polyglot will only start builds after it confirms there is a cpu core ready to accept the build thread. This ensures that jekyll will build large sites efficiently, streamlining build processes instead of overloading machines with process thrash.
192
+ To do this, you can create a file like `_data/:lang/strings.yml`, one for each language, and Polyglot will bring those keys under `site.data[:lang].strings`. For example, suppose you have the following files:
179
193
 
180
- #### Localized site.data
194
+ `_data/en/strings.yml`
195
+ ```yaml
196
+ hello: "Hello"
197
+ greetings:
198
+ morning: "Good morning"
199
+ evening: "Good evening"
200
+ ```
181
201
 
182
- There are cases when `site.data` localization is required.
183
- For instance: you might need to localize `_data/navigation.yml` that holds "navigation menu".
184
- In order to localize it, just place language-specific files in `_data/:lang/...` folder, and Polyglot will bring those keys to the top level.
202
+ `_data/pt-br/strings.yml`
203
+ ```yaml
204
+ hello: "Olá"
205
+ greetings:
206
+ morning: "Bom dia"
207
+ evening: "Boa noite"
208
+ ```
209
+
210
+ You can use the `site.data` to access the localized content in your layouts and pages:
211
+
212
+ ```liquid
213
+ <p>{{ site.data[site.active_lang].strings.hello }}, {{ site.data[site.active_lang].strings.greetings.morning }}</p>
214
+ ```
215
+
216
+ For more information on this matter, check out this [post](https://polyglot.untra.io/2024/02/29/localized-variables/).
217
+
218
+ ### Localized collections
219
+
220
+ To localize collections, you first have to properly define the collection in your `_config.yml` file. For example, if you have a collection of `projects`, you can define it like this:
221
+
222
+ ```yaml
223
+ collections:
224
+ projects:
225
+ output: true
226
+ permalink: /:collection/:title/
227
+ ```
228
+
229
+ Note that the [permalink](https://jekyllrb.com/docs/permalinks/#collections) definition here is important. Then, you can create a file for each language in the `_projects` directory, and Polyglot will bring those files under `site.projects`. For more information, check the related discussion #188.
185
230
 
186
231
  ## How It Works
187
232
  This plugin makes modifications to existing Jekyll classes and modules, namely `Jekyll::StaticFile` and `Jekyll::Site`. These changes are as lightweight and slim as possible. The biggest change is in `Jekyll::Site.process`. Polyglot overwrites this method to instead spawn a separate process for each language you intend to process the site for. Each of those processes calls the original `Jekyll::Site.process` method with its language in mind, ensuring your website scales to support any number of languages, while building all of your site languages simultaneously.
188
233
 
189
234
  `Jekyll::Site.process` is the entry point for the Jekyll build process. Take care whatever other plugins you use do not also attempt to overwrite this method. You may have problems.
190
235
 
236
+ ### (:polyglot, :post_write) hook
237
+ _New in 1.8.0_
238
+ Polyglot issues a `:polyglot, :post_write` hook event once all languages have been built for the site. This hook runs exactly once, after all site languages been processed:
239
+
240
+ ```rb
241
+ Jekyll::Hooks.register :polyglot, :post_write do |site|
242
+ # do something custom and cool here!
243
+ end
244
+ ```
245
+
246
+ ### Machine-aware site building
247
+ _New in 1.5.0_
248
+
249
+ Polyglot will only start builds after it confirms there is a cpu core ready to accept the build thread. This ensures that jekyll will build large sites efficiently, streamlining build processes instead of overloading machines with process thrash.
191
250
 
192
251
  ### Writing Tests and Debugging
193
252
  _:wave: I need assistance with modern ruby best practices for test maintenance with rake and rspec. If you got the advice I have the ears._
194
253
 
195
254
  Tests are run with `bundle exec rake`. Tests are in the `/spec` directory, and test failure output detail can be examined in the `rspec.xml` file.
196
255
 
197
-
198
256
  ## Features
199
257
  This plugin stands out from other I18n Jekyll plugins.
200
258
  - automatically corrects your relative links, keeping your *french* visitors on your *french* website, even when content has to fallback to the `default_lang`.
@@ -208,20 +266,11 @@ This plugin stands out from other I18n Jekyll plugins.
208
266
  - a creator that will answer all of your questions and issues.
209
267
 
210
268
  ## SEO Recipes
211
- Jekyll-polyglot has a few spectacular [Search Engine Optimization techniques](https://untra.github.io/polyglot/seo) to ensure your Jekyll blog gets the most out of it's multilingual audience. Check them out!
269
+ Jekyll-polyglot has a few spectacular [Search Engine Optimization techniques](https://untra.github.io/polyglot/seo) to ensure your Jekyll blog gets the most out of its multilingual audience. Check them out!
212
270
 
213
- ### Other Websites Built with Polyglot
214
- Feel free to open a PR and list your multilingual blog here you may want to share:
271
+ ### Sitemap generation
215
272
 
216
- * [Polyglot project website](https://polyglot.untra.io)
217
- * [LogRhythm Corporate Website](https://logrhythm.com)
218
- * [All Over Earth](https://allover.earth/)
219
- * [Hanare Cafe in Toshijima, Japan](https://hanarecafe.com)
220
- * [F-Droid](https://f-droid.org)
221
- * [Ubuntu MATE](https://ubuntu-mate.org)
222
- * [Leo3418 blog](https://leo3418.github.io/)
223
- * [Gaphor](https://gaphor.org)
224
- * [Yi Yunseok's personal blog website](https://Yi-Yunseok.GitHub.io)
273
+ See the example [sitemap.xml](/site/sitemap.xml) and [robots.txt](/site/robots.txt) for how to automatically generate a multi-language sitemap for your page and turn it in for the SEO i18n credit.
225
274
 
226
275
  ## Compatibility
227
276
  Currently supports Jekyll 3.0 , and Jekyll 4.0
@@ -238,10 +287,38 @@ Please! I need all the support I can get! 🙏
238
287
  But for real I would appreciate any code contributions and support. This started as an open-source side-project and has gotten bigger than I'd ever imagine!
239
288
  If you have something you'd like to contribute to jekyll-polyglot, please open a PR!
240
289
 
290
+ ### Contributors
291
+ These are talented and considerate software developers across the world that have lent their support to this project.
292
+ **Thank You! ¡Gracias! Merci! Danke! 감사합니다! תודה רבה! Спасибо! Dankjewel! 谢谢!Obrigado!**
293
+
294
+ * [@jerturowetz](https://github.com/jerturowetz) 1.7.1
295
+ * [@antoniovazquezblanco](https://github.com/antoniovazquezblanco) [1.7.0](https://polyglot.untra.io/2023/10/29/polyglot-1.7.0/)
296
+ * [@salinatedcoffee](https://github.com/SalinatedCoffee) [ko support](https://polyglot.untra.io/2023/02/27/korean-support/)
297
+ * [@aturret](https://github.com/aturret) [zh-CN support](https://polyglot.untra.io/2023/06/08/polyglot-1.6.0-chinese-support/)
298
+ * [@dougieh](https://github.com/dougieh) [1.5.1](https://polyglot.untra.io/2022/10/01/polyglot-1.5.1/)
299
+ * [@pandermusubi](https://github.com/PanderMusubi) [nl support](https://polyglot.untra.io/2022/01/15/dutch-site-support/)
300
+ * [@obfusk](https://github.com/obfusk) [1.5.0](https://polyglot.untra.io/2021/07/17/polyglot-1.5.0/)
301
+ * [@eighthave](https://github.com/eighthave) [1.5.0](https://polyglot.untra.io/2021/07/17/polyglot-1.5.0/)
302
+ * [@george-gca](https://github.com/george-gca) [Localized Variables](https://polyglot.untra.io/2024/02/29/localized-variables.md)
303
+
304
+ ### Other Websites Built with Polyglot
305
+ Feel free to open a PR and list your multilingual blog here you may want to share:
306
+
307
+ * [**Polyglot project website**](https://polyglot.untra.io)
308
+ * [LogRhythm Corporate Website](https://logrhythm.com)
309
+ * [All Over Earth](https://allover.earth/)
310
+ * [Hanare Cafe in Toshijima, Japan](https://hanarecafe.com)
311
+ * [F-Droid](https://f-droid.org)
312
+ * [Ubuntu MATE](https://ubuntu-mate.org)
313
+ * [Leo3418 blog](https://leo3418.github.io/)
314
+ * [Gaphor](https://gaphor.org)
315
+ * [Yi Yunseok's personal blog website](https://Yi-Yunseok.GitHub.io)
316
+ * [Tarlogic Cybersecurity](https://www.tarlogic.com/)
317
+ * [A beautiful, simple, clean, and responsive Jekyll theme for academics](https://github.com/george-gca/multi-language-al-folio)
241
318
 
242
319
  ## 2.0 Roadmap
243
- * [ ] - **site language**: portuguese Brazil `pt-BR` `pt-PT`
244
- * [ ] - **site language**: portuguese Portugal `pt-BR` `pt-PT`
320
+ * [x] - **site language**: portuguese Brazil `pt-BR`
321
+ * [ ] - **site language**: portuguese Portugal `pt-PT`
245
322
  * [ ] - **site language**: arabic `ar`
246
323
  * [ ] - **site language**: japanese `ja`
247
324
  * [x] - **site language**: russian `ru`
@@ -249,7 +326,7 @@ If you have something you'd like to contribute to jekyll-polyglot, please open a
249
326
  * [x] - **site language**: korean `ko`
250
327
  * [x] - **site language**: hebrew `he`
251
328
  * [x] - **site language**: chinese China `zh-CN`
252
- * [ ] - **site language**: chinese Taiwan `zh_TW`
329
+ * [ ] - **site language**: chinese Taiwan `zh-TW`
253
330
  * [ ] - get whitelisted as an official github-pages jekyll plugin
254
331
  * [x] - update CI provider
255
332
 
@@ -12,6 +12,7 @@ module Jekyll
12
12
  def render(context)
13
13
  site = context.registers[:site]
14
14
  permalink = context.registers[:page]['permalink']
15
+ permalink_lang = context.registers[:page]['permalink_lang']
15
16
  site_url = @url.empty? ? site.config['url'] : @url
16
17
  i18n = "<meta http-equiv=\"Content-Language\" content=\"#{site.active_lang}\">\n"
17
18
  i18n += "<link rel=\"alternate\" hreflang=\"#{site.default_lang}\" "\
@@ -19,8 +20,9 @@ module Jekyll
19
20
  site.languages.each do |lang|
20
21
  next if lang == site.default_lang
21
22
 
23
+ url = permalink_lang && permalink_lang[lang] ? permalink_lang[lang] : permalink
22
24
  i18n += "<link rel=\"alternate\" hreflang=\"#{lang}\" "\
23
- "href=\"#{site_url}/#{lang}#{permalink}\"/>\n"
25
+ "href=\"#{site_url}/#{lang}/#{url}\"/>\n"
24
26
  end
25
27
  i18n
26
28
  end
@@ -43,7 +43,10 @@ module Jekyll
43
43
  while pids.length >= (lang == all_langs[-1] ? 1 : nproc)
44
44
  sleep 0.1
45
45
  pids.map do |lang, pid|
46
- pids.delete lang if waitpid pid, Process::WNOHANG
46
+ next unless waitpid pid, Process::WNOHANG
47
+
48
+ pids.delete lang
49
+ raise "Polyglot subprocess #{pid} (#{lang}) failed (#{$?.exitstatus})" unless $?.success?
47
50
  end
48
51
  end
49
52
  end
@@ -60,6 +63,7 @@ module Jekyll
60
63
  process_language lang
61
64
  end
62
65
  end
66
+ Jekyll::Hooks.trigger :polyglot, :post_write
63
67
  end
64
68
 
65
69
  alias site_payload_orig site_payload
@@ -149,6 +153,7 @@ module Jekyll
149
153
  @file_langs[page_id] = lang
150
154
  end
151
155
  approved.values.each {|doc| assignPageRedirects(doc, docs) }
156
+ approved.values.each {|doc| assignPageLanguagePermalinks(doc, docs) }
152
157
  approved.values
153
158
  end
154
159
 
@@ -166,6 +171,20 @@ module Jekyll
166
171
  end
167
172
  end
168
173
 
174
+ def assignPageLanguagePermalinks(doc, docs)
175
+ pageId = doc.data['page_id']
176
+ if !pageId.nil? && !pageId.empty?
177
+ unless doc.data['permalink_lang'] then doc.data['permalink_lang'] = {} end
178
+ permalinkDocs = docs.select do |dd|
179
+ dd.data['page_id'] == pageId
180
+ end
181
+ permalinkDocs.each do |dd|
182
+ doclang = dd.data['lang'] || derive_lang_from_path(dd) || @default_lang
183
+ doc.data['permalink_lang'][doclang] = dd.data['permalink']
184
+ end
185
+ end
186
+ end
187
+
169
188
  # performs any necesarry operations on the documents before rendering them
170
189
  def process_documents(docs)
171
190
  # return if @active_lang == @default_lang
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-polyglot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Volin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-29 00:00:00.000000000 Z
11
+ date: 2024-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll