Class: Jekyll::L10n::PostWriteHtmlReprocessor
- Inherits:
-
Object
- Object
- Jekyll::L10n::PostWriteHtmlReprocessor
- 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
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(site) ⇒ PostWriteHtmlReprocessor
constructor
Initialize a new PostWriteHtmlReprocessor.
-
#reprocess_localized_pages ⇒ void
Reprocess all localized pages with translations.
Constructor Details
#initialize(site) ⇒ PostWriteHtmlReprocessor
Initialize a new PostWriteHtmlReprocessor.
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
#site ⇒ Object (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_pages ⇒ void
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 |