-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.rb
38 lines (34 loc) · 1.48 KB
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def translate_for(item, options = {})
model_name = item.scan(/(\w+).\w+.\w+/).flatten[0]
with_options :scope => "activerecord.models" do |w|
options[:model] ||= w.t model_name, :count => 1, :default => model_name
options[:models] ||= w.t(model_name, :count => 2, :default => model_name.pluralize).gsub(/\d+/, '').strip
end
default_item = item.gsub(model_name, 'default')
base = "actionview.actions"
t "#{base}.#{item}", options.reverse_merge(:default => t( "#{base}.#{default_item}", options))
end
def translate_save(object_name)
object_instance = instance_variable_get("@#{object_name}")
action = object_instance.new_record? ? "new" : "edit"
translate_for("#{object_name.to_s}.#{action}.save_button_name")
end
## Yaml file belongs to
# def translate_for(item, options = {})
# model_name = item.scan(/(\w+).\w+.\w+/).flatten[0]
#
# with_options :scope => "activerecord.models" do |w|
# options[:model] ||= w.t model_name, :count => 1, :default => model_name
# options[:models] ||= w.t(model_name, :count => 2, :default => model_name.pluralize).gsub(/\d+/, '').strip
# end
#
# default_item = item.gsub(model_name, 'default')
# base = "actionview.actions"
# t "#{base}.#{item}", options.reverse_merge(:default => t( "#{base}.#{default_item}", options))
# end
#
# def translate_save(object_name)
# object_instance = instance_variable_get("@#{object_name}")
# action = object_instance.new_record? ? "new" : "edit"
# translate_for("#{object_name.to_s}.#{action}.save_button_name")
# end