Module: I18n::Tasks::Scanners::RelativeKeys
- Included in:
- PatternMapper, PatternScanner, RubyAstScanner
- Defined in:
- lib/i18n/tasks/scanners/relative_keys.rb
Instance Method Summary collapse
-
#absolute_key(key, path, roots: config[:relative_roots], exclude_method_name_paths: config[:relative_exclude_method_name_paths], calling_method: nil) ⇒ String
Absolute version of the key.
Instance Method Details
#absolute_key(key, path, roots: config[:relative_roots], exclude_method_name_paths: config[:relative_exclude_method_name_paths], calling_method: nil) ⇒ String
Returns absolute version of the key.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/i18n/tasks/scanners/relative_keys.rb', line 12 def absolute_key(key, path, roots: config[:relative_roots], exclude_method_name_paths: config[:relative_exclude_method_name_paths], calling_method: nil) return key unless key.start_with?(DOT) fail 'roots argument is required' unless roots.present? normalized_path = File.(path) (root = path_root(normalized_path, roots)) || fail(CommandError, "Cannot resolve relative key \"#{key}\".\n" \ "Set search.relative_roots in config/i18n-tasks.yml (currently #{roots.inspect})") normalized_path.sub!(root, '') if (exclude_method_name_paths || []).map { |p| (p) }.include?(root) "#{prefix(normalized_path)}#{key}" else "#{prefix(normalized_path, calling_method: calling_method)}#{key}" end end |