Class: Jekyll::L10n::Generator

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll-l10n/jekyll/generator.rb

Overview

Localized Page Generator - Creates locale-prefixed copies of pages during Jekyll build

This is the main Jekyll integration point for the localization plugin. It runs as a low-priority generator during the Jekyll build process, creating duplicate pages for each configured locale. Each localized page inherits content and metadata from the source page but includes locale-prefixed URLs.

Key responsibilities:

  • Identify pages marked for localization (with_locales: true)

  • Extract configured locales from page front matter

  • Create LocalizedPage instances for each locale variant

  • Optimize regeneration by skipping unchanged pages

The generator respects Jekyll’s incremental build mode and only regenerates pages when the source page or configuration has changed, improving rebuild performance.

Examples:

Usage in Jekyll site configuration

# _config.yml
plugins:
  - jekyll-l10n

Marking pages for localization

# src/page.md
---
with_locales: true
with_locales_data:
  locales: [es, fr, pt, de]
---

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ void

This method returns an undefined value.

Generate localized pages for all marked pages in the Jekyll site

This method is automatically called by Jekyll during the generate phase. It iterates through all pages in the site, identifies those marked for localization, and creates locale-specific variants.

Returns early with no output if no pages are marked for localization.

Parameters:

  • site (Jekyll::Site)

    The Jekyll site object containing pages to process

See Also:



50
51
52
53
54
55
# File 'lib/jekyll-l10n/jekyll/generator.rb', line 50

def generate(site)
  return unless any_pages_to_localize?(site)

  Jekyll.logger.info 'Localization', 'Generating localized pages...'
  generate_localized_pages(site)
end