jekyll-polyglot 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3ca341e67c10066675cb10c5ded127cf9126c5db547d2f3fdfc3d545c43bd6a
4
- data.tar.gz: 32315c6551ac56da248adb7d465c130d8f0ec4f03a7d589eb5e2081c1a420821
3
+ metadata.gz: 36484f859398f365dc36080eb9a72a170606e0150726a6447349062ee5bbba66
4
+ data.tar.gz: f09be79e1c07abc021f7d16fd6fc52da4f8dd04d0a424557163bebd6be509d99
5
5
  SHA512:
6
- metadata.gz: b53d59e7090b20849d36cdfe6b54a6b0e40e40db839916f1df45c62f26b0ef541f43d30d88c3cbfcd0eb8e58ecc4e45b1f3ae1509cdd2aa0149aad4be41d9a95
7
- data.tar.gz: 12a99dc155b5e4c7ba5f960e0267a90b547fa10576c9c3bf718784f139bf45b0da7554ac40e262b491aa113301eba5d1c16c2bb615fb901d26adf4cee90d0917
6
+ metadata.gz: 3bb811b6db49a5db36edfa1aade491de2cb4c068f8e7a255c9b636a682525fd525a98dedaa83666957b0f539ad51a32c512e2ffd494811b3e36583bd6b078ebd
7
+ data.tar.gz: 002ffded1c695403ce4f9c036facd6235cac6c3e7764a4cf9c33c2a5a383918153283f923b4ee02dcdc34d1b118cf0434595369e7896b33d3dc6d16b58b6a6cd
data/README.md CHANGED
@@ -28,7 +28,7 @@ In your `_config.yml` file, add the following preferences
28
28
  ```YAML
29
29
  languages: ["en", "sv", "de", "fr"]
30
30
  default_lang: "en"
31
- exclude_from_localization: ["javascript", "images", "css", "public", "sitemap"]
31
+ exclude_from_localization: ["javascript", "images", "css", "public", "sitemap", "CNAME"]
32
32
  parallel_localization: true
33
33
  url: https://polyglot.untra.io
34
34
  ```
@@ -59,8 +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 separate language versions of
63
- the website using only the files with the correct `lang` variable in the front matter.
62
+ Organized names will generate consistent permalinks when the post is rendered, and Polyglot will know to build separate language versions of the website using only the files with the correct `lang` variable in the front matter.
64
63
 
65
64
  In short:
66
65
  * Be consistent with how you name and place your *posts* files
@@ -114,6 +113,8 @@ Estos somos nosotros!
114
113
  Additionally, if you are also using the `jekyll-redirect-from` plugin, pages coordinated this way will automatically have redirects created between pages.
