Class: Fastlane::Helper::PoFileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/po_file_generator.rb

Overview

Generates PO/POT files from source text files.

This class generates gettext PO files from a hash of source files, handling special cases like versioned release notes and what’s new entries.

Examples:

Basic usage with file paths

generator = PoFileGenerator.new(
  release_version: '1.0',
  source_files: {
    app_name: '/path/to/name.txt',
    description: '/path/to/desc.txt'
  }
)

With translator comments

generator = PoFileGenerator.new(
  release_version: '1.0',
  source_files: {
    app_store_subtitle: {
      path: '/path/to/subtitle.txt',
      comment: 'translators: Limit to 30 characters!'
    },
    description: '/path/to/desc.txt'  # no comment
  }
)

Instance Method Summary collapse

Constructor Details

#initialize(release_version:, source_files:) ⇒ PoFileGenerator

Returns a new instance of PoFileGenerator.

Parameters:

  • release_version (String)

    The release version (e.g., “1.23”)

  • source_files (Hash)

    A hash mapping keys to file paths (String) or hashes with :path and :comment keys



37
38
39
40
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/po_file_generator.rb', line 37

def initialize(release_version:, source_files:)
  @release_version = release_version
  @source_files = source_files
end

Instance Method Details

#generateString

Generates the PO file content as a string

Returns:

  • (String)

    The generated PO file content



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/po_file_generator.rb', line 44

def generate
  po = GetText::PO.new
  # Disable GetText's internal sorting so we control entry order via our own sort_by(:msgctxt)
  po.order = :none

  # Add standard PO header
  add_header(po)

  # Collect all entries first, then sort by msgctxt for deterministic output
  entries = []
  @source_files.each do |key, value|
    path, comment = extract_path_and_comment(value)
    content = File.read(path)
    entries.concat(create_entries_for_key(key.to_sym, content, comment))
  end

  # Sort entries alphabetically by msgctxt and add to PO
  entries.sort_by(&:msgctxt).each do |entry|
    po[entry.msgctxt, entry.msgid] = entry
  end

  # GetText::PO#to_s doesn't add a trailing newline
  "#{po}\n"
end

#write(output_path) ⇒ Object

Writes the generated PO content to a file

Parameters:

  • output_path (String)

    The path to write to



71
72
73
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/po_file_generator.rb', line 71

def write(output_path)
  File.write(output_path, generate)
end