Module: I18n::Processes::Scanners::RelativeKeys

Included in:
PatternMapper, PatternScanner, RubyAstScanner
Defined in:
lib/i18n/processes/scanners/relative_keys.rb

Instance Method Summary collapse

Instance Method Details

#absolute_key(key, path, roots: config[:relative_roots], calling_method: nil) ⇒ String

Returns absolute version of the key.

Parameters:

  • key (String)

    relative i18n key (starts with a .)

  • path (String)

    path to the file containing the key

  • roots (Array<String>) (defaults to: config[:relative_roots])

    paths to relative roots

  • calling_method (#call, Symbol, String, false, nil) (defaults to: nil)

Returns:

  • (String)

    absolute version of the key



11
12
13
14
15
16
17
18
19
20
# File 'lib/i18n/processes/scanners/relative_keys.rb', line 11

def absolute_key(key, path, roots: config[:relative_roots], calling_method: nil)
  return key unless key.start_with?(DOT)
  fail 'roots argument is required' unless roots.present?
  normalized_path = File.expand_path(path)
  (root = path_root(normalized_path, roots)) ||
    fail(CommandError, "Cannot resolve relative key \"#{key}\".\n" \
                        "Set search.relative_roots in config/i18n-processes.yml (currently #{roots.inspect})")
  normalized_path.sub!(root, '')
  "#{prefix(normalized_path, calling_method: calling_method)}#{key}"
end