115
114
  So `/es/about` will automatically redirect to `/es/acerca-de` and `/acerca-de` can redirect to `/about`. If you use this approach, be sure to also employ a customized [redirect.html](https://github.com/untra/polyglot/blob/main/site/_layouts/redirect.html).
116
115
 
116
+ As of version 1.12, Polyglot also properly supports `redirect_from` frontmatter across sublanguages. When you add redirect paths to pages in non-default languages, Polyglot will correctly scope those redirects to each language's prefix, preventing duplicate redirects and ensuring proper routing.
117
+
117
118
  #### Fallback Language Support
118
119
  Lets say you are building your website. You have an `/about/` page written in *english*, *german* and
119
120
  *swedish*. You are also supporting a *french* website, but you never designed a *french* version of your `/about/` page!
@@ -260,11 +261,48 @@ This plugin stands out from other I18n Jekyll plugins.
260
261
  - provides the liquid tag `{{ site.languages }}` to get an array of your I18n strings.
261
262
  - provides the liquid tag `{{ site.default_lang }}` to get the default_lang I18n string.
262
263
  - provides the liquid tag `{{ site.active_lang }}` to get the I18n language string the website was built for. Alternative names for `active_lang` can be configured via `config.lang_vars`.
264
+ - provides the liquid tag `{{ page.rendered_lang }}` to get the language the page content is actually rendered in (useful for detecting fallback pages).
263
265
  - provides the liquid tag `{{ I18n_Headers }}` to append SEO bonuses to your website.
264
266
  - provides the liquid tag `{{ Unrelativized_Link href="/hello" }}` to make urls that do not get influenced by url correction regexes.
265
267
  - provides `site.data` localization for efficient rich text replacement.
266
268
  - a creator that will answer all of your questions and issues.
267
269
 
270
+ ### Detecting Fallback Pages with `page.rendered_lang`
271
+
272
+ The `page.rendered_lang` variable indicates the actual language of a page's content. This is different from `site.active_lang`, which indicates the language version of the site currently being built.
273
+
274
+ - `site.active_lang`: The language the site is being built for (e.g., `es` for the Spanish site)
275
+ - `page.rendered_lang`: The language of the page's actual content (e.g., `en` if no Spanish translation exists)
276
+
277
+ When `page.rendered_lang != site.active_lang`, the page is a **fallback page** - it's being served in the default language because no translation exists.
278
+
279
+ **Example: Showing a "not translated" notice:**
280
+ ```liquid
281
+ {% if page.rendered_lang != site.active_lang %}
282
+ <div class="translation-notice">
283
+ This page is not yet available in {{ site.active_lang }}.
284
+ Showing {{ page.rendered_lang }} version.
285
+ </div>
286
+ {% endif %}
287
+ ```
288
+
289
+ **Example: Conditional content based on translation status:**
290
+ ```liquid
291
+ {% if page.rendered_lang == site.active_lang %}
292
+ <!-- This is an actual translation -->
293
+ <p>Welcome to our {{ site.active_lang }} content!</p>
294
+ {% else %}
295
+ <!-- This is fallback content -->
296
+ <p>Content available in {{ page.rendered_lang }} only.</p>
297
+ {% endif %}
298
+ ```
299
+
300
+ This is useful for:
301
+ - Displaying notices when content hasn't been translated
302
+ - Tracking translation coverage
303
+ - Applying different styling to fallback pages
304
+ - Building translation status dashboards
305
+
268
306
  ## SEO Recipes
269
307
  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!
270
308
 
@@ -310,6 +348,10 @@ These are talented and considerate software developers across the world that hav
310
348
  * [@obfusk](https://github.com/obfusk) [1.5.0](https://polyglot.untra.io/2021/07/17/polyglot-1.5.0/)
311
349
  * [@eighthave](https://github.com/eighthave) [1.5.0](https://polyglot.untra.io/2021/07/17/polyglot-1.5.0/)
312
350
  * [@george-gca](https://github.com/george-gca) [pt-BR support](https://polyglot.untra.io/pt-BR/2024/02/29/localized-variables.md)
351
+ * [@PanderMusubi](https://github.com/PanderMusubi) - 1.12 / jekyll-minimal-mistakes-polyglot demo
352
+ * [@GruberMarkus](https://github.com/GruberMarkus) - redirect anchor support
353
+ * [@rathboma](https://github.com/rathboma) - page.rendered_lang / sublanguage redirects
354
+ * [@manabu-nakamura](https://github.com/manabu-nakamura) - Japanese strings
313
355
 
314
356
  ### Other Websites Built with Polyglot
315
357
  Feel free to open a PR and list your multilingual blog here you may want to share:
@@ -328,6 +370,7 @@ Feel free to open a PR and list your multilingual blog here you may want to shar
328
370
  * [AnotherTurret just another study note blog](https://aturret.space/)
329
371
  * [Diciotech is a collaborative online tech dictionary](https://diciotech.netlify.app/)
330
372
  * [Yunseo Kim's Study Notes](https://www.yunseo.kim/)
373
+ * [Beekeeper Studio](https://www.beekeeperstudio.io/)
331
374
 
332
375
  ## 2.0 Roadmap
333
376
  * [x] - **site language**: portuguese Brazil `pt-BR`
@@ -338,6 +381,8 @@ Feel free to open a PR and list your multilingual blog here you may want to shar
338
381
  * [x] - **site language**: korean `ko`
339
382
  * [x] - **site language**: hebrew `he`
340
383
  * [x] - **site language**: chinese China `zh-CN`
384
+ * [x] - **site language**: italian `it`
385
+ * [x] - **site language**: turkish `tk`
341
386
  * [ ] - **site language**: chinese Taiwan `zh-TW`
342
387
  * [ ] - **site language**: portuguese Portugal `pt-PT`
343
388
  * [ ] - get whitelisted as an official github-pages jekyll plugin
@@ -18,7 +18,7 @@ module Jekyll
18
18
  permalink_lang = page['permalink_lang']
19
19
  baseurl = site.config['baseurl'] || ''
20
20
  site_url = @url.empty? ? site.config['url'] + baseurl : @url
21
- i18n = "<meta http-equiv=\"Content-Language\" content=\"#{site.active_lang}\">\n"
21
+ i18n = ""
22
22
 
23
23
  # Find all documents with the same page_id
24
24
  docs_with_same_id = site.collections.values
@@ -154,6 +154,9 @@ module Jekyll
154
154
  url = doc.url.gsub(regex, '/')
155
155
  page_id = doc.data['page_id'] || url
156
156
  doc.data['permalink'] = url if doc.data['permalink'].to_s.empty? && !doc.data['lang'].to_s.empty?
157
+ # Set rendered_lang to indicate what language this page is actually rendered in
158
+ # This allows templates to detect fallback pages (rendered_lang != active_lang)
159
+ doc.data['rendered_lang'] = lang
157
160
 
158
161
  # skip entirely if nothing to check
159
162
  next if @file_langs.nil?
@@ -175,22 +178,42 @@ module Jekyll
175
178
  end
176
179
 
177
180
  def assignPageRedirects(doc, docs)
181
+ # Preserve and normalize user-defined redirect_from
182
+ user_redirects = doc.data['redirect_from'] || []
183
+ user_redirects = [user_redirects] unless user_redirects.is_a?(Array)
184
+
185
+ # Determine document language
186
+ doc_lang = doc.data['lang'] || derive_lang_from_path(doc) || @default_lang
187
+
188
+ # Scope user-defined redirects to document's language if non-default
189
+ if doc_lang != @default_lang && !user_redirects.empty?
190
+ user_redirects = user_redirects.map do |redirect_path|
191
+ # Normalize path to start with /
192
+ redirect_path = "/#{redirect_path}" unless redirect_path.start_with?('/')
193
+ # Only prefix if not already prefixed with this language
194
+ if redirect_path.start_with?("/#{doc_lang}/")
195
+ redirect_path
196
+ else
197
+ "/#{doc_lang}#{redirect_path}"
198
+ end
199
+ end
200
+ end
201
+
202
+ # Compute page_id based redirects (cross-language)
203
+ computed_redirects = []
178
204
  pageId = doc.data['page_id']
179
205
  if !pageId.nil? && !pageId.empty?
180
- redirects = []
181
-
182
206
  docs_with_same_id = docs.select { |dd| dd.data['page_id'] == pageId }
183
-
184
- # For each document with the same page_id
185
207
  docs_with_same_id.each do |dd|
186
- # Add redirect if it's a different permalink
187
208
  if dd.data['permalink'] != doc.data['permalink']
188
- redirects << dd.data['permalink']
209
+ computed_redirects << dd.data['permalink']
189
210
  end
190
211
  end
191
-
192
- doc.data['redirect_from'] = redirects
193
212
  end
213
+
214
+ # Merge user-defined and computed redirects, removing duplicates
215
+ all_redirects = (user_redirects + computed_redirects).uniq
216
+ doc.data['redirect_from'] = all_redirects unless all_redirects.empty?
194
217
  end
195
218
 
196
219
  def assignPageLanguagePermalinks(doc, docs)
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.11.0
4
+ version: 1.12.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: 2025-09-20 00:00:00.000000000 Z
11
+ date: 2026-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: 3.1.0
73
73
  requirements: []
74
- rubygems_version: 3.3.7
74
+ rubygems_version: 3.3.27
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: I18n plugin for Jekyll Blogs