Class: Fastlane::Helper::PoFileGenerator
- Inherits:
-
Object
- Object
- Fastlane::Helper::PoFileGenerator
- 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.
Instance Method Summary collapse
-
#generate ⇒ String
Generates the PO file content as a string.
-
#initialize(release_version:, source_files:) ⇒ PoFileGenerator
constructor
A new instance of PoFileGenerator.
-
#write(output_path) ⇒ Object
Writes the generated PO content to a file.
Constructor Details
#initialize(release_version:, source_files:) ⇒ PoFileGenerator
Returns a new instance of PoFileGenerator.
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
#generate ⇒ String
Generates the PO file content as a string
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
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 |