3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/MotionLocalize/android/string.rb', line 3
def translate(opts={})
context = MotionLocalize.context
raise ArgumentError.new 'MotionLocalize on android require that you init MotionLocalize.context' unless context
package_name = context.getPackageName
resource_id = context.getResources.getIdentifier(self, 'string', package_name)
str = context.getString(resource_id)
unless str
mp missing_translation: self, force_color: :red
return self
end
str = str.dup
opts.each do |key, value|
puts "replace #{key} with #{value}"
str.gsub!("%{#{key}}", value.respond_to?(:to_s) ? value.to_s : value)
end
str
end
|