jekyll-polyglot 1.13.0 → 1.14.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: c41fff580d3b7b67c65668954a77168ecf5017f5c0ca7b3747bdcc67ddb7d8ed
4
- data.tar.gz: 6666fb42d87a589c695229be0386cdd601511aee2115c6da472f2de3b829c8ef
3
+ metadata.gz: 431827884e33750d9871432f109f15ef806adc3c92ac12d69b4dd71d7f5b8c26
4
+ data.tar.gz: fbd2aa987e77785d37ad5578ef06b78fdd6f8de30e65007886c13f782605b51c
5
5
  SHA512:
6
- metadata.gz: 446131b28c107601f59f17e4d630c800c6c6b4c64290f00ecf417c407cfd1e3bb960f36a1994d84d7b438cd862d358216090556f198b89ab31a1f6043f842bc9
7
- data.tar.gz: 4902c0e1a8de5060c667eade6806a3e3932eae52475c1a0ad1f4cb5fcb984086080e4c08bf7551eb923098c152e6a46ffe7d63475ec27f9acbe948bee48d8adb
6
+ metadata.gz: 6b28158712094d6870f20bec2882608de81f0188087a8c609da85a6fd7c94f2a12769a220448696984e2464d34b9eadacdd55732b4a84e767d812d153bf69cb5
7
+ data.tar.gz: 9280111b1d14364adf562230d8e84512224ad880c88d9797771ce9fdaf3a5fe474ba803b9cfb691687f81ea92b9d21b4bcd90b3a7950d1d2b46268f666081c4d
data/README.md CHANGED
@@ -30,13 +30,14 @@ languages: ["en", "sv", "de", "fr"]
30
30
  default_lang: "en"
31
31
  exclude_from_localization: ["javascript", "images", "css", "public", "sitemap", "CNAME"]
32
32
  parallel_localization: true
33
+ serial_default_lang: true
33
34
  url: https://polyglot.untra.io
34
35
  ```
35
36
  These configuration preferences indicate
36
37
  - what i18n languages you wish to support
37
38
  - what is your default "fallback" language for your content
38
39
  - what root level files/folders are excluded from localization, based 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.)
39
- - whether to run language processing in parallel or serial. Set to `false` if building on Windows hosts, or if Polyglot collides with other Jekyll plugins.
40
+ - whether to run language processing in parallel or serial. Set to `false` if building on Windows hosts, or if Polyglot collides with other Jekyll plugins. - If `parallel_localization` collides with other jekyll plugins, this setting makes polyglot build the default language first before processing the other language sites.
40
41
  - your jekyll website production url. Make sure this value is set; Polyglot requires this to relative site urls correctly, and to make functioning language switchers.
41
42
 
42
43
  The optional `lang_from_path: true` option enables getting the page language from a filepath segment seperated by `/` or `.`, e.g `de/first-one.md`, or `_posts/zh_HK/use-second-segment.md` , if the lang frontmatter isn't defined.
@@ -461,7 +462,7 @@ These are talented and considerate software developers across the world that hav
461
462
  * [@george-gca](https://github.com/george-gca) [pt-BR support](https://polyglot.untra.io/pt-BR/2024/02/29/localized-variables.md)
462
463
  * [@PanderMusubi](https://github.com/PanderMusubi) - 1.12 / jekyll-minimal-mistakes-polyglot demo
463
464
  * [@GruberMarkus](https://github.com/GruberMarkus) - redirect anchor support
464
- * [@rathboma](https://github.com/rathboma) - page.rendered_lang / sublanguage redirects
465
+ * [@rathboma](https://github.com/rathboma) - page.rendered_lang / sublanguage redirects / serial_default_lang
465
466
  * [@manabu-nakamura](https://github.com/manabu-nakamura) - Japanese strings
466
467
 
467
468
  ### Other Websites Built with Polyglot
@@ -496,10 +497,12 @@ Feel free to open a PR and list your multilingual blog here you may want to shar
496
497
  * [x] - **site language**: turkish `tk`
497
498
  * [x] - **site language**: ukrainian `uk`
498
499
  * [x] - **site language**: hindi `hi`
499
- * [ ] - **site language**: chinese Taiwan `zh-TW`
500
- * [ ] - **site language**: portuguese Portugal `pt-PT`
501
- * [ ] - get whitelisted as an official github-pages jekyll plugin
500
+ * [x] - **site language**: chinese Taiwan `zh-TW`
501
+ * [x] - **site language**: portuguese Portugal `pt-PT`
502
502
  * [x] - update CI provider
503
+ * [ ] - get to 512 github stars
504
+ * [ ] - get whitelisted as an official github-pages jekyll plugin
505
+
503
506
 
504
507
  ## Copyright
505
508
  Copyright (c) Samuel Volin 2025. License: MIT
@@ -3,13 +3,14 @@ require 'etc'
3
3
  include Process
4
4
  module Jekyll
5
5
  class Site
6
- attr_reader :default_lang, :languages, :exclude_from_localization, :lang_vars, :lang_from_path, :fallback_canonical_to_default_lang
6
+ attr_reader :default_lang, :languages, :exclude_from_localization, :lang_vars, :lang_from_path, :fallback_canonical_to_default_lang, :serial_default_lang
7
7
  attr_accessor :file_langs, :active_lang
8
8
 
9
9
  def prepare
10
10
  @file_langs = {}
11
11
  fetch_languages
12
12
  @parallel_localization = config.fetch('parallel_localization', true)
13
+ @serial_default_lang = config.fetch('serial_default_lang', false)
13
14
  @lang_from_path = config.fetch('lang_from_path', false)
14
15
  @fallback_canonical_to_default_lang = config.fetch('fallback_canonical_to_default_lang', false)
15
16
  @exclude_from_localization = config.fetch('exclude_from_localization', []).map do |e|
@@ -34,14 +35,21 @@ module Jekyll
34
35
  prepare
35
36
  all_langs = ([@default_lang] + @languages).uniq
36
37
  if @parallel_localization
38
+ if @serial_default_lang
39
+ # Run the default language in the parent first to prime
40
+ process_language @default_lang
41
+ langs_to_fork = @languages - [@default_lang]
42
+ else
43
+ langs_to_fork = all_langs
44
+ end
37
45
  nproc = Etc.nprocessors
38
46
  pids = {}
39
47
  begin
40
- all_langs.each do |lang|
48
+ langs_to_fork.each do |lang|
41
49
  pids[lang] = fork do
42
50
  process_language lang
43
51
  end
44
- while pids.length >= (lang == all_langs[-1] ? 1 : nproc)
52
+ while pids.length >= (lang == langs_to_fork[-1] ? 1 : nproc)
45
53
  sleep 0.1
46
54
  pids.map do |pid_lang, pid|
47
55
  next unless waitpid pid, Process::WNOHANG
@@ -52,7 +60,7 @@ module Jekyll
52
60
  end
53
61
  end
54
62
  rescue Interrupt
55
- all_langs.each do |lang|
63
+ langs_to_fork.each do |lang|
56
64
  next unless pids.key? lang
57
65
 
58
66
  puts "Killing #{pids[lang]} : #{lang}"
@@ -154,12 +162,7 @@ module Jekyll
154
162
  explicit_lang = doc.data['lang'] || derive_lang_from_path(doc)
155
163
  lang = explicit_lang || @default_lang
156
164
 
157
- # FILTER: Skip documents whose explicit lang is not in configured languages.
158
- # Check the explicit value (not the fallback) so that documents with an
159
- # unconfigured lang like 'de' are excluded even if normalization would
160
- # map them to default_lang. Compare case-insensitively so case-mismatched
161
- # frontmatter (e.g. 'pt-br' vs configured 'pt-BR') is normalized below
162
- # rather than rejected here.
165
+ # Skip documents whose explicit lang is not in configured languages.
163
166
  if explicit_lang && valid_languages.none? { |l| l.downcase == explicit_lang.downcase }
164
167
  Jekyll.logger.warn "Polyglot:", "Skipping #{doc.relative_path} - lang '#{explicit_lang}' not in configured languages #{valid_languages.inspect}"
165
168
  next
@@ -211,11 +214,12 @@ module Jekyll
211
214
  user_redirects = user_redirects.map do |redirect_path|
212
215
  # Normalize path to start with /
213
216
  redirect_path = "/#{redirect_path}" unless redirect_path.start_with?('/')
214
- # Only prefix if not already prefixed with this language
215
- if redirect_path.start_with?("/#{doc_lang}/")
216
- redirect_path
217
+ if redirect_path == "/#{doc_lang}"
218
+ '/'
219
+ elsif redirect_path.start_with?("/#{doc_lang}/")
220
+ redirect_path.delete_prefix("/#{doc_lang}")
217
221
  else
218
- "/#{doc_lang}#{redirect_path}"
222
+ redirect_path
219
223
  end
220
224
  end
221
225
  end
@@ -305,7 +309,10 @@ module Jekyll
305
309
  non_rel_regex = relative_url_regex(true)
306
310
  non_abs_regex = absolute_url_regex(url, true)
307
311
  docs.each do |doc|
308
- unless @active_lang == @default_lang then relativize_urls(doc, rel_regex) end
312
+ unless @active_lang == @default_lang || doc.output.nil?
313
+ localize_redirect_target(doc)
314
+ relativize_urls(doc, rel_regex)
315
+ end
309
316
  correct_nonrelativized_urls(doc, non_rel_regex)
310
317
  if url
311
318
  unless @active_lang == @default_lang then relativize_absolute_urls(doc, abs_regex, url) end
@@ -314,6 +321,26 @@ module Jekyll
314
321
  end
315
322
  end
316
323
 
324
+ # jekyll-redirect-from renders its target into (script location=, meta refresh url=)
325
+ # rewrite the redirect target before language lookaheads in the href regexes skip
326
+ def localize_redirect_target(doc)
327
+ return if @active_lang == @default_lang || doc.output.nil?
328
+
329
+ redirect = doc.data['redirect']
330
+ return unless redirect.is_a?(Hash)
331
+
332
+ target = redirect['to'].to_s
333
+ origin = "#{config['url']}#{@baseurl}"
334
+ return unless target.start_with?("#{origin}/")
335
+
336
+ path = target.delete_prefix(origin)
337
+ return if path.start_with?("/#{@active_lang}/")
338
+
339
+ localized = "#{origin}/#{@active_lang}#{path}"
340
+ doc.output = doc.output.gsub(target, localized)
341
+ redirect['to'] = localized
342
+ end
343
+
317
344
  # a regex that matches urls or permalinks with i18n prefixes or suffixes
318
345
  # matches /en/foo , .en/foo , foo.en/ and other simmilar default urls
319
346
  # made by jekyll when parsing documents without explicitly set permalinks
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.13.0
4
+ version: 1.14.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: 2026-05-16 00:00:00.000000000 Z
11
+ date: 2026-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -65,14 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.1.0
68
+ version: 3.2.0
69
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: 3.1.0
73
+ version: 3.2.0
74
74
  requirements: []
75
- rubygems_version: 3.3.27
75
+ rubygems_version: 3.4.19
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: I18n plugin for Jekyll Blogs