Class: Klenod::Build::Plugins::IntlPlugin::Plugin

Inherits:
Klenod::Build::Plugin show all
Defined in:
lib/klenod/build/plugins/intl_plugin.rb

Constant Summary collapse

INTL_FILE_RE =
/\.intl\.(?<locale>[^\/]+)\.toml\z/

Instance Method Summary collapse

Methods inherited from Klenod::Build::Plugin

#finalize, #import_value, #invalidate_module_ids, #load, #resolve, #runtime_import_value, #transform

Instance Method Details

#translations_for(context, module_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/klenod/build/plugins/intl_plugin.rb', line 18

def translations_for(context, module_id)
  base = module_id.path.delete_suffix(module_id.extname)
  pattern = context.absolute_path(ModuleId.new("#{base}.intl.*.toml", nil)).to_s

  Dir
    .glob(pattern)
    .sort
    .to_h do |path|
      locale = File.basename(path).match(INTL_FILE_RE)[:locale]
      [locale, TomlRB.load_file(path)]
    end
end