Class: Jekyll::L10n::PostWriteHtmlReprocessor

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

Overview

Applies translations to localized HTML pages after Jekyll build.

PostWriteHtmlReprocessor finds all localized HTML pages generated by the Generator, loads appropriate translations, applies them using HtmlTranslator, and rewrites the HTML files. It processes pages after Jekyll’s standard build completes, during the post-write phase.

Key responsibilities:

  • Find localized HTML pages in the build output

  • Load page translations (compendium + page-specific)

  • Create HtmlTranslator with proper configuration

  • Apply translations to HTML documents

  • Preserve external link icons from original HTML

  • Write translated HTML back to files

  • Handle errors gracefully with logging

Examples:

reprocessor = PostWriteHtmlReprocessor.new(site)
reprocessor.reprocess_localized_pages
# Reads localized HTML, translates, preserves icons, writes back

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ PostWriteHtmlReprocessor

Initialize a new PostWriteHtmlReprocessor.

Parameters:

  • site (Jekyll::Site)

    Jekyll site object



38
39
40
41
# File 'lib/jekyll-l10n/jekyll/post_write_html_reprocessor.rb', line 38

def initialize(site)
  @site = site
  @dest = SiteConfigAccessor.dest(@site)
end

Instance Attribute Details

#siteObject (readonly)

Returns the value of attribute site.



33
34
35
# File 'lib/jekyll-l10n/jekyll/post_write_html_reprocessor.rb', line 33

def site
  @site
end

Instance Method Details

#reprocess_localized_pagesvoid

This method returns an undefined value.

Reprocess all localized pages with translations.

Finds all localized HTML pages that were written during the Jekyll build, loads their translations, applies translations to text and attributes, preserves external link icon styling from the original HTML, and writes the translated HTML back to disk.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jekyll-l10n/jekyll/post_write_html_reprocessor.rb', line 51

def reprocess_localized_pages
  localized_files = find_localized_html_files
  return if localized_files.empty?

  msg = "Applying translations to #{localized_files.length} localized pages..."
  Jekyll.logger.info 'Localization', msg

  localized_files.each do |html_path, locale, original_url|
    translate_html_file(html_path, locale, original_url)
  end
end