Class: Jekyll::L10n::PoFileMerger
- Inherits:
-
Object
- Object
- Jekyll::L10n::PoFileMerger
- Defined in:
- lib/jekyll-l10n/po_file/merger.rb
Overview
Merges multiple PO files for a locale into a single translation hash.
PoFileMerger combines page-specific PO files in a locale directory into a single merged translation hash. Used when creating compendia by combining all extracted strings across pages for a locale.
Key responsibilities:
-
Find all PO files for a locale
-
Parse PO files with reference metadata
-
Merge into single translation hash
-
Preserve references for debugging
-
Handle parsing errors gracefully
Class Method Summary collapse
-
.merge_file_into(po_file, merged) ⇒ void
Merge a single PO file into an existing merged hash.
-
.merge_files(po_files) ⇒ Hash<String, Hash>
Merge a list of PO files.
-
.merge_for_locale(source, locales_dir, locale) ⇒ Hash<String, Hash>
Merge all PO files for a locale.
Class Method Details
.merge_file_into(po_file, merged) ⇒ void
This method returns an undefined value.
Merge a single PO file into an existing merged hash.
Parses the PO file with references and adds entries that aren’t already in the merged hash. The hash can be empty, and it is modified in place.
70 71 72 73 74 75 76 77 |
# File 'lib/jekyll-l10n/po_file/merger.rb', line 70 def self.merge_file_into(po_file, merged) translations = PoFileReader.parse_with_references(po_file) translations.each do |msgid, entry| merged[msgid] ||= entry end rescue StandardError => e Jekyll.logger.warn 'Localization', "Error merging PO file #{po_file}: #{e.}" end |
.merge_files(po_files) ⇒ Hash<String, Hash>
Merge a list of PO files.
Parses each file and merges into single hash. Later files don’t override entries from earlier files (first occurrence wins).
54 55 56 57 58 59 60 |
# File 'lib/jekyll-l10n/po_file/merger.rb', line 54 def self.merge_files(po_files) merged = {} po_files.each do |po_file| merge_file_into(po_file, merged) end merged end |
.merge_for_locale(source, locales_dir, locale) ⇒ Hash<String, Hash>
Merge all PO files for a locale.
Finds all PO files in the locale subdirectory, parses them with references, and merges into a single hash. First occurrence of each msgid is kept.
38 39 40 41 42 43 44 |
# File 'lib/jekyll-l10n/po_file/merger.rb', line 38 def self.merge_for_locale(source, locales_dir, locale) locale_dir = File.join(source, locales_dir, locale) return {} unless File.directory?(locale_dir) po_files = Dir.glob(File.join(locale_dir, '**', '*.po')).sort merge_files(po_files) end |