lib/traducto/base.rb in traducto-1.0.5 vs lib/traducto/base.rb in traducto-1.0.6

- old
+ new

@@ -10,12 +10,18 @@ def initialize(rails_helpers) @rails_helpers = rails_helpers init_state + + set_base_actions end + def add_action(action) + @actions << action + end + def translate(key, options={}) init_state key, options lazy_translate if lazy_lookup? @@ -28,15 +34,12 @@ else @text end end - private - def action - request[:action] - end + private def controller request[:controller] end @@ -79,12 +82,28 @@ def lazy_lookup? @base_key[0,1] == '.' end def lazy_translate - i18n_translate "views.#{controller}.#{action}#{@base_key}" + @actions.each do |action| + i18n_translate "views.#{controller}.#{action}#{@base_key}" if translation_missing? + end i18n_translate "views.#{controller}#{@base_key}" if translation_missing? i18n_translate "views#{@base_key}" if translation_missing? + end + + def set_base_actions + @actions = [] + + if request + @actions = [request[:action]] + + if request[:action] == 'create' + @actions << 'new' + elsif request[:action] == 'update' + @actions << 'edit' + end + end end def translation_missing? @text.blank? or @text.include? 'translation missing' end