Class: I18n::Commands::Keys
Instance Method Summary collapse
- #find(keys, options = {}) ⇒ Object
-
#initialize(highlighter = Highlighters::Ansi.new(:bold), out = $stdout) ⇒ Keys
constructor
A new instance of Keys.
- #replace(search, replace, options) ⇒ Object
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, = {}) index = index() index.find_calls(*keys).each do |call| log "\n" + call.to_s(:context => [: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, ) key = search.gsub(/^\*\.|\.\*$/, '') interactive = .has_key?(:'interactive') ? [:'interactive'] : true index = index() 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. end |