Class: I18n::Commands::Keys

Inherits:
Object show all
Defined in:
lib/i18n/commands/keys.rb

Instance Method Summary collapse

Constructor Details

#initialize(highlighter = Highlighters::Ansi.new(:bold), out = $stdout) ⇒ Keys

Returns a new instance of Keys.



10
11
12
13
# File 'lib/i18n/commands/keys.rb', line 10

def initialize(highlighter = Highlighters::Ansi.new(:bold), out = $stdout)
  @highlighter = highlighter
  @out = out
end

Instance Method Details

#find(keys, options = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/i18n/commands/keys.rb', line 15

def find(keys, options = {})
  index = index(options)
  index.find_calls(*keys).each do |call|
    log "\n" + call.to_s(:context => options[:context], :highlight => @highlighter).gsub(Dir.pwd, '')
  end
end

#replace(search, replace, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/i18n/commands/keys.rb', line 22

def replace(search, replace, options)
  key = search.gsub(/^\*\.|\.\*$/, '')
  interactive = options.has_key?(:'interactive') ? options[:'interactive'] : true
  index = index(options)
  found = false
  
  index.find_calls(search).each do |call|
    if replace?(call, replace, :interactive => interactive)
      I18n.backend.copy_translations(key, replace)
      index.replace_key(call, search, replace)
      I18n.backend.remove_translation(key)
      found = true
    end
    break if cancelled?
  end
  
  log "No occurences were found or no replacements made for: #{search}." unless found
rescue I18n::KeyExists => e
  log e.message
end