Module: Jekyll::L10n::XPathReferenceGenerator

Defined in:
lib/jekyll-l10n/utils/xpath_reference_generator.rb

Overview

Generates file location references for extracted strings.

XPathReferenceGenerator creates location references for extracted translatable strings in the format “file_path:line_number”. These references appear as comments in PO files to help translators locate text in the original source. Note: Despite the module name, these are file location references, not XPath expressions.

Key responsibilities:

  • Generate location references from DOM nodes

  • Include file path and line number

  • Format references for PO file comments

Examples:

ref = XPathReferenceGenerator.generate(node, 'docs/index.html', '_site')
# Returns 'docs/index.html:42' (42 is line number in HTML)

Class Method Summary collapse

Class Method Details

.generate(node, file_path, dest, _attr_name = nil) ⇒ String

Generate a reference for an extracted string.

Creates a reference in the format “file_path:line_number” for use as a PO file comment marking where a string was extracted from.

Parameters:

  • node (Nokogiri::XML::Node)

    DOM node where string was found

  • file_path (String)

    Path to HTML file being processed

  • dest (String)

    Destination directory (stripped to get relative path)

  • _attr_name (String, nil) (defaults to: nil)

    Optional attribute name (defaults to nil; maintained for API compatibility)

Returns:

  • (String)

    Reference in format “relative_path:line_number”



37
38
39
40
41
42
# File 'lib/jekyll-l10n/utils/xpath_reference_generator.rb', line 37

def generate(node, file_path, dest, _attr_name = nil)
  relative_path = UrlPathBuilder.relative_path(file_path, dest)
  line_number = node.line.to_s

  "#{relative_path}:#{line_number}"
end