Class: NSString

Inherits:
Object
  • Object
show all
Defined in:
lib/MotionLocalize/cocoa/ns_string.rb

Instance Method Summary collapse

Instance Method Details

#translate(opts = {}) ⇒ Object Also known as: _



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/MotionLocalize/cocoa/ns_string.rb', line 3

def translate(opts={})
  str = NSBundle.mainBundle.localizedStringForKey(self, value: nil, table: nil)
  unless str
    mp missing_translation: self, force_color: :red
    return self
  end

  str = str.dup
  opts.each do |key, value|
    str.gsub!("%{#{key}}", value.respond_to?(:to_s) ? value.to_s : value)
  end
  str
end