Class: Jekyll::L10n::PoFileLoader
- Inherits:
-
Object
- Object
- Jekyll::L10n::PoFileLoader
- Defined in:
- lib/jekyll-l10n/po_file/loader.rb
Overview
Loads PO files from disk with automatic caching.
PoFileLoader handles loading PO files and managing the global in-memory cache to avoid redundant disk I/O. It constructs proper file paths for locale and page combinations, checks the cache first, and reads from disk only when needed.
Key responsibilities:
-
Check global cache for already-loaded files
-
Construct file paths for locale/page combinations
-
Load PO files from disk when not cached
-
Parse PO file content into translation hashes
-
Cache parsed translations for reuse
-
Handle file-not-found gracefully (return empty hash)
-
Log errors during loading
Class Method Summary collapse
-
.load(source, locales_dir, locale, page_path) ⇒ Hash
Load a PO file with caching.
- .load_and_cache(cache_key, po_path) ⇒ Object
Class Method Details
.load(source, locales_dir, locale, page_path) ⇒ Hash
Load a PO file with caching.
First checks the global PoFileManager cache for already-loaded translations. If not found, constructs the file path, loads from disk if file exists, parses the PO file, caches the result, and returns. Returns empty hash if file doesn’t exist or if an error occurs during loading.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll-l10n/po_file/loader.rb', line 43 def self.load(source, locales_dir, locale, page_path) cache_key = "#{locale}:#{page_path}" cached = PoFileManager.cache[cache_key] return cached if cached po_path = PoPathBuilder.build(source, locales_dir, locale, page_path) return {} unless File.exist?(po_path) load_and_cache(cache_key, po_path) end |
.load_and_cache(cache_key, po_path) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/jekyll-l10n/po_file/loader.rb', line 54 def self.load_and_cache(cache_key, po_path) translations = PoFileReader.parse(po_path) PoFileManager.cache[cache_key] = translations translations rescue StandardError => e Jekyll.logger.warn 'Localization', "Error loading PO file #{po_path}: #{e.}" {} end